示例#1
0
        public bool AddToSchedule(string serviceName, int accountID, DateTime targetTime, Edge.Core.SettingsCollection options)
        {
            bool respond = true;

            try
            {
                ServiceConfiguration myServiceConfiguration = new ServiceConfiguration();
                ServiceConfiguration baseConfiguration      = new ServiceConfiguration();
                ActiveServiceElement activeServiceElement   = new ActiveServiceElement(EdgeServicesConfiguration.Current.Accounts.GetAccount(accountID).Services[serviceName]);
                if (options != null)
                {
                    foreach (string option in options.Keys)
                    {
                        activeServiceElement.Options[option] = options[option];
                    }
                }
                ServiceElement serviceElement = EdgeServicesConfiguration.Current.Services[serviceName];

                //base configuration;
                baseConfiguration.Name                    = serviceElement.Name;
                baseConfiguration.MaxConcurrent           = serviceElement.MaxInstances;
                baseConfiguration.MaxCuncurrentPerProfile = serviceElement.MaxInstancesPerAccount;


                //configuration per profile

                myServiceConfiguration = new ServiceConfiguration();

                myServiceConfiguration.Name = activeServiceElement.Name;
                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  = DateTime.Now,
                    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       = accountID,
                    Name     = accountID.ToString(),
                    Settings = new Dictionary <string, object>()
                };
                profile.Settings.Add("AccountID", accountID);
                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);
        }
示例#2
0
        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));
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
            }
        }