private void addBtn_Click(object sender, EventArgs e) { ServicePriority servicePriority = ServicePriority.Low; var options = new Edge.Core.SettingsCollection(); DateTime targetDateTime = new DateTime(dateToRunPicker.Value.Year, dateToRunPicker.Value.Month, dateToRunPicker.Value.Day, timeToRunPicker.Value.Hour, timeToRunPicker.Value.Minute, 0); if (priorityCmb.SelectedItem != null) { switch (priorityCmb.SelectedItem.ToString()) { case "Low": { servicePriority = ServicePriority.Low; break; } case "Normal": { servicePriority = ServicePriority.Normal; break; } case "High": { servicePriority = ServicePriority.High; break; } case "Immediate": { servicePriority = ServicePriority.Immediate; break; } } } int countedSelectedServices = 0; foreach (TreeNode accountNode in servicesTreeView.Nodes) { foreach (TreeNode serviceNode in accountNode.Nodes) { if (!serviceNode.Checked) { continue; } countedSelectedServices++; AccountElement account = (AccountElement)accountNode.Tag; ActiveServiceElement service = (ActiveServiceElement)serviceNode.Tag; if (useOptionsCheckBox.Checked) { foreach (ListViewItem item in optionsListView.Items) { options.Add(item.SubItems[0].Text.Trim(), item.SubItems[1].Text.Trim()); } DateTime from = FromPicker.Value; DateTime to = toPicker.Value; if (to.Date < from.Date || to.Date > DateTime.Now.Date) { MessageBox.Show(String.Format("Account {0} service {1}: To date must be equal or greater than from date, and both should be less then today's date", account.ID, service.Name )); continue; } DateTimeRange daterange = new DateTimeRange() { Start = new DateTimeSpecification() { BaseDateTime = from, Hour = new DateTimeTransformation() { Type = DateTimeTransformationType.Exact, Value = 0 }, }, End = new DateTimeSpecification() { BaseDateTime = to, Hour = new DateTimeTransformation() { Type = DateTimeTransformationType.Max }, } }; options.Add(PipelineService.ConfigurationOptionNames.TimePeriod, daterange.ToAbsolute().ToString()); } _listener.AddToSchedule(service, account, targetDateTime, options, servicePriority); options.Clear(); } } MessageBox.Show(String.Format("{0} unplanned services were added.", countedSelectedServices)); }
private void addBtn_Click(object sender, EventArgs e) { bool allSucceed = true; try { ServicePriority servicePriority = ServicePriority.Low; Edge.Core.SettingsCollection options = new Edge.Core.SettingsCollection(); DateTime targetDateTime = new DateTime(dateToRunPicker.Value.Year, dateToRunPicker.Value.Month, dateToRunPicker.Value.Day, timeToRunPicker.Value.Hour, timeToRunPicker.Value.Minute, 0); bool result = false; if (priorityCmb.SelectedItem != null) { switch (priorityCmb.SelectedItem.ToString()) { case "Low": { servicePriority = ServicePriority.Low; break; } case "Normal": { servicePriority = ServicePriority.Normal; break; } case "High": { servicePriority = ServicePriority.High; break; } case "Immediate": { servicePriority = ServicePriority.Immediate; break; } } } int countedSelectedServices = 0; foreach (TreeNode accountNode in servicesTreeView.Nodes) { foreach (TreeNode serviceNode in accountNode.Nodes) { if (serviceNode.Checked) { countedSelectedServices++; AccountElement account = (AccountElement)accountNode.Tag; ActiveServiceElement service = (ActiveServiceElement)serviceNode.Tag; if (useOptionsCheckBox.Checked) { foreach (ListViewItem item in optionsListView.Items) { options.Add(item.SubItems[0].Text.Trim(), item.SubItems[1].Text.Trim()); } DateTime from = FromPicker.Value; DateTime to = toPicker.Value; if (to.Date < from.Date || to.Date > DateTime.Now.Date) { throw new Exception("to date must be equal or greater then from date, and both should be less then today's date"); } if (chkBackward.Checked) { while (from.Date <= to.Date) { //For backward compatbility options["Date"] = from.ToString("yyyyMMdd"); result = _listner.FormAddToSchedule(service, account, targetDateTime, options, servicePriority); options.Clear(); if (!result) { allSucceed = result; MessageBox.Show(string.Format("Service {0} for account {1} did not run", service.Name, accountNode.Text)); } from = from.AddDays(1); } } else { DateTimeRange daterange = new DateTimeRange() { Start = new DateTimeSpecification() { BaseDateTime = from, Hour = new DateTimeTransformation() { Type = DateTimeTransformationType.Exact, Value = 0 }, }, End = new DateTimeSpecification() { BaseDateTime = to, Hour = new DateTimeTransformation() { Type = DateTimeTransformationType.Max }, } }; options.Add(PipelineService.ConfigurationOptionNames.TimePeriod, daterange.ToAbsolute().ToString()); result = _listner.FormAddToSchedule(service, account, targetDateTime, options, servicePriority); options.Clear(); if (!result) { allSucceed = result; MessageBox.Show(string.Format("Service {0} for account {1} did not run", service.Name, accountNode.Text)); } } } else { result = _listner.FormAddToSchedule(service, account, targetDateTime, options, servicePriority); if (!result) { allSucceed = result; } } } } } if (!allSucceed) { throw new Exception("Some services did not run"); } else { if (countedSelectedServices > 0) { MessageBox.Show(@"Unplaned service\services added successfully"); } else { MessageBox.Show(@"No services selected"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }