/// <summary> /// Higlights the days. /// </summary> private void HiglightDays() { this.NormalizeDisplayDate(); this._nextOccurences = ScheduleUtility.GetNextOccurrences(this.Schedule, this.DayCalendar.DisplayDate.AddMinutes(-1), this.DayCalendar.DisplayDate.LastDayOfMonth().AddDays(1)).ToList(); DateTime?selectedDate = this.DayCalendar.SelectedDate ?? DateTime.Today; this.DayCalendar.SelectedDates.Clear(); this.DayCalendar.BlackoutDates.Clear(); int firstDay = this.DayCalendar.DisplayDate.Day; var allDays = Enumerable.Range(firstDay, this.DayCalendar.DisplayDate.LastDayOfMonth().Day - firstDay + 1); var occurenceDays = this._nextOccurences.Select(o => o.Day).Distinct(); var blockedDays = allDays.Except(occurenceDays); foreach (int day in blockedDays) { CalendarDateRange blockedRange = new CalendarDateRange(this.DayCalendar.DisplayDate.AddDays(day - firstDay)); this.DayCalendar.BlackoutDates.Add(blockedRange); } // reselect date if we can (will kick of date selection) if (selectedDate.HasValue && !this.DayCalendar.BlackoutDates.Contains(selectedDate.Value)) { this.DayCalendar.SelectedDate = selectedDate; } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); app.UseSwagger(); app.UseSwaggerUI(setupAction => { setupAction.SwaggerEndpoint( "/swagger/LibraryOpenAPISpecification/swagger.json", "Dental API"); setupAction.RoutePrefix = ""; }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); var cs = new ScheduleUtility(context); cs.InitializeSchedule(); }
/// <summary> /// Updates the months. /// </summary> private void UpdateMonthControls() { var description = ScheduleUtility.GetMonthDescription(this.Schedule); if (description.IsEvery) { this.EveryMonthRadioButton.IsChecked = true; if (string.IsNullOrWhiteSpace(description.PartialDescription)) { this.MonthMultiSelect.SelectAll(); } else { SelectMultiSelectValues(this.MonthMultiSelect, description); } } else { this.AtMonthRadioButton.IsChecked = true; if (!string.IsNullOrWhiteSpace(description.PartialDescription)) { SelectMultiSelectValues(this.MonthMultiSelect, description); } } }
/// <summary> /// Shows the service app details. /// </summary> /// <param name="serviceApp">The service app.</param> /// <param name="isReadOnly">If set to <c>true</c> show the details as read only.</param> private void ShowServiceAppDetails(ServiceApp serviceApp, bool isReadOnly) { if (serviceApp == null) { serviceApp = new Models.ServiceApp { StartupTypeEnum = Enums.StartupType.NotSet, Schedule = string.Empty }; } this.ServiceAppNameLabel.Content = this.ServiceAppNameTextBox.Text = serviceApp.Name; this.MessageLabel.Text = serviceApp.LastMessage; this.StartServiceAppButton.IsEnabled = serviceApp.CanStart && isReadOnly; this.StopServiceAppButton.IsEnabled = serviceApp.CanStop && isReadOnly; this.RunButton.IsEnabled = serviceApp.CanRun && isReadOnly; this.StartupTypeLabel.Text = serviceApp.StartupTypeEnum.GetName(); this.StartupTypeComboBox.SelectedValue = serviceApp.StartupTypeEnum; this.ServiceAppDescriptionLabel.Text = this.DescriptionTextBox.Text = serviceApp.Description; this.ServiceAppEnvironmentLabel.Text = this.ServiceAppEnvironmentTextBox.Text = serviceApp.Environment; this.ServiceAppParameterLabel.Text = this.ParameterTextBox.Text = serviceApp.Parameters; this.AppFilePathLabel.Text = this.AppFilePathTextBox.Text = serviceApp.AppFilePath; this.AppFilePathViewButton.IsEnabled = !string.IsNullOrWhiteSpace(serviceApp.AppFilePath); this.SendSuccessCheckBox.IsChecked = serviceApp.SendSuccessNotification; this.IdentityLabel.Text = this.IdentityLabel.Text = serviceApp.Username; this.PasswordHiddenLabel.Text = serviceApp.Password; this.ScheduleLabel.Text = ScheduleUtility.GetFullDescription(serviceApp.Schedule); this.ScheduleHiddenLabel.Text = serviceApp.Schedule; this.EditServiceAppButton.IsEnabled = !serviceApp.CanRun; this.EditMessageTextBlock.Text = serviceApp.CanRun ? "Stop the app before making changes" : null; }
public JsonResult GetFilmByCinemaAndDate(int cinemaId) { //DateTime currentDate = DateTime.Today; string dateInput = "2018-06-08"; DateTime currentDate = DateTime.Parse(dateInput); List <Object> films = new ScheduleUtility().getFilmListInSchedule(cinemaId, currentDate); return(Json(films)); }
public void GetScheduleFromString_Test() { var expected = new Schedule(Period.Seconds, 1); Schedule actual = ScheduleUtility.GetScheduleFromString("secOnds", "1"); Assert.AreEqual(expected.Period, actual.Period); Assert.AreEqual(expected.Unit, actual.Unit); }
/// <summary> /// Handles the Click event of the ScheduleSelectButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void ScheduleSelectButton_Click(object sender, RoutedEventArgs e) { ScheduleWindow scheduleWindow = new ScheduleWindow(); scheduleWindow.UpdateWith(!string.IsNullOrWhiteSpace(this.ScheduleHiddenLabel.Text) ? this.ScheduleHiddenLabel.Text : ScheduleUtility.DefaultCrontab); if (scheduleWindow.ShowDialog() == true) { this.ScheduleHiddenLabel.Text = scheduleWindow.Schedule; this.ScheduleLabel.Text = ScheduleUtility.GetFullDescription(scheduleWindow.Schedule); } }
private void Run() { while (true) { try { TimerTask executeTask = m_timerTaskList.OrderBy(t => t.TaskSchedule.ScheduleCycle.NextExecute).FirstOrDefault(t => !t.Running); if (executeTask == null) { m_planExecutorWaiter.WaitOne(); } //休眠 Schedule planSchedule = executeTask.TaskSchedule; DateTime currTime = DateTime.Now; //if (planSchedule.ScheduleCycle.NextExecute == null || !executePlan.Running) //任务服务重启的情况 //{ // //更新执行时间 // SetPlanNextExecute(planSchedule, currTime); //} if (planSchedule.ScheduleCycle.NextExecute != null) { int waitTimeout = (int)((planSchedule.ScheduleCycle.NextExecute.Value - currTime).TotalMilliseconds); //误差2分钟内,有效执行 if (waitTimeout < 0 && waitTimeout > -2 * 60 * 1000) { waitTimeout = 0; } if (waitTimeout >= 0) { _logger.LogInformation("等待{0}ms后将执行预案....", waitTimeout); TimePeriod tp = ScheduleUtility.GetPlanTaskTimePeriod(planSchedule, planSchedule.ScheduleCycle.NextExecute.Value); // 运行预案 PlanTaskWrapper task = new PlanTaskWrapper() { Plan = executeTask.Plan, RunTimePeriod = tp, TaskId = executeTask.TimerTaskId }; PlanExecutor executor = new PlanExecutor(task); executor.OnPlanExecutedEnd += Executor_OnPlanExecutedEnd; executeTask.Running = true; var planTask = Task.Delay(waitTimeout).ContinueWith((runTask) => executor.Start()); AddPlanExecutorToCache(executor); } } } catch (Exception ex) { _logger.LogError("执行预案异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } }
/// <summary> /// Updates the schedule. /// </summary> public void RefreshSchedule() { ScheduleBuildResult result = ScheduleUtility.BuildSchedule( minutePart: GetSchedulePart(this.MinuteMultiSelect, this.EveryMinuteRadioButton.IsChecked ?? false), hourPart: GetSchedulePart(this.HourMultiSelect, this.EveryHourRadioButton.IsChecked ?? false), dayPart: GetSchedulePart(this.DayMultiSelect, this.EveryDayRadioButton.IsChecked ?? false), monthPart: GetSchedulePart(this.MonthMultiSelect, this.EveryMonthRadioButton.IsChecked ?? false), dayOfWeekPart: this.GetDayOfWeekSelection()); this.Schedule = result.Result; this.ValidationMessagesTextBlock.Text = string.Join(Environment.NewLine, result.Messages); this.SaveButton.IsEnabled = string.IsNullOrEmpty(this.ValidationMessagesTextBlock.Text); this.UpdateDescription(); }
public void TestCreateSimpleScheduleCreate() { TestInitialize(); DateTime D1 = new DateTime(2020, 1, 1); DateTime D2 = new DateTime(2020, 1, 1); DateTime D3 = new DateTime(2020, 1, 1, 8, 30, 0); var cs = new ScheduleUtility(context); cs.CreateSchedule(D1, D2); int count = context.Schedules.Count(); Schedule S = context.Schedules.Where(s => s.Date == D3).FirstOrDefault(); Assert.AreEqual(16, count); Assert.IsNotNull(S); }
public IActionResult Add([FromBody] Schedule model) { try { if (model == null) { return(BadRequest()); } using (var db = new AllInOneContext.AllInOneContext()) { if (model.ScheduleCycle != null) { //补全数据 SystemOption cycletype = db.Set <SystemOption>() .FirstOrDefault(p => p.SystemOptionId.Equals(model.ScheduleCycle.CycleTypeId)); Schedule Schedule = model; if (cycletype != null) { Schedule.ScheduleCycle.CycleType = cycletype; } DateTime?executeTime = ScheduleUtility.GetExecuteTime(Schedule, DateTime.Now); model.ScheduleCycle.NextExecute = executeTime; } db.Schedule.Add(model); db.SaveChanges(); return(Created("", "OK")); } } catch (DbUpdateException dbEx) { _logger.LogError("Add:Message:{0}\r\n,StackTrace:{1}", dbEx.Message, dbEx.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (System.Exception ex) { _logger.LogError("Add:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
/// <summary> /// 设置查勤包运行时间 /// </summary> /// <param name="planSchedule"></param> /// <returns></returns> private void SetPlanNextExecute(Schedule planSchedule, DateTime startTime) { try { //更新查勤计划下执行时间 DateTime?executeTime = ScheduleUtility.GetExecuteTime(planSchedule, startTime); planSchedule.ScheduleCycle.LastExecute = planSchedule.ScheduleCycle.NextExecute; planSchedule.ScheduleCycle.NextExecute = executeTime; //更新查勤计划执行时间 string url = string.Format("{0}/Infrastructure/schedule", GlobalSetting.AppServerBaseUrl); string result = string.Empty; HttpClientHelper.Put <Schedule>(planSchedule, url); _logger.LogInformation("更新查勤计划下一运行时间...."); } catch (Exception ex) { _logger.LogError("更新查勤计划运行时间异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } }
/// <summary> /// Updates the days of week. /// </summary> private void UpdateDayOfWeekControls() { var description = ScheduleUtility.GetDayOfWeekDescription(this.Schedule); IList <int> valuesToSelect; if (description.IsEvery) { if (string.IsNullOrWhiteSpace(description.PartialDescription)) { valuesToSelect = Enumerable.Range(0, 7).ToList(); } else { int repeatDay = description.ExpandedValues.First(); valuesToSelect = Enumerable.Range(0, 7).Where(i => i % repeatDay == 0).ToList(); } } else { valuesToSelect = description.ExpandedValues; } this.SundayCheckBox.IsChecked = false; this.MondayCheckBox.IsChecked = false; this.TuesdayCheckBox.IsChecked = false; this.WednesdayCheckBox.IsChecked = false; this.ThursdayCheckBox.IsChecked = false; this.FridayCheckBox.IsChecked = false; this.SaturdayCheckBox.IsChecked = false; valuesToSelect.ToList().ForEach(i => { this.SundayCheckBox.IsChecked |= i == 0; this.MondayCheckBox.IsChecked |= i == 1; this.TuesdayCheckBox.IsChecked |= i == 2; this.WednesdayCheckBox.IsChecked |= i == 3; this.ThursdayCheckBox.IsChecked |= i == 4; this.FridayCheckBox.IsChecked |= i == 5; this.SaturdayCheckBox.IsChecked |= i == 6; }); }
private void Run() { while (true) { try { DutyCheckPackageTimePlan executeTask = m_timerList.OrderBy(t => t.Schedule.ScheduleCycle.NextExecute).FirstOrDefault(t => !t.Running); if (executeTask == null) { m_planExecutorWaiter.WaitOne(); } //休眠 Schedule planSchedule = executeTask.Schedule; DateTime currTime = DateTime.Now; if (planSchedule.ScheduleCycle.NextExecute != null && !executeTask.Running) { int waitTimeout = (int)((planSchedule.ScheduleCycle.NextExecute.Value - currTime).TotalMilliseconds); //误差2分钟内,有效执行 if (waitTimeout < 0 && waitTimeout > -2 * 60 * 1000) { waitTimeout = 0; } if (waitTimeout >= 0) { TimePeriod tp = ScheduleUtility.GetPlanTaskTimePeriod(planSchedule, planSchedule.ScheduleCycle.NextExecute.Value); executeTask.Running = true; bool isGenerate = DutyCheckPackageHelper.CheckDutyPackageExist(executeTask.OrganizationId); if (isGenerate) { DutyCheckPackageHelper.AllocationDutychekPackage(executeTask.OrganizationId, DateTime.Now); } var planTask = Task.Delay(waitTimeout).ContinueWith((runTask) => GetDutyCheckPackage()); } } } catch (Exception ex) { _logger.LogError("执行查勤包异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } }
/// <summary> /// Updates the description. /// </summary> private void UpdateDescription() { this.DescriptionLabel.Text = ScheduleUtility.GetFullDescription(this.Schedule); this.ScheduleCalendar.Schedule = this.Schedule; }
public void GetFullDescription_AlternatingSetValues() { string desc = ScheduleUtility.GetFullDescription("4-6 * 4-6 * 4-6"); Assert.AreEqual("On Thursday-Saturday, every month, on the 4th-6th day, every hour, at 4-6 minutes", desc); }
public void GetFullDescription_EveryFewHoursEveryMinute() { string desc = ScheduleUtility.GetFullDescription("* */4 * * *"); Assert.AreEqual("Every 4 hours, every minute", desc); }
public IActionResult Update([FromBody] Schedule model) { try { if (model == null) { return(BadRequest()); } using (var db = new AllInOneContext.AllInOneContext()) { using (var tran = db.Database.BeginTransaction()) { if (model.ScheduleCycle != null) { //补全数据 SystemOption cycletype = db.Set <SystemOption>() .FirstOrDefault(p => p.SystemOptionId.Equals(model.ScheduleCycle.CycleTypeId)); Schedule Schedule = model; if (cycletype != null) { Schedule.ScheduleCycle.CycleType = cycletype; } DateTime?executeTime = ScheduleUtility.GetExecuteTime(Schedule, DateTime.Now); model.ScheduleCycle.NextExecute = executeTime; } //转换一般数据 Schedule shedule = db.Schedule .Include(t => t.ScheduleType) .Include(t => t.ScheduleCycle).ThenInclude(t => t.DayPeriods) .Include(t => t.ScheduleCycle).ThenInclude(t => t.CycleType) .FirstOrDefault(p => p.ScheduleId.Equals(model.ScheduleId)); if (shedule == null) { return(BadRequest()); } shedule.EffectiveTime = model.EffectiveTime; shedule.ExpirationTime = model.ExpirationTime; shedule.ScheduleTypeId = model.ScheduleTypeId; shedule.ScheduleName = model.ScheduleName; // ScheduleCycle scheduleCycle = db.Set <ScheduleCycle>() .Include(t => t.DayPeriods) .FirstOrDefault(p => p.ScheduleCycleId.Equals(shedule.ScheduleCycle.ScheduleCycleId)); //转换ScheduleCycle scheduleCycle.CycleTypeId = model.ScheduleCycle.CycleTypeId; scheduleCycle.Days = model.ScheduleCycle.Days; scheduleCycle.DaysJson = model.ScheduleCycle.DaysJson; scheduleCycle.LastExecute = model.ScheduleCycle.LastExecute; scheduleCycle.Months = model.ScheduleCycle.Months; scheduleCycle.MonthsJson = model.ScheduleCycle.MonthsJson; scheduleCycle.NextExecute = model.ScheduleCycle.NextExecute; scheduleCycle.WeekDayJson = model.ScheduleCycle.WeekDayJson; scheduleCycle.WeekDays = model.ScheduleCycle.WeekDays; // RemoveList(db, shedule); // scheduleCycle.DayPeriods = model.ScheduleCycle.DayPeriods; shedule.ScheduleCycle = scheduleCycle; db.Schedule.Update(shedule); db.SaveChanges(); // tran.Commit(); return(new NoContentResult()); } } } catch (DbUpdateException dbEx) { _logger.LogError("Update:Message:{0}\r\n,StackTrace:{1}", dbEx.Message, dbEx.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (System.Exception ex) { _logger.LogError("Update:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
public void GetFullDescription_EveryFewHoursAtASetMinute() { string desc = ScheduleUtility.GetFullDescription("15 */4 * * *"); Assert.AreEqual("Every 4 hours, at 15 minutes", desc); }
private void Run() { while (WaitHandle.WaitAny(m_WaitHandles) == 0) { if (m_alarmLogQueue.Count == 0) { m_queueThreadSemaphore.Reset(); } //出列,处理 AlarmLog alarmLog = null; bool dequeueOk = m_alarmLogQueue.TryDequeue(out alarmLog); if (dequeueOk) { //报警联动 using (var db = new AllInOneContext.AllInOneContext()) { try { var setting = GetAlarmSetting(db, alarmLog); if (setting != null) { int code = 0; if (Int32.TryParse(setting.AlarmSource.Organization.OrganizationCode, out code)) { setting.AlarmSource.IPDeviceCode = code; } Plan plan = null; DeviceAlarmStatus status = null; //本地广播报警消息 MQPulish.PublishMessage("AlarmLog", alarmLog); if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100001"))) //执行预案,状态未确认 { if (ScheduleUtility.IsValidSchedule(setting.Schedule, DateTime.Now)) //符合当前排班的情况 { ////本地广播报警消息 //MQPulish.PublishMessage("AlarmLog", alarmLog); plan = db.Plan.Include(t => t.Actions).ThenInclude(t => t.PlanActions).ThenInclude(t => t.Action).FirstOrDefault(t => t.PlanId.Equals(setting.BeforePlanId)); } } else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100002"))) //执行应急预案 { //预案确认 plan = db.Plan.Include(t => t.Actions).ThenInclude(t => t.PlanActions).ThenInclude(t => t.Action).FirstOrDefault(t => t.PlanId.Equals(setting.EmergencyPlanId)); //哨位报警,确认需推送报警确认/取消到哨位中心服务 status = GetDeviceAlarmStatus(db, setting, true); } else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100003"))) //报警取消,停止联动动作 { //哨位报警,取消需推送报警确认/取消到哨位中心服务 status = GetDeviceAlarmStatus(db, setting, false); StopPlan(setting); } else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100004"))) //停止联动动作,已关闭 { status = GetDeviceAlarmStatus(db, setting, false); StopPlan(setting); } //找到满足条件的预案,发送到任务服务,启动预案 if (plan != null) { plan.PlanTrigger = new PlanTriggerSource() { AlarmSource = setting.AlarmSource, AlarmType = setting.AlarmType, BeforePlanId = setting.BeforePlanId, EmergencyPlanId = setting.EmergencyPlanId, AlarmLogId = alarmLog.AlarmLogId }; StartPlan(plan); } if (status != null) { SendAlarmStatusToASCS(status, setting.AlarmSource.OrganizationId); } } else { _logger.LogInformation("未配置报警,没有任务联动响应!!!!"); } } catch (Exception ex) { _logger.LogError("报警处理异常,Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } } } }
public void GetFullDescription_AtSetMinutes() { string desc = ScheduleUtility.GetFullDescription("5,10,11-15,30 * * * *"); Assert.AreEqual("Every hour, at 5,10-15,30 minutes", desc); }
public void GetFullDescription_AtSpecificDaysOfTheWeekEveryOddDay() { string desc = ScheduleUtility.GetFullDescription("* * */5 * 1-3,5,6"); Assert.AreEqual("On Monday-Wednesday,Friday-Saturday, every 5 days, every minute", desc); }
public void GetFullDescription_EveryOtherDayOfTheWeekEveryMinute() { string desc = ScheduleUtility.GetFullDescription("* * * * */2"); Assert.AreEqual("On Sunday,Tuesday,Thursday,Saturday, every minute", desc); }
public void GetFullDescription_ReturnsDescriptionForDefaultSchedule() { string desc = ScheduleUtility.GetFullDescription("* * * * *"); Assert.AreEqual(ScheduleUtility.AnyTimeDescription, desc); }
public void GetFullDescription_AtSetHoursEveryMinute() { string desc = ScheduleUtility.GetFullDescription("* 0,8,12-16 * * *"); Assert.AreEqual("Every day, at midnight,8am,12pm-4pm, every minute", desc); }
public void GetFullDescription_AtASetHourEveryMinute() { string desc = ScheduleUtility.GetFullDescription("* 6 * * *"); Assert.AreEqual("Every day, at 6am, every minute", desc); }
public void GetFullDescription_FullEveryTest() { string desc = ScheduleUtility.GetFullDescription("*/5 */5 */5 */5 */5"); Assert.AreEqual("On Sunday,Friday, every 5 months, every 5 days, every 5 hours, every 5 minutes", desc); }
public void GetFullDescription_ThatBizarrelySpecificDayOfTheYearThatWillRunOnceEverySevenYears() { string desc = ScheduleUtility.GetFullDescription("30 16 24 4 5"); Assert.AreEqual("On Friday, in April, on the 24th day, at 16:30", desc); }
public void GetFullDescription_AtSetTimesEveryDay() { string desc = ScheduleUtility.GetFullDescription("0,20 0,12-14 * * *"); Assert.AreEqual("Every day, at 00:00,00:20,12:00,12:20-14:00,14:20", desc); }
public void GetFullDescription_EveryFewMintues() { string desc = ScheduleUtility.GetFullDescription("*/3 * * * *"); Assert.AreEqual("Every 3 minutes", desc); }