private IList <string> GetSuitableDictionaryFor(SheduleFrequencyProperty property) { if (property.Occurs == RhythmByDate.OneTime) { return(AddUnitaryAddIns((SingleLanchFrequency)property)); } var dict = new List <string> { "Выполняется" }; switch (property.Occurs) { case RhythmByDate.Daily: dict.AddRange(AddDailyAddIns((DailyFrequency)property)); break; case RhythmByDate.Weekly: dict.AddRange(AddWeeklyAddIns((WeeklyFrequency)property)); break; case RhythmByDate.Monthly: dict.AddRange(AddMonthlyAddIns((MonthlyFrequency)property)); break; } dict.AddRange(AddTimeAddIns(property.DailyFrequency)); dict.Add("Расписание будет использовано"); //ScheduleWillBeUsed dict.Add(string.Format(DescriptionFormattingString, (property.IsInfinite ? @"с" : @"между"), //starting on, between property.DurationFrom.ToShortDateString())); if (!property.IsInfinite) { dict.Add(string.Format(DescriptionFormattingString, @"и", property.DurationTo.ToShortDateString()));//and2 } dict.Add(string.Format(DescriptionFormattingString, string.Empty, ".")); return(dict); }
/// <summary> /// Возвращает локализованное представление описания для указанного расписания <see cref="SheduleFrequencyProperty"/>. /// </summary> /// <param name="property">Расписание.</param> /// <returns>Локализованная строка расписания <see cref="SheduleFrequencyProperty"/>.</returns> public string DescriptionFor(SheduleFrequencyProperty property) { var descr = new StringBuilder(); IList <string> dict = GetSuitableDictionaryFor(property); for (int i = 0; i < dict.Count; i++) { string key; string value = string.Empty; if (dict[i].Contains(DescriptionValuesDelimeter)) { string[] words = dict[i].Split(DescriptionValuesDelimeter); key = words.First(); value = words.Last(); } else { key = dict[i]; } if (!string.IsNullOrEmpty(key)) { // key = _resourceStore.GetValueForKey(ResourceType.PageContent, key); descr.AppendFormat(i == 0 ? "{0}" : " {0}", key); } if (string.IsNullOrEmpty(value)) { continue; } descr.AppendFormat(value.Length > 1 ? " {0}" : (_delimeters.Contains(value) ? "{0}" : " {0}"), value); } return(descr.ToString()); }
protected Sheduler(string type, bool isPeriodic) { _createdOn = DateTime.Now; _iteration = 0; _isEnabled = true; _isKill = false; _type = type; if (isPeriodic) { _frequency = new DailyFrequency(); } else { _frequency = new SingleLanchFrequency(DateTime.Now.AddHours(2)); } }
private SchedulerModel LoadSheduling(SheduleFrequencyProperty sheduler) { SchedulerModel model = new SchedulerModel(); switch (sheduler.Occurs) { case RhythmByDate.OneTime: model.cDate = _shaper.Frequency.DurationFrom.Add(sheduler.DailyFrequency.StartingAt); break; case RhythmByDate.Daily: model.DailyPeriod = sheduler.Period; break; case RhythmByDate.Weekly: model.WeeklyPeriod = sheduler.Period; List <DayOfWeek> recuring = ((WeeklyFrequency)sheduler).RecuringDays; model.Monday = recuring.Contains(DayOfWeek.Monday); model.Tuesday = recuring.Contains(DayOfWeek.Tuesday); model.Wednesday = recuring.Contains(DayOfWeek.Wednesday); model.Thursday = recuring.Contains(DayOfWeek.Thursday); model.Friday = recuring.Contains(DayOfWeek.Friday); model.Saturday = recuring.Contains(DayOfWeek.Saturday); model.Sunday = recuring.Contains(DayOfWeek.Sunday); break; case RhythmByDate.Monthly: model.MonthlyPeriod = model.tbxMonthNumFor = sheduler.Period; if (((MonthlyFrequency)sheduler).IsDefinedByDay) { model.RblMonthDetail = false; model.DayOffset = ((MonthlyFrequency)sheduler).DayOffset; } else { model.RblMonthDetail = true; KeyValuePair <RhythmByWeek, DayOfWeek>?datePart = ((MonthlyFrequency)sheduler).DayOfWeek; if (!datePart.HasValue) { return(model); } foreach (var item in model.WeekPartList) { item.Selected = item.Value == ((int)datePart.Value.Key).ToString(); if (item.Selected) { model.ddlWeekPart = ((int)datePart.Value.Key); } } foreach (var item in model.DayOfWeekList) { item.Selected = item.Value == ((int)datePart.Value.Value).ToString(); if (item.Selected) { model.ddlWeeks = (int)datePart.Value.Value; } } } break; } foreach (var item in model.DateRhythmList) { item.Selected = item.Value == ((int)sheduler.Occurs).ToString(); if (item.Selected) { model.ddlDateRhythm = (int)sheduler.Occurs; } } TimeSpanFrequency daily = sheduler.DailyFrequency; if (daily.IsSingleLanch) { model.cTimeConst = DateTime.Now.Date.Add(daily.StartingAt); } else { model.IsSingleLanch = true; //foreach (ListItem item in IsSingleLanch.Items) //{ // item.Selected = item.Value == @"1"; //} foreach (var item in model.RhythmByTimeList) { item.Selected = item.Value == ((int)daily.OccursEvery).ToString(); if (item.Selected) { model.OccursEvery = (int)daily.OccursEvery; } } model.StartingAt = new DateTime().Add(daily.StartingAt); model.EndingAt = new DateTime().Add(daily.EndingAt); model.SingleLanchPeriod = daily.Period; } model.DurationFrom = sheduler.DurationFrom; if (!sheduler.IsInfinite) { //foreach (ListItem item in rblStopDetail.Items) // item.Selected = item.Value == @"1"; model.IsInfinite = false; model.DurationTo = sheduler.DurationTo; } else { model.IsInfinite = true; } return(model); }
private SheduleFrequencyProperty ApplySheduling(Sofia.WebSite.Models.SchedulerModel model) { SheduleFrequencyProperty frequencyProperty = null; if (model.FrequencyType == 0) { return(new SingleLanchFrequency(model.cDate)); } var periodType = (RhythmByDate)Enum.Parse(typeof(RhythmByDate), (model.ddlDateRhythm).ToString()); switch (periodType) { case RhythmByDate.Daily: frequencyProperty = new DailyFrequency { Period = model.DailyPeriod }; break; case RhythmByDate.Weekly: frequencyProperty = new WeeklyFrequency { Period = model.WeeklyPeriod }; var daysOfWeek = new HashSet <DayOfWeek>(); if (model.Monday) { daysOfWeek.Add(DayOfWeek.Monday); } if (model.Tuesday) { daysOfWeek.Add(DayOfWeek.Tuesday); } if (model.Wednesday) { daysOfWeek.Add(DayOfWeek.Wednesday); } if (model.Thursday) { daysOfWeek.Add(DayOfWeek.Thursday); } if (model.Friday) { daysOfWeek.Add(DayOfWeek.Friday); } if (model.Saturday) { daysOfWeek.Add(DayOfWeek.Saturday); } if (model.Sunday) { daysOfWeek.Add(DayOfWeek.Sunday); } ((WeeklyFrequency)frequencyProperty).SetDays(daysOfWeek); break; case RhythmByDate.Monthly: frequencyProperty = new MonthlyFrequency(model.RblMonthDetail); if (model.RblMonthDetail == false) { frequencyProperty.Period = model.MonthlyPeriod; ((MonthlyFrequency)frequencyProperty).DayOffset = model.DayOffset; } else { frequencyProperty.Period = model.tbxMonthNumFor; ((MonthlyFrequency)frequencyProperty).DayOfWeek = new KeyValuePair <RhythmByWeek, DayOfWeek>( (RhythmByWeek) Enum.Parse(typeof(RhythmByWeek), model.ddlWeekPart.ToString()), (DayOfWeek) Enum.Parse(typeof(DayOfWeek), model.ddlWeeks.ToString())); } break; } if (frequencyProperty == null) { return(null); } frequencyProperty.DurationFrom = model.DurationFrom.Date; if (model.IsInfinite == false) { frequencyProperty.DurationTo = model.DurationTo.Date; } frequencyProperty.DailyFrequency = ApplyTimeRange(model); return(frequencyProperty); }
public ActionResult Index(SchedulerModel model) { var session = Db <WebEnvironmentFiact> .NSession; if (model.Id == 0) { switch (model.Type) { case "import": _shaper = new ImportSheduling(); break; case "export": _shaper = new ExportSheduling(); break; default: _shaper = new MoreSheduling(); break; } } else { _shaper = session.Get <Sheduler>(model.Id); try { using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta")) { IImportAxapta channel = factory.CreateChannel(); var id = _shaper.Id; channel.RemoveShedule(id); } Thread.Sleep(2000); }catch (Exception e) { } } _shaper.IsEnabled = model.IsEnabled; _shaper.IsKill = model.IsKill; _shaper.Runtime = model.Runtime; _shaper.Param = model.Param; _shaper.TimeGetData = model.TimeGetData; _shaper.Name = model.Name; SheduleFrequencyProperty oldFreq = _shaper.Frequency; session.Delete(oldFreq); _shaper.Frequency = ApplySheduling(model); _shaper.UpdateShedule(); model = LoadSheduling(_shaper.Frequency); model.IsEnabled = _shaper.IsEnabled; model.Name = _shaper.Name; if (_shaper.Frequency is SingleLanchFrequency) { model.FrequencyType = 0; } else { model.FrequencyType = 1; } model.Id = _shaper.Id; model.Runtime = _shaper.Runtime; model.IsKill = _shaper.IsKill; model.Param = _shaper.Param; model.TimeGetData = _shaper.TimeGetData; LoadEntity(model); ModelState.Clear(); session.Save(_shaper); session.Flush(); if (_shaper.IsEnabled) { try { using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta")) { IImportAxapta channel = factory.CreateChannel(); channel.AddShedule(_shaper.Id); } }catch (Exception e) { } } return(View(model)); }