private void RefreshRow() { PolicyName = Policy.Name(); PolicyVmCount = Policy.VMs.FindAll(vm => Policy.Connection.Resolve(vm).is_a_real_vm()).Count; PolicyStatus = Policy.enabled ? Messages.ENABLED : Messages.DISABLED; //the policy is in server's local time zone if (serverTimeInfo.HasValue) { NextRunLocalToServer = Policy.GetNextRunTime(serverTimeInfo.Value.ServerLocalTime); } if (serverTimeInfo.HasValue && NextRunLocalToServer.HasValue) { NextRunLocalToClient = HelpersGUI.RoundToNearestQuarter(NextRunLocalToServer.Value + serverTimeInfo.Value.ServerClientTimeZoneDiff); } if (AlertMessages.Count > 0) { if (AlertMessages[0].priority == PolicyAlert.INFO_PRIORITY) { PolicyLastResult = Messages.VMSS_SUCCEEDED; PolicyLastResultImage = Resources._075_TickRound_h32bit_16; } else { PolicyLastResult = Messages.FAILED; PolicyLastResultImage = Resources._075_WarningRound_h32bit_16; } } else { PolicyLastResult = Messages.NOT_YET_RUN; PolicyLastResultImage = null; } _name.Value = PolicyName; _numVMs.Value = PolicyVmCount; _status.Value = PolicyStatus; _lastResult.Value = PolicyLastResult; _lastResult.Image = PolicyLastResultImage; _nextRunClientLocal.Value = NextRunLocalToClient.HasValue ? HelpersGUI.DateTimeToString(NextRunLocalToClient.Value, Messages.DATEFORMAT_DMY_HM, true) : Messages.VMSS_HOST_NOT_LIVE; _nextRunServerLocal.Value = NextRunLocalToServer.HasValue ? HelpersGUI.DateTimeToString(NextRunLocalToServer.Value, Messages.DATEFORMAT_DMY_HM, true) : Messages.VMSS_HOST_NOT_LIVE; }
private void PopulateTab() { try { updating = true; if (_policyCopy == null || !_serverTimeInfo.HasValue) { return; } var nextRunOnServer = _policyCopy.GetNextRunTime(_serverTimeInfo.Value.ServerLocalTime); if (!nextRunOnServer.HasValue) { return; } var nextRunOnClient = HelpersGUI.RoundToNearestQuarter(nextRunOnServer.Value + _serverTimeInfo.Value.ServerClientTimeZoneDiff); switch (_policyCopy.frequency) { case vmss_frequency.hourly: SetHourlyMinutes(nextRunOnClient.Minute); radioButtonHourly.Checked = true; break; case vmss_frequency.daily: dateTimePickerDaily.Value = new DateTime(1970, 1, 1, nextRunOnClient.Hour, nextRunOnClient.Minute, 0); radioButtonDaily.Checked = true; break; case vmss_frequency.weekly: dateTimePickerWeekly.Value = new DateTime(1970, 1, 1, nextRunOnClient.Hour, nextRunOnClient.Minute, 0); daysWeekCheckboxes.SelectedDays = VMSS.BackUpScheduleDays(_policyCopy.schedule); radioButtonWeekly.Checked = true; break; } numericUpDownRetention.Value = _policyCopy.retained_snapshots; } finally { updating = false; RecalculateSchedule(); } }
private void RecalculateSchedule() { if (updating) { return; } Schedule = new Dictionary <string, string>(); DateTime?nextRunOnClient = null; DateTime?nextRunOnServer = null; if (radioButtonHourly.Checked && int.TryParse(comboBoxMin.SelectedItem.ToString(), out int min)) { SubText = FormattedSchedule = string.Format(Messages.HOURLY_SCHEDULE_FORMAT, min); nextRunOnClient = VMSS.GetHourlyDate(DateTime.Now, min); if (_serverTimeInfo.HasValue) { nextRunOnServer = HelpersGUI.RoundToNearestQuarter(nextRunOnClient.Value - _serverTimeInfo.Value.ServerClientTimeZoneDiff); Schedule["min"] = nextRunOnServer.Value.Minute.ToString(); } } else if (radioButtonDaily.Checked) { SubText = FormattedSchedule = string.Format(Messages.DAILY_SCHEDULE_FORMAT, HelpersGUI.DateTimeToString(dateTimePickerDaily.Value, Messages.DATEFORMAT_HM, true)); nextRunOnClient = VMSS.GetDailyDate(DateTime.Now, dateTimePickerDaily.Value.Minute, dateTimePickerDaily.Value.Hour); if (_serverTimeInfo.HasValue) { nextRunOnServer = HelpersGUI.RoundToNearestQuarter(nextRunOnClient.Value - _serverTimeInfo.Value.ServerClientTimeZoneDiff); Schedule["hour"] = nextRunOnServer.Value.Hour.ToString(); Schedule["min"] = nextRunOnServer.Value.Minute.ToString(); } } else if (radioButtonWeekly.Checked && daysWeekCheckboxes.AnySelected()) { var days = daysWeekCheckboxes.SelectedDays; var longString = string.Join(", ", days.Select(d => HelpersGUI.DayOfWeekToString(d))); var shortString = string.Join(", ", days.Select(d => HelpersGUI.DayOfWeekToShortString(d))); FormattedSchedule = string.Format(Messages.WEEKLY_SCHEDULE_FORMAT, HelpersGUI.DateTimeToString(dateTimePickerWeekly.Value, Messages.DATEFORMAT_HM, true), longString); SubText = string.Format(Messages.WEEKLY_SCHEDULE_FORMAT, HelpersGUI.DateTimeToString(dateTimePickerWeekly.Value, Messages.DATEFORMAT_HM, true), shortString); var nextClientRuns = VMSS.GetWeeklyDates(DateTime.Now, dateTimePickerWeekly.Value.Minute, dateTimePickerWeekly.Value.Hour, days); if (_serverTimeInfo.HasValue && nextClientRuns.Count > 0) { nextRunOnClient = nextClientRuns[0]; var nextServerRuns = nextClientRuns.Select(n => HelpersGUI.RoundToNearestQuarter(n - _serverTimeInfo.Value.ServerClientTimeZoneDiff)).ToList(); nextRunOnServer = nextServerRuns[0]; Schedule["hour"] = nextRunOnServer.Value.Hour.ToString(); Schedule["min"] = nextRunOnServer.Value.Minute.ToString(); Schedule["days"] = string.Join(",", nextServerRuns.Select(n => n.DayOfWeek.ToString())).ToLower(); } } if (string.IsNullOrEmpty(FormattedSchedule)) { FormattedSchedule = Messages.UNKNOWN; } if (string.IsNullOrEmpty(SubText)) { SubText = Messages.UNKNOWN; } RefreshTime(nextRunOnServer, nextRunOnClient); OnPageUpdated(); if (Populated != null) { Populated(); } }