/// <summary> /// Create a service object by the function parameters. /// </summary> /// <param name="serviceElement"></param> /// <param name="serviceInstanceType"></param> /// <param name="serviceTimeScheduled"></param> /// <returns></returns> private ServiceInstance CreateNewService(EnabledConfigurationElement enabledConfigurationElement, DateTime serviceTimeScheduled, SchedulingRuleElement activeSchedulingRule, int accountID) { //// Create new service list if needed. //if (!_scheduleTable.ContainsKey(accountServiceElement.Uses.Element.Name)) //{ // _scheduleTable.Add(accountServiceElement.Uses.Element.Name, new ServiceList(accountServiceElement.Uses.Element)); //} ServiceInstance service; try { service = Service.CreateInstance(enabledConfigurationElement, accountID); } catch (Exception ex) { Log.Write("Exception occured while performing CreateInstance.", ex); return(null); } service.StateChanged += _stateChangedHandler; service.OutcomeReported += _outcomeReportedHandler; service.ChildServiceRequested += _childServiceRequestedHandler; service.ActiveSchedulingRule = activeSchedulingRule; service.TimeScheduled = serviceTimeScheduled; return(service); }
/*=========================*/ #endregion #region Generate /*=========================*/ /// <summary> /// /// </summary> internal static ServiceInstance Generate(EnabledConfigurationElement config, ServiceInstance parentInstance, int accountID) { ActiveServiceElement activeConfig; // Get the right constructor if (config is ServiceElement) { activeConfig = new ActiveServiceElement((ServiceElement)config); } else if (config is ExecutionStepElement) { activeConfig = new ActiveServiceElement((ExecutionStepElement)config); } else if (config is AccountServiceElement) { activeConfig = new ActiveServiceElement((AccountServiceElement)config); } else if (config is AccountServiceSettingsElement) { activeConfig = new ActiveServiceElement((AccountServiceSettingsElement)config); } else { throw new ArgumentException("Configuration is an unrecognized class.", "config"); } // Don't allow non-enabled services if (!activeConfig.IsEnabled) { throw new InvalidOperationException(String.Format("Cannot create an instance of a disabled service. Set IsEnabled to true in the configuration file in order to run. Service name: {0}", activeConfig.Name)); } return(new ServiceInstance(activeConfig, parentInstance, accountID)); }
/// <summary> /// Create a service by serviceElement and add it as a manual request. /// </summary> /// <param name="serviceElement">the service will be created by this service element settings.</param> public void AddManualRequest(EnabledConfigurationElement serviceElement, int accountID) { //_scheduleTable.Timer.Enabled = false; _scheduleTable.RunTaskSync.WaitOne(); ServiceInstance service; try { service = CreateNewService(serviceElement, DateTime.Now, null, accountID); } catch (Exception ex) { Log.Write(string.Format("Can't add the service {0} for accoutID {1}", serviceElement.ToString(), accountID.ToString()), ex, LogMessageType.Error); //_scheduleTable.Timer.Enabled = true; _scheduleTable.RunTaskSync.Release(); return; } if (service != null) { _scheduleTable.AddService(service); } //_scheduleTable.Timer.Enabled = true; _scheduleTable.RunTaskSync.Release(); }
/// <summary> /// /// </summary> public static ServiceInstance CreateInstance(EnabledConfigurationElement configuration, ServiceInstance parentInstance, int accountID) { return(ServiceInstance.Generate(configuration, parentInstance, accountID)); }
/*=========================*/ #endregion #region CreateInstance /*=========================*/ /// <summary> /// /// </summary> public static ServiceInstance CreateInstance(EnabledConfigurationElement configuration) { return(ServiceInstance.Generate(configuration, null, -1)); }