[HttpPost] [Route("UploadFile")] public async Task<IActionResult> UploadFile() { var files = Request.Form.Files; var data = JsonConvert.DeserializeObject<UploadFileEntity>(Request.Form["data"]);
string snPath = $"{_hostingEnvironment.WebRootPath}//{_config["UploadPath"]}//{data.sn}"; foreach (var item in data.files) { var processPath = $"{snPath}//{ ConversionPath(item.processPath)}"; if (!Directory.Exists(processPath)) { Directory.CreateDirectory(processPath); } var file = files.Where(p => p.FileName == item.fileName).FirstOrDefault();
if (file!=null && file.Length != 0) { // 只保留三份有效文件 DirectoryInfo di = new DirectoryInfo(processPath); FileInfo[] oldFiles = di.GetFiles($"*{file.FileName}"); string newFileName = $"{(oldFiles.Length + 1)}_{file.FileName}"; if (oldFiles.Length == 3) { newFileName = oldFiles.OrderBy(f => f.LastWriteTime).FirstOrDefault().Name; } var filePath = $"{processPath}//{newFileName}"; using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } } } return NoContent(); }
public class UploadFileEntity { public string sn { get; set; } public List<File> files { get; set; } } public class File { public string processPath { get; set; } public string fileName { get; set; } }
using System; using Quartz.Logging; using Quartz.Spi; using Quartz.Util; namespace Quartz.Simpl { /// <summary> /// The default JobFactory used by Quartz - simply calls /// <see cref="ObjectUtils.InstantiateType{T}" /> on the job class. /// </summary> /// <seealso cref="IJobFactory" /> /// <seealso cref="PropertySettingJobFactory" /> /// <author>James House</author> /// <author>Marko Lahma (.NET)</author> public class SimpleJobFactory : IJobFactory { private static readonly ILog log = LogProvider.GetLogger(typeof (SimpleJobFactory)); /// <summary> /// Called by the scheduler at the time of the trigger firing, in order to /// produce a <see cref="IJob" /> instance on which to call Execute. /// </summary> /// <remarks> /// It should be extremely rare for this method to throw an exception - /// basically only the case where there is no way at all to instantiate /// and prepare the Job for execution. When the exception is thrown, the /// Scheduler will move all triggers associated with the Job into the /// <see cref="TriggerState.Error" /> state, which will require human /// intervention (e.g. an application restart after fixing whatever /// configuration problem led to the issue with instantiating the Job). /// </remarks> /// <param name="bundle">The TriggerFiredBundle from which the <see cref="IJobDetail" /> /// and other info relating to the trigger firing can be obtained.</param> /// <param name="scheduler"></param> /// <returns>the newly instantiated Job</returns> /// <throws> SchedulerException if there is a problem instantiating the Job. </throws> public virtual IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { IJobDetail jobDetail = bundle.JobDetail; Type jobType = jobDetail.JobType; try { if (log.IsDebugEnabled()) { log.Debug($"Producing instance of Job '{jobDetail.Key}', class={jobType.FullName}"); } return ObjectUtils.InstantiateType<IJob>(jobType); } catch (Exception e) { SchedulerException se = new SchedulerException($"Problem instantiating class '{jobDetail.JobType.FullName}'", e); throw se; } } /// <summary> /// Allows the job factory to destroy/cleanup the job if needed. /// No-op when using SimpleJobFactory. /// </summary> public virtual void ReturnJob(IJob job) { var disposable = job as IDisposable; disposable?.Dispose(); } } }