public static void UnzipFile(string filePathToUnzip, string unzipedFilePath) { CheckPath(filePathToUnzip, unzipedFilePath); using (ZipInputStream s = new ZipInputStream(File.OpenRead(filePathToUnzip))) { ZipEntry entry = s.GetNextEntry(); UtilsFunc.Assert(entry != null, "entry is null"); using (FileStream outputStream = File.Create(unzipedFilePath)) { int size = 0; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { outputStream.Write(data, 0, size); } else { break; } } } // No Dir supported in this function. UtilsFunc.Assert(null == s.GetNextEntry()); } }
private static void CheckPath(string inputFilePath, string outputFilePath) { UtilsFunc.Assert(!String.IsNullOrEmpty(inputFilePath)); UtilsFunc.Assert(!String.IsNullOrEmpty(outputFilePath)); UtilsFunc.Assert(File.Exists(inputFilePath)); UtilsFunc.Assert(!File.Exists(outputFilePath)); UtilsFunc.Assert(Directory.Exists(Path.GetDirectoryName(outputFilePath))); }
private bool __Save(List <JobMeta> jobMetas) { var encodingJobMetas = new List <string>(jobMetas.Count); foreach (var item in jobMetas) { encodingJobMetas.Add(UtilsFunc.JobMetaToString(item)); } File.WriteAllLines("jobrunningenv.cache", encodingJobMetas, Encoding.UTF8); return(true); }
/// <summary> /// 开启job /// </summary> /// <param name="jobParam">job执行参数</param> /// <param name="onceJob">是否执行计划外的任务</param> /// <returns></returns> public bool StartJob(JobMeta jobParam, bool onceJob = false) { try { var triggerKey = onceJob ? UtilsFunc.GenTriggerKey(jobParam.JobName) : GetTriggerKey(); var trigger = GenTrigger(triggerKey, jobParam.StartTime, jobParam.Interval, jobParam.CronExpression, onceJob); if (trigger == null) { JobLogHelper.Error( $"创建{jobParam.JobName}的trigger失败,参数为{onceJob},{jobParam.StartTime},{jobParam.Interval},{jobParam.CronExpression}", null, nameof(StartJob)); return(false); } var jobkey = onceJob ? UtilsFunc.GenJobKey(jobParam.JobName) : GetJobKey(); var job = JobBuilder.Create <T>() .WithIdentity(jobkey) .Build(); job.SetJobName(jobParam.JobName); job.SetJobCode(jobParam.JobCode); job.SetOnceJobFlag(onceJob); job.SetDepJobs(jobParam.DepJobs); job.SetJobRunParams(jobParam.RunParams); job.SetAutoClose(jobParam.AutoClose); job.SetIsDoNotice(jobParam.IsDoNotice); ScheduleModConfig.Instance.DefaultScheduler.ScheduleJob(job, trigger); var jobListener = new LT(); if (onceJob) { jobListener.SetName(UtilsFunc.GenListenerName(jobParam.JobName)); } ScheduleModConfig.Instance.DefaultScheduler.ListenerManager.AddJobListener(jobListener, KeyMatcher <JobKey> .KeyEquals(jobkey)); ScheduleModConfig.Instance.DefaultScheduler.ListenerManager.AddTriggerListener(jobListener, KeyMatcher <TriggerKey> .KeyEquals(triggerKey)); if (jobParam.State == JobStateEnum.Pause) { ScheduleModConfig.Instance.DefaultScheduler.PauseJob(jobkey); } return(true); } catch (Exception ex) { JobLogHelper.Error(ex.Message, ex, nameof(StartJob)); return(false); } }
public List <JobMeta> ReadAllJobEnv() { if (!File.Exists("jobrunningenv.cache")) { return(new List <JobMeta>(0)); } var allJobStr = File.ReadAllLines("jobrunningenv.cache", Encoding.UTF8); var jobMetaList = new List <JobMeta>(allJobStr.Length); foreach (var item in allJobStr) { jobMetaList.Add(UtilsFunc.StringToJobMeta(item)); } return(jobMetaList); }
public static byte[] ZipBytes(byte[] input, int compressLevel) { UtilsFunc.Assert(input != null); Deflater compressor = new Deflater(); compressor.SetLevel(compressLevel); compressor.SetInput(input); compressor.Finish(); byte[] ret = null; using (MemoryStream bos = new MemoryStream(input.Length)) { byte[] buf = new byte[1024]; while (!compressor.IsFinished) { int count = compressor.Deflate(buf); bos.Write(buf, 0, count); } ret = bos.ToArray(); } return(ret); }
/// <summary> /// 停止单次运行的job /// </summary> /// <param name="name"></param> /// <returns></returns> public async Task <JobActionRetEnum> StopJobAsync(string name) { var jobParams = ScheduleModConfig.Instance.Jobs == null ? null : ScheduleModConfig.Instance.Jobs.FirstOrDefault(x => x.JobName.Equals(name)); if (jobParams != null) { //非单次运行的job不支持停止,只能暂停 return(JobActionRetEnum.Conflict); } __JobEnvManager.DelJobFromEnv(name); var jobKey = UtilsFunc.GenJobKey(name); var listenerName = UtilsFunc.GenListenerName(name); //移除job, trigger listener and job self and its trigger return(ScheduleModConfig.Instance.DefaultScheduler.ListenerManager.RemoveJobListener(listenerName) && ScheduleModConfig.Instance.DefaultScheduler.ListenerManager.RemoveTriggerListener(listenerName) && await ScheduleModConfig.Instance.DefaultScheduler.DeleteJob(jobKey) ? JobActionRetEnum.Success : JobActionRetEnum.Failed); }