public bool AddToSchedule(string serviceName, int accountID, DateTime targetTime, Edge.Core.SettingsCollection options) { AccountElement account = EdgeServicesConfiguration.Current.Accounts.GetAccount(accountID); if (account == null) { Log.Write(Program.LS, String.Format("Ignoring AddToSchedule request for account {0} which does not exist.", accountID), LogMessageType.Warning); return(false); } AccountServiceElement service = account.Services[serviceName]; if (service == null) { Log.Write(Program.LS, String.Format("Ignoring AddToSchedule request for service {0} which does not exist in account {1}.", serviceName, accountID), LogMessageType.Warning); return(false); } var activeServiceElement = new ActiveServiceElement(service); ServicePriority priority = activeServiceElement.Options.ContainsKey("ServicePriority") ? (ServicePriority)Enum.Parse(typeof(ServicePriority), activeServiceElement.Options["ServicePriority"]) : ServicePriority.Normal; AddToSchedule(activeServiceElement, account, targetTime, options, priority); return(true); }
public ServiceInstanceInfo(ServiceInstance instance) { _accountID = instance.AccountID; _instanceID = instance.InstanceID; _priority = instance.Priority; _config = instance.Configuration; _rule = instance.ActiveSchedulingRule; _timeStarted = instance.TimeStarted; _timeScheduled = instance.TimeScheduled; _serviceUrl = instance.ServiceUrl; if (instance.ParentInstance != null) { _parentInstanceData = new ServiceInstanceInfo(instance.ParentInstance); } }
public BotServiceInfo(string name, string about, ServicePriority priority) { this.Name = name; this.About = about; this.Priority = priority; }
public static int Compare(ServicePriority a, ServicePriority b, bool highestFirst) => highestFirst?Compare(b, a) : Compare(a, b);
public static int Compare(ServicePriority a, ServicePriority b) => ((int)a).CompareTo((int)b);
public bool FormAddToSchedule(ActiveServiceElement activeServiceElement, AccountElement account, DateTime targetTime, Edge.Core.SettingsCollection options, ServicePriority servicePriority) { bool respond = true; try { ServiceConfiguration myServiceConfiguration = new ServiceConfiguration(); ServiceConfiguration baseConfiguration = new ServiceConfiguration(); if (options != null) { foreach (string option in options.Keys) { activeServiceElement.Options[option] = options[option]; } } //ServiceElement serviceElement = EdgeServicesConfiguration.Current.Services[activeServiceElement.Name]; //base configuration; baseConfiguration.Name = activeServiceElement.Name; baseConfiguration.MaxConcurrent = activeServiceElement.MaxInstances; baseConfiguration.MaxCuncurrentPerProfile = activeServiceElement.MaxInstancesPerAccount; //configuration per profile myServiceConfiguration = new ServiceConfiguration(); myServiceConfiguration.Name = activeServiceElement.Name; myServiceConfiguration.priority = (int)servicePriority; if (activeServiceElement.Options.ContainsKey("ServicePriority")) { myServiceConfiguration.priority = int.Parse(activeServiceElement.Options["ServicePriority"]); } myServiceConfiguration.MaxConcurrent = (activeServiceElement.MaxInstances == 0) ? 9999 : activeServiceElement.MaxInstances; myServiceConfiguration.MaxCuncurrentPerProfile = (activeServiceElement.MaxInstancesPerAccount == 0) ? 9999 : activeServiceElement.MaxInstancesPerAccount; myServiceConfiguration.LegacyConfiguration = activeServiceElement; // //scheduling rules myServiceConfiguration.SchedulingRules.Add(new SchedulingRule() { Scope = SchedulingScope.UnPlanned, SpecificDateTime = targetTime, MaxDeviationAfter = new TimeSpan(0, 0, 45, 0, 0), Hours = new List <TimeSpan>(), GuidForUnplaned = Guid.NewGuid() }); myServiceConfiguration.SchedulingRules[0].Hours.Add(new TimeSpan(0, 0, 0, 0)); myServiceConfiguration.BaseConfiguration = baseConfiguration; Edge.Core.Scheduling.Objects.Profile profile = new Edge.Core.Scheduling.Objects.Profile() { ID = account.ID, Name = account.Name, Settings = new Dictionary <string, object>() }; profile.Settings.Add("AccountID", account.ID.ToString()); myServiceConfiguration.SchedulingProfile = profile; _scheduler.AddNewServiceToSchedule(myServiceConfiguration); } catch (Exception ex) { respond = false; Edge.Core.Utilities.Log.Write("AddManualServiceListner", ex.Message, ex, Edge.Core.Utilities.LogMessageType.Error); } return(respond); }
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)); }
public void AddToSchedule(ActiveServiceElement activeServiceElement, AccountElement account, DateTime targetTime, Edge.Core.SettingsCollection options, ServicePriority servicePriority) { if (options != null) { foreach (string option in options.Keys) { activeServiceElement.Options[option] = options[option]; } } //base configuration var baseConfiguration = new ServiceConfiguration() { Name = activeServiceElement.Name, MaxConcurrent = activeServiceElement.MaxInstances, MaxConcurrentPerProfile = activeServiceElement.MaxInstancesPerAccount }; //configuration per profile var instanceConfiguration = new ServiceConfiguration() { BaseConfiguration = baseConfiguration, Name = activeServiceElement.Name, MaxConcurrent = (activeServiceElement.MaxInstances == 0) ? 9999 : activeServiceElement.MaxInstances, MaxConcurrentPerProfile = (activeServiceElement.MaxInstancesPerAccount == 0) ? 9999 : activeServiceElement.MaxInstancesPerAccount, LegacyConfiguration = activeServiceElement }; //scheduling rules instanceConfiguration.SchedulingRules.Add(new SchedulingRule() { Scope = SchedulingScope.UnPlanned, SpecificDateTime = targetTime, MaxDeviationAfter = TimeSpan.FromMinutes(30), Hours = new List <TimeSpan>(), GuidForUnplaned = Guid.NewGuid(), }); instanceConfiguration.SchedulingRules[0].Hours.Add(new TimeSpan(0, 0, 0, 0)); Profile profile = new Profile() { ID = account.ID, Name = account.ID.ToString(), Settings = new Dictionary <string, object>() }; profile.Settings.Add("AccountID", account.ID); instanceConfiguration.SchedulingProfile = profile; _scheduler.AddNewServiceToSchedule(instanceConfiguration); }
private void addBtn_Click(object sender, EventArgs e) { try { string[] serviceAndAccount; bool resultAll = true; ServicePriority servicePriority = ServicePriority.Low; for (int i = 0; i < servicesCheckedListBox.Items.Count; i++) { bool chk = servicesCheckedListBox.GetItemChecked(i); if (chk) { serviceAndAccount = servicesCheckedListBox.Items[i].ToString().Split(':'); string account = serviceAndAccount[0].Trim(); string serviceName = serviceAndAccount[1].Trim(); 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; } } } Easynet.Edge.Core.SettingsCollection options = new Easynet.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 (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"); } while (from.Date <= to.Date) { options["Date"] = from.ToString("yyyyMMdd"); result = _listner.FormAddToSchedule(serviceName, int.Parse(account), targetDateTime, options, servicePriority); from = from.AddDays(1); } } else { result = _listner.FormAddToSchedule(serviceName, int.Parse(account), targetDateTime, options, servicePriority); } if (result != true) { resultAll = result; } } } if (resultAll) { MessageBox.Show("Service has been added to schedule and will be runinng shortly"); this.Close(); } else { MessageBox.Show("one or more unplaned serivces did not schedule"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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); } }