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); }
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); }