/// <summary> /// Copies from. /// </summary> /// <param name="other">The other.</param> /// <exception cref="ArgumentException">Invalid type.</exception> public void CopyFrom(RecurrencePattern other) { if (this.GetType().FullName != other.GetType().FullName) { throw new ArgumentException("Invalid type"); } this.StartTime = other.StartTime; this.StopTime = other.StopTime; this.Times = other.Times; this.DailyFrequency = other.DailyFrequency; this.DailyInterval = other.DailyInterval; this.Frequency = other.Frequency; this.Interval = other.Interval; this.DayOrdinal = other.DayOrdinal; this.DayOfMonth = other.DayOfMonth; this.DaysOfWeekMask = other.DaysOfWeekMask; this.FirstDayOfWeek = other.FirstDayOfWeek; }
protected static RecurrencePattern Deserialize(string data) { RecurrencePattern o = null; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(data)); try { DataContractJsonSerializer ser = GetSerializer(); o = ser.ReadObject(ms) as RecurrencePattern; } catch (Exception e) { throw new RecurrencePatternLoadException(string.Format("Error thrown then read RecurrencePattern: {0}", e.Message)); } finally { ms.Close(); } return(o); }
private static RecurrenceType GetTypeFromRule(RecurrencePattern pattern) { switch (pattern.Frequency) { case RecurrenceFrequency.Daily: return(RecurrenceType.Daily); case RecurrenceFrequency.Weekly: if (pattern.Interval == 1 && pattern.DaysOfWeekMask == RecurrenceDays.WeekDays) { return(RecurrenceType.WeekDays); } return(RecurrenceType.Weekly); case RecurrenceFrequency.Monthly: if (pattern.DayOfMonth > 0) { return(RecurrenceType.Monthly); } return(RecurrenceType.MonthlyNth); } return(RecurrenceType.Weekly); }
private static RecurrenceType GetTypeFromRule(RecurrencePattern pattern) { switch (pattern.Frequency) { case RecurrenceFrequency.Daily: return RecurrenceType.Daily; case RecurrenceFrequency.Weekly: if (pattern.Interval == 1 && pattern.DaysOfWeekMask == RecurrenceDays.WeekDays) { return RecurrenceType.WeekDays; } return RecurrenceType.Weekly; case RecurrenceFrequency.Monthly: if (pattern.DayOfMonth > 0) { return RecurrenceType.Monthly; } return RecurrenceType.MonthlyNth; } return RecurrenceType.Weekly; }
/// <summary> /// Determines whether pattern is valid. /// </summary> /// <param name="pattern">The pattern.</param> /// <returns> /// <c>True</c> if pattern is valid; otherwise, <c>false</c>. /// </returns> internal static bool IsValidPattern(RecurrencePattern pattern) { if (pattern.Interval <= 0) { return false; } switch (pattern.Frequency) { case RecurrenceFrequency.None: return false; case RecurrenceFrequency.Secondly: case RecurrenceFrequency.Minutely: case RecurrenceFrequency.Hourly: { if (pattern.Interval == 0) return false; } break; case RecurrenceFrequency.Daily: { if (pattern.DaysOfWeekMask == RecurrenceDays.None || pattern.DayOfMonth.HasValue || pattern.DayOrdinal.HasValue) { return false; } break; } case RecurrenceFrequency.Weekly: break; case RecurrenceFrequency.Monthly: if (pattern.DayOfMonth.HasValue && pattern.DayOfMonth.Value == 0) { return false; } break; default: break; } return true; }
/// <summary> /// <b>Deep</b> copies this instance. /// </summary> /// <returns> /// A <b>deep</b> copy of the current object. /// </returns> public RecurrencePattern Copy() { var rule = new RecurrencePattern(); rule.CopyFrom(this); return rule; }
private void LoadConfig() { _configValues.Clear(); string path = System.Reflection.Assembly.GetExecutingAssembly().Location.ToLowerInvariant(); Configuration cfg = ConfigurationManager.OpenExeConfiguration(path); foreach (string key in cfg.AppSettings.Settings.AllKeys) _configValues.Add(key, cfg.AppSettings.Settings[key].Value); // schedule parameters try { if (_configValues.ContainsKey(ConfigConstants.CriticalSchedule)) _criticalSchedule = RecurrencePattern.Load(_configValues[ConfigConstants.CriticalSchedule]); } catch { } try { if (_configValues.ContainsKey(ConfigConstants.WarningSchedule)) _warningSchedule = RecurrencePattern.Load(_configValues[ConfigConstants.WarningSchedule]); } catch { } }
public void LoadConfig() { bool scr; sendCritical.IsChecked = false; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CheckCriticalUpdates) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.CheckCriticalUpdates].Value, out scr)) sendCritical.IsChecked = scr; sendSecurity.IsChecked = false; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CheckSecurityUpdates) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.CheckSecurityUpdates].Value, out scr)) sendSecurity.IsChecked = scr; sendDefinition.IsChecked = false; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CheckDefinitionUpdates) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.CheckDefinitionUpdates].Value, out scr)) sendDefinition.IsChecked = scr; sendUpdate.IsChecked = false; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CheckUpdates) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.CheckUpdates].Value, out scr)) sendUpdate.IsChecked = scr; sendFuture.IsChecked = false; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CheckFuturePacks) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.CheckFuturePacks].Value, out scr)) sendFuture.IsChecked = scr; sendOther.IsChecked = false; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CheckOtherUpdates) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.CheckOtherUpdates].Value, out scr)) sendOther.IsChecked = scr; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.SendCriticalUpdatesAsCritical) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.SendCriticalUpdatesAsCritical].Value, out scr)) { criticalUpdatesAsCritical.IsChecked = scr; criticalUpdatesAsWarning.IsChecked = !scr; } if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.SendSecurityUpdatesAsCritical) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.SendSecurityUpdatesAsCritical].Value, out scr)) { securityUpdatesAsCritical.IsChecked = scr; securityUpdatesAsWarning.IsChecked = !scr; } if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.SendDefinitionUpdatesAsCritical) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.SendDefinitionUpdatesAsCritical].Value, out scr)) { definitionUpdatesAsCritical.IsChecked = scr; definitionUpdatesAsWarning.IsChecked = !scr; } if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.SendUpdatesAsCritical) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.SendUpdatesAsCritical].Value, out scr)) { updatesAsCritical.IsChecked = scr; updatesAsWarning.IsChecked = !scr; } if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.SendFuturePacksAsCritical) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.SendFuturePacksAsCritical].Value, out scr)) { futurePackAsCritical.IsChecked = scr; futurePackAsWarning.IsChecked = !scr; } if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.SendOtherUpdatesAsCritical) == true) if (bool.TryParse(_cfg.AppSettings.Settings[ConfigConstants.SendOtherUpdatesAsCritical].Value, out scr)) { otherUpdatesAsCritical.IsChecked = scr; otherUpdatesAsWarning.IsChecked = !scr; } if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CriticalServiceName) == true) criticalServiceName.Text = _cfg.AppSettings.Settings[ConfigConstants.CriticalServiceName].Value; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.WarningServiceName) == true) warningServiceName.Text = _cfg.AppSettings.Settings[ConfigConstants.WarningServiceName].Value; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.CriticalSchedule) == true) { try { _criticalSchedule = RecurrencePattern.Load(_cfg.AppSettings.Settings[ConfigConstants.CriticalSchedule].Value); } catch { _criticalSchedule = new RecurrencePattern(); } } if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.WarningSchedule) == true) { try { _warningSchedule = RecurrencePattern.Load(_cfg.AppSettings.Settings[ConfigConstants.WarningSchedule].Value); } catch { _warningSchedule = new RecurrencePattern(); } } }
private void warningSched_Click(object sender, RoutedEventArgs e) { Window w = InitScheduleWindow(_warningSchedule); w.Closed += (sx, ex) => { if (w.DialogResult == true) { _warningSchedule = ((NetClient.Common.Schedule.ScheduleView)w.Content).Pattern; } }; w.ShowDialog(); }
private static Window InitScheduleWindow(RecurrencePattern rPattern) { Window w = new Window(); w.SizeToContent = SizeToContent.WidthAndHeight; w.WindowStartupLocation = WindowStartupLocation.CenterScreen; NetClient.Common.Schedule.ScheduleView v = new NetClient.Common.Schedule.ScheduleView(); v.Pattern = rPattern; w.Content = v; w.Title = "Schedule settings"; w.ShowInTaskbar = false; w.WindowStyle = WindowStyle.SingleBorderWindow; w.ResizeMode = ResizeMode.NoResize; return w; }
private void GetValues() { _Pattern = new RecurrencePattern(); CultureInfo ci = new CultureInfo("en-US"); // time values if (this.dailyPeriodically.IsChecked == true) { TimeSpan tStart = new TimeSpan(); if (TimeSpan.TryParseExact(this.periodicallyStart.Text, "%h\\:mm", ci, out tStart) == true) _Pattern.StartTime = tStart; TimeSpan tStop = new TimeSpan(); if (TimeSpan.TryParseExact(this.periodicallyStop.Text, "%h\\:mm", ci, out tStop) == true) _Pattern.StopTime = tStop; int di = 1; int.TryParse(this.periodicallyMinutes.Text, out di); // shoul be checked convertion result for validate the form _Pattern.DailyInterval = di; } else { _Pattern.Times.AddRange((List<TimeSpan>)timesForSchedule.ItemsSource); } // day/week/month values // daily if (this.dailyPattern.IsChecked == true) { if (this.everyWeekDay.IsChecked == true) { _Pattern.Frequency = RecurrenceFrequency.Weekly; _Pattern.DaysOfWeekMask = RecurrenceDays.WeekDays; _Pattern.Interval = 1; } else { int interval = 1; int.TryParse(this.daysNumber.Text, out interval); _Pattern.Interval = interval; _Pattern.DaysOfWeekMask = RecurrenceDays.EveryDay; _Pattern.Frequency = RecurrenceFrequency.Daily; } } // weekly else if (this.weeklyPattern.IsChecked == true) { _Pattern.Frequency = RecurrenceFrequency.Weekly; int interval = 1; int.TryParse(this.recurrEveryWeeks.Text, out interval); _Pattern.Interval = interval; RecurrenceDays dayMask = RecurrenceDays.None; if (this.sunday.IsChecked == true) dayMask = dayMask | RecurrenceDays.Sunday; if (this.monday.IsChecked == true) dayMask = dayMask | RecurrenceDays.Monday; if (this.tuesday.IsChecked == true) dayMask = dayMask | RecurrenceDays.Tuesday; if (this.wednesday.IsChecked == true) dayMask = dayMask | RecurrenceDays.Wednesday; if (this.thursday.IsChecked == true) dayMask = dayMask | RecurrenceDays.Thursday; if (this.friday.IsChecked == true) dayMask = dayMask | RecurrenceDays.Friday; if (this.saturday.IsChecked == true) dayMask = dayMask | RecurrenceDays.Saturday; _Pattern.DaysOfWeekMask = dayMask; _Pattern.FirstDayOfWeek = CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek; } else if (this.monthlyPattern.IsChecked == true) { _Pattern.Frequency = RecurrenceFrequency.Monthly; if (this.monthlyDays.IsChecked == true) { int interval = 1; int.TryParse(this.monthlyDaysNum.Text, out interval); _Pattern.Interval = interval; int dayOfMonth = 1; int.TryParse(this.monthlyDaysMonths.Text, out dayOfMonth); _Pattern.DayOfMonth = dayOfMonth; } else if (this.monthlyNums.IsChecked == true) { switch (this.monthlyNum.Text) { case "first": _Pattern.DayOrdinal = 1; break; case "second": _Pattern.DayOrdinal = 2; break; case "third": _Pattern.DayOrdinal = 3; break; case "fourth": _Pattern.DayOrdinal = 4; break; case "last": _Pattern.DayOrdinal = 5; break; } if (this.monthlyNumType.Text == "Monday") _Pattern.DaysOfWeekMask = RecurrenceDays.Monday; else if (this.monthlyNumType.Text == "Tuesday") _Pattern.DaysOfWeekMask = RecurrenceDays.Tuesday; else if (this.monthlyNumType.Text == "Wednesday") _Pattern.DaysOfWeekMask = RecurrenceDays.Wednesday; else if (this.monthlyNumType.Text == "Thursday") _Pattern.DaysOfWeekMask = RecurrenceDays.Thursday; else if (this.monthlyNumType.Text == "Friday") _Pattern.DaysOfWeekMask = RecurrenceDays.Friday; else if (this.monthlyNumType.Text == "Saturday") _Pattern.DaysOfWeekMask = RecurrenceDays.Saturday; else if (this.monthlyNumType.Text == "Sunday") _Pattern.DaysOfWeekMask = RecurrenceDays.Sunday; int interval = 1; int.TryParse(this.monthlyValue.Text, out interval); _Pattern.Interval = interval; } } }