protected void On(ContentStatusScheduled @event) { ScheduleJob = new ScheduleJob(Guid.NewGuid(), @event.Status, @event.Actor, @event.DueTime); }
public void ReLoadSchedule() { lock (_lock) { _allJobs.Clear(); log.Info("Loading job schedule"); using (var jobs = Program.Database.JobProxy.LoadAllActiveSchedule()) { var now = DateTime.Now; while (jobs.MoveNext()) { log.InfoFormat("Setting up job {0}:[{1}]", jobs.Current.Uid, jobs.Current.Name); var sc = new ScheduleJob(jobs.Current); sc.ComputeNextRuntime(now); log.DebugFormat("Job {0}:[{1}] - Next run time @ {2}", jobs.Current.Uid, jobs.Current.Name,sc.NextRunTime.ToString("yyyy-MM-dd hh:mm:ss")); _allJobs.Add(jobs.Current.Uid, sc); } } } }
public override bool ApplyEvent(IEvent @event, EnvelopeHeaders headers) { switch (@event) { case ContentCreated e: { SimpleMapper.Map(e, this); CurrentVersion = new ContentVersion(e.Status, e.Data); break; } case ContentDraftCreated e: { NewVersion = new ContentVersion(e.Status, CurrentVersion.Data); ScheduleJob = null; break; } case ContentDraftDeleted _: { NewVersion = null; ScheduleJob = null; break; } case ContentStatusChanged e: { ScheduleJob = null; if (NewVersion != null) { if (e.Status == Status.Published) { CurrentVersion = new ContentVersion(e.Status, NewVersion.Data); NewVersion = null; } else { NewVersion = NewVersion.WithStatus(e.Status); } } else { CurrentVersion = CurrentVersion.WithStatus(e.Status); } break; } case ContentSchedulingCancelled _: { ScheduleJob = null; break; } case ContentStatusScheduled e: { ScheduleJob = ScheduleJob.Build(e.Status, e.Actor, e.DueTime); break; } case ContentUpdated e: { if (NewVersion != null) { NewVersion = NewVersion.WithData(e.Data); } else { CurrentVersion = CurrentVersion.WithData(e.Data); } break; } case ContentDeleted _: { IsDeleted = true; break; } } return(true); }
public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCustomAuthentication(opts => { }); services.AddAuthorization(policy => { policy.AddPolicy("Authenticated", p => p.RequireAuthenticatedUser()); policy.AddPolicy("create_humantaskinstance", p => p.RequireAuthenticatedUser()); }); services.AddMvc(); services.AddLogging(); var emptyTask = HumanTaskDefBuilder.New("emptyTask") .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetPotentialOwnerUserIdentifiers(new List <string> { "administrator" }) .Build(); var addClient = HumanTaskDefBuilder.New("addClient") .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetPotentialOwnerUserIdentifiers(new List <string> { "administrator" }) .AddDescription("en-US", "<b>firstname is $firstName$, isGoldenClient $isGoldenClient$</b>", "text/html") .AddPresentationParameter("firstName", ParameterTypes.STRING, "context.GetInput(\"firstName\")") .AddPresentationParameter("isGoldenClient", ParameterTypes.BOOL, "context.GetInput(\"isGoldenClient\")") .AddInputOperationParameter("firstName", ParameterTypes.STRING, true) .AddInputOperationParameter("isGoldenClient", ParameterTypes.BOOL, false) .AddOutputOperationParameter("wage", ParameterTypes.INT, true) .Build(); var noPotentialOwner = HumanTaskDefBuilder.New("noPotentialOwner") .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetBusinessAdministratorUserIdentifiers(new List <string> { "businessAdmin" }) .Build(); var multiplePotentialOwners = HumanTaskDefBuilder.New("multiplePotentialOwners") .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetPotentialOwnerUserIdentifiers(new List <string> { "administrator", "guest" }) .Build(); var startDeadLine = HumanTaskDefBuilder.New("startDeadLine") .AddInputOperationParameter("firstName", ParameterTypes.STRING, true) .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetPotentialOwnerUserIdentifiers(new List <string> { "administrator", "guest" }) .AddStartDeadLine("sendReminder", (dl) => { dl.SetUntilExpression("P0Y0M0DT0H0M2S"); dl.AddEscalation(eb => { eb.AddToPart("firstName", "context.GetInput(\"firstName\")"); eb.SetNotification("firstNotification"); }); }) .Build(); var completionDeadLine = HumanTaskDefBuilder.New("completionDeadLine") .AddInputOperationParameter("firstName", ParameterTypes.STRING, true) .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetPotentialOwnerUserIdentifiers(new List <string> { "administrator", "guest" }) .AddCompletionDeadLine("sendReminder", (dl) => { dl.SetUntilExpression("P0Y0M0DT0H0M2S"); dl.AddEscalation(eb => { eb.AddToPart("firstName", "context.GetInput(\"firstName\")"); eb.SetNotification("secondNotification"); }); }) .Build(); var compositeTask = HumanTaskDefBuilder.New("compositeTask") .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetPotentialOwnerUserIdentifiers(new List <string> { "administrator" }) .AddInputOperationParameter("firstName", ParameterTypes.STRING, true) .AddInputOperationParameter("isGoldenClient", ParameterTypes.BOOL, false) .SetParallelComposition(InstantiationPatterns.AUTOMATIC, cb => { cb.AddSubTask("addClient", new List <ToPart> { new ToPart { Expression = "context.GetInput(\"firstName\")", Name = "firstName" }, new ToPart { Expression = "context.GetInput(\"isGoldenClient\")", Name = "isGoldenClient" } }); }) .Build(); var compositeTaskWithAutomaticCompletionBehavior = HumanTaskDefBuilder.New("compositeTaskWithAutomaticCompletionBehavior") .SetTaskInitiatorUserIdentifiers(new List <string> { "taskInitiator" }) .SetPotentialOwnerUserIdentifiers(new List <string> { "administrator" }) .AddInputOperationParameter("firstName", ParameterTypes.STRING, true) .AddInputOperationParameter("isGoldenClient", ParameterTypes.BOOL, false) .SetParallelComposition(InstantiationPatterns.AUTOMATIC, cb => { cb.AddSubTask("addClient", new List <ToPart> { new ToPart { Expression = "context.GetInput(\"firstName\")", Name = "firstName" }, new ToPart { Expression = "context.GetInput(\"isGoldenClient\")", Name = "isGoldenClient" } }); cb.AddSubTask("emptyTask", new List <ToPart>()); }) .SetAutomaticCompletion(cb => { cb.AddCompletion("context.GetIntOutput(\"wage\", \"addClient\") > 2", new List <Copy> { new Copy { From = "context.GetIntOutput(\"wage\", \"addClient\")", To = "wage" } }); }) .Build(); var firstNotification = NotificationDefBuilder.New("firstNotification") .AddInputOperationParameter("firstName", ParameterTypes.STRING, true) .SetRecipientUserIdentifiers(new List <string> { "guest" }) .AddName("en-US", "<b>firstName is $firstName$</b>") .AddPresentationParameter("firstName", ParameterTypes.STRING, "context.GetInput(\"firstName\")") .Build(); var secondNotification = NotificationDefBuilder.New("secondNotification") .AddInputOperationParameter("firstName", ParameterTypes.STRING, true) .SetRecipientUserIdentifiers(new List <string> { "guest" }) .AddName("en-US", "<b>firstName is $firstName$</b>") .AddPresentationParameter("firstName", ParameterTypes.STRING, "context.GetInput(\"firstName\")") .Build(); services.AddHostedService <HumanTaskJobServerHostedService>(); services.AddHumanTasksApi(); services.AddHumanTaskServer() .AddHumanTaskDefs(new List <HumanTaskDefinitionAggregate> { addClient, noPotentialOwner, multiplePotentialOwners, startDeadLine, compositeTask, completionDeadLine, compositeTaskWithAutomaticCompletionBehavior, emptyTask }) .AddNotificationDefs(new List <NotificationDefinitionAggregate> { firstNotification, secondNotification }) .AddScheduledJobs(new List <ScheduleJob> { ScheduleJob.New <ProcessActivationTimerJob>(1 * 1000), ScheduleJob.New <ProcessDeadLinesJob>(1 * 1000) }); }
/// <summary> /// upload schedule excel file and save the schedule data into the system /// </summary> /// <param name="excelPath"></param> public static void UploadAndSaveExcel(string excelPath, List <string> nursersName, List <string> jobsName) { try { Excel.Application excel = new Excel.Application(); excel.Visible = false; Excel.Workbook workbook = excel.Application.Workbooks.Open(excelPath, Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value); Excel.Worksheet sheet = (Excel.Worksheet)workbook.Sheets["Sheet1"]; ///---这里获取的是 行索引为1,列索引为1的单元格的值 //Excel.Range range = (Excel.Range)sheet.Cells[1, 1]; //int dateColIndex = 5; //for (int i = 0; i < 7; i++) //{ //读取第三行周时间单元 // Excel.Range mergedCells = sheet.Cells[3, dateColIndex]; // if (mergedCells.MergeCells) // { // Excel.Range range = sheet.Cells[3, dateColIndex]; // string text = range.Text; // } // dateColIndex += 2; //} List <Schedules> scheduledList = new List <Schedules>(); int baseDataRow = 7; for (int indexRow = baseDataRow; indexRow < baseDataRow + nursersName.Count(); indexRow++) { Excel.Range rangeNurseName = (Excel.Range)sheet.Cells[baseDataRow, 3]; string nurseName = rangeNurseName.Text; //判断护士名称是否存在 if (nursersName.Select(e => e.Equals(nurseName.Trim())).Any()) { Schedules schedule = new Schedules(); schedule.ScheduledNurser = new Nurser() { NurserName = nurseName.Trim() }; int baseScheduleDataColumns = 5; //从第五列开始,直到一周结束,一周为14个小单元 for (int indexCol = baseScheduleDataColumns; indexCol < baseScheduleDataColumns + 14; indexCol++) { Excel.Range rangeScheduleData = (Excel.Range)sheet.Cells[indexRow, indexCol]; string scheduleJobData = rangeScheduleData.Text; if (jobsName.Select(e => e.Equals(scheduleJobData.Trim())).Any()) { ScheduleJob job = new ScheduleJob(); job.Tasks = new List <TaskDetail>(); if (indexCol / 2 == 0) // 下午 { TaskDetail task_afternoon = new TaskDetail() { JobDayType = ScheduledType.Afternoon.ToString(), JobName = scheduleJobData }; } else { TaskDetail task_morning = new TaskDetail() { JobDayType = ScheduledType.Morning.ToString(), JobName = scheduleJobData }; } } else { Exception ex = new Exception("文件中排班名称与系统中名称名称不一致"); throw ex; } } } else { Exception ex = new Exception("文件中护士名称与系统中护士名称或数量不一致"); throw ex; } } }catch (Exception ex) { throw ex; } }
public override bool ApplyEvent(IEvent @event) { switch (@event) { case ContentCreated e: { SimpleMapper.Map(e, this); UpdateData(null, e.Data, false); break; } case ContentChangesPublished _: { ScheduleJob = null; UpdateData(DataDraft, null, false); break; } case ContentStatusChanged e: { ScheduleJob = null; SimpleMapper.Map(e, this); if (e.Status == Status.Published) { UpdateData(DataDraft, null, false); } break; } case ContentUpdated e: { UpdateData(e.Data, e.Data, false); break; } case ContentUpdateProposed e: { UpdateData(null, e.Data, true); break; } case ContentChangesDiscarded _: { UpdateData(null, Data, false); break; } case ContentSchedulingCancelled _: { ScheduleJob = null; break; } case ContentStatusScheduled e: { ScheduleJob = ScheduleJob.Build(e.Status, e.Actor, e.DueTime); break; } case ContentDeleted _: { IsDeleted = true; break; } } return(true); }
public void ScheduleJobForScannig(ScheduleJob job) { job.RegisterListener(this); job.ExecuteFileChecker(); }