示例#1
0
        public void AddChildServiceToSchedule(Legacy.ServiceInstance legacyInstance)
        {
            ServiceConfiguration baseConfiguration;

            if (!_serviceBaseConfigurations.TryGetValue(legacyInstance.Configuration.Name, out baseConfiguration))
            {
                throw new KeyNotFoundException(String.Format("No base configuration exists for the service '{0}'.", legacyInstance.Configuration.Name));
            }

            Profile profile;

            if (!_profiles.TryGetValue(legacyInstance.AccountID, out profile))
            {
                throw new KeyNotFoundException(String.Format("No profile exists with the ID '{0}' (account ID).", legacyInstance.AccountID));
            }

            ServiceInstance childInstance = ServiceInstance.FromLegacyInstance(legacyInstance, baseConfiguration, profile);

            SchedulingRequest request = new SchedulingRequest(childInstance, new SchedulingRule()
            {
                SpecificDateTime  = DateTime.Now,
                Scope             = SchedulingScope.Unplanned,
                MaxDeviationAfter = TimeSpan.FromHours(1)
            }, DateTime.Now);

            AddRequestToSchedule(request);
        }
示例#2
0
        void instance_ChildServiceRequested(object sender, ServiceRequestedEventArgs e)
        {
            Edge.Core.Services.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;

            //e.RequestedService.OutcomeReported += new EventHandler(instance_OutcomeReported);
            e.RequestedService.StateChanged += new EventHandler <ServiceStateChangedEventArgs>(child_instance_StateChanged);

            e.RequestedService.Initialize();
        }
示例#3
0
        public static ServiceInstance FromLegacyInstance(Legacy.ServiceInstance legacyInstance, ServiceConfiguration configuration, Profile profile = null)
        {
            var serviceInstance = new ServiceInstance()
            {
                Configuration  = ServiceInstanceConfiguration.FromLegacyConfiguration(legacyInstance, configuration, profile ?? configuration.Profile),
                LegacyInstance = legacyInstance
            };

            serviceInstance.Configuration.Instance = serviceInstance;
            return(serviceInstance);
        }
示例#4
0
 void GridUpdateInstanceInner(legacy.ServiceInstance legacyInstance)
 {
     foreach (DataGridViewRow row in scheduleInfoGrid.Rows)
     {
         var rowData = (Scheduler.Entry)row.Tag;
         if (Object.Equals(rowData.Instance.LegacyInstance, legacyInstance))
         {
             GridUpdateRow(row);
             break;
         }
     }
 }
示例#5
0
        static void ActiveRuleProperty_Setting(object sender, ValueTranslationEventArgs e)
        {
            ServiceInstance current = (ServiceInstance)e.Entity;

            if ((int)current.State > (int)ServiceState.Uninitialized)
            {
                throw new InvalidOperationException("Cannot change properties after Initialize has been called.");
            }

            current._activeRule = (SchedulingRuleElement)e.Input;
            e.Output            = null;
        }
示例#6
0
        public static ServiceInstanceConfiguration FromLegacyConfiguration(Legacy.ServiceInstance legacyInstance, ServiceConfiguration baseConfiguration = null, Profile profile = null, Dictionary <string, string> options = null)
        {
            ServiceInstanceConfiguration configuration = ServiceConfiguration.FromLegacyConfiguration <ServiceInstanceConfiguration>(
                legacyInstance.Configuration,
                baseConfiguration,
                profile,
                options
                );

            configuration.SchedulingRules.Clear();
            return(configuration);
        }
示例#7
0
        void OnChildServiceRequested(int stepNumber, int attemptNumber, SettingsCollection options)
        {
            // Get the step configuration elements
            WorkflowStepElement           stepConfig   = this.Configuration.Workflow[stepNumber];
            AccountServiceSettingsElement stepSettings =
                this.Configuration.StepSettings != null ?
                this.Configuration.StepSettings[stepConfig] :
                null;

            // Take the step configuration
            ActiveServiceElement configuration = stepSettings != null ?
                                                 new ActiveServiceElement(stepSettings) :
                                                 new ActiveServiceElement(stepConfig);

            // Add child-specific options
            if (options != null)
            {
                configuration.Options.Merge(options);
            }

            // Add parent options, without overriding child options with the same name
            foreach (var parentOption in this.Configuration.Options)
            {
                if (!configuration.Options.ContainsKey(parentOption.Key))
                {
                    configuration.Options.Add(parentOption.Key, parentOption.Value);
                }
            }

            // Add parent extensions, without overriding child options with the same name
            foreach (var parentExtension in this.Configuration.Extensions)
            {
                if (!configuration.Extensions.ContainsKey(parentExtension.Key))
                {
                    configuration.Extensions.Add(parentExtension.Key, parentExtension.Value);
                }
            }

            // Generate a child instance
            ServiceInstance child = Service.CreateInstance(configuration, this, this.AccountID);

            child.StateChanged     += _childStateHandler;
            child.OutcomeReported  += _childOutcomeHandler;
            child.ProgressReported += _childProgressHandler;
            _childServices.Add(child, stepNumber);

            if (ChildServiceRequested != null)
            {
                ChildServiceRequested(this, new ServiceRequestedEventArgs(child, attemptNumber));
            }
        }
        /// <summary>
        /// Initializing service from current configuration
        /// </summary>
        /// <param name="timePeriod">Service time period</param>
        /// <param name="serviceName">Service Name , See Const</param>
        /// <param name="channels">Channels List in string format seperated by comma</param>
        /// <param name="accounts">Accounts List in string format seperated by comma</param>
        internal void InitServices(DateTimeRange timePeriod, string serviceName, string channels, string accounts, Dictionary <string, Object> eventsHandlers)
        {
            try
            {
                ActiveServiceElement serviceElements = new ActiveServiceElement(EdgeServicesConfiguration.Current.Accounts.GetAccount(-1).Services[serviceName]);



                //Removing overide options
                serviceElements.Options.Remove("fromDate");
                serviceElements.Options.Remove("toDate");
                serviceElements.Options.Remove("ChannelList");
                serviceElements.Options.Remove("AccountsList");

                // TimePeriod
                serviceElements.Options.Add("fromDate", timePeriod.Start.ToDateTime().ToString());
                serviceElements.Options.Add("toDate", timePeriod.End.ToDateTime().ToString());

                serviceElements.Options.Add("ChannelList", channels);
                serviceElements.Options.Add("AccountsList", accounts);
                serviceElements.Options.Add("PmsServiceName", serviceName);


                //Update WorkFlow
                foreach (WorkflowStepElement step in serviceElements.Workflow)
                {
                    //CHECK IF CHILD SERVICE OPTION IS -> PMS = ENABLED
                    if (step.Options.ContainsKey("PMS") && !step.Options["PMS"].ToString().ToUpper().Equals("ENABLED"))
                    {
                        step.IsEnabled = false;
                    }
                    else
                    {
                        step.IsEnabled = true;
                    }
                }

                ServiceInstance = Edge.Core.Services.Service.CreateInstance(serviceElements);

                ServiceInstance.OutcomeReported       += (EventHandler)eventsHandlers[Const.EventsTypes.ParentOutcomeReportedEvent];
                ServiceInstance.StateChanged          += (EventHandler <ServiceStateChangedEventArgs>)eventsHandlers[Const.EventsTypes.ParentStateChangedEvent];
                ServiceInstance.ChildServiceRequested += (EventHandler <ServiceRequestedEventArgs>)eventsHandlers[Const.EventsTypes.ChildServiceRequested];

                //instance.ProgressReported += new EventHandler(instance_ProgressReported);
                ServiceInstance.Initialize();
            }
            catch (Exception ex)
            {
                throw new Exception("Could not init validation service, Check configuration", ex);
            }
        }
        //=================
        #endregion

        #region Static
        //=================

        internal static ServiceInstance FromService(Service serviceEngine)
        {
            ServiceInstance instance = new ServiceInstance()
            {
                InstanceID     = serviceEngine.InstanceID,
                ParentInstance = serviceEngine.ParentInstance,
                Environment    = serviceEngine.Environment,
                StateInfo      = serviceEngine.StateInfo,
                SchedulingInfo = serviceEngine.SchedulingInfo,
                Configuration  = serviceEngine.Configuration
            };

            return(instance);
        }
示例#10
0
        /*=========================*/
        #endregion

        #region Constructor
        /*=========================*/

        /// <summary>
        ///
        /// </summary>
        internal ServiceInstance(ActiveServiceElement activeConfiguration, ServiceInstance parentInstance, int accountID)
        {
            this.Guid = Guid.NewGuid();
            ActiveConfigurationProperty.SetValue(this, activeConfiguration);
            ParentInstanceProperty.SetValue(this, parentInstance);
            _logSource = activeConfiguration.Name;

            if (accountID > -1)
            {
                AccountIDProperty.SetValue(this, accountID);
            }

            _childStateHandler    = new EventHandler <ServiceStateChangedEventArgs>(ChildStateChanged);
            _childOutcomeHandler  = new EventHandler(ChildOutcomeReported);
            _childProgressHandler = new EventHandler(ChildProgressReported);
        }
示例#11
0
        void LegacyInstance_ChildServiceRequested(object sender, Edge.Core.Services.ServiceRequestedEventArgs e)
        {
            legacy.ServiceInstance instance = (legacy.ServiceInstance)sender;

            e.RequestedService.ChildServiceRequested += new EventHandler <legacy.ServiceRequestedEventArgs>(LegacyInstance_ChildServiceRequested);
            e.RequestedService.StateChanged          += new EventHandler <legacy.ServiceStateChangedEventArgs>(LegacyInstance_StateChanged);
            e.RequestedService.OutcomeReported       += new EventHandler(LegacyInstance_OutcomeReported);

            try { e.RequestedService.Initialize(); }
            catch (Exception ex)
            {
                string msg = String.Format("{1}: Failed to initialize child service {0}", instance.Configuration.Name, instance.AccountID);
                LogText(msg);
                Log.Write(Program.LS, msg, ex);
            }
        }
示例#12
0
        void ChildOutcomeReported(object sender, EventArgs e)
        {
            ServiceInstance child = (ServiceInstance)sender;

            child.StateChanged     -= _childStateHandler;
            child.OutcomeReported  -= _childOutcomeHandler;
            child.ProgressReported -= _childProgressHandler;

            int stepNumer = _childServices[child];

            _childServices.Remove(child);

            if (_commChannel != null && _commChannel.State == CommunicationState.Opened)
            {
                _commChannel.Engine.ChildServiceOutcomeReported(stepNumer, child.Outcome);
            }
        }
示例#13
0
        void LegacyInstance_StateChanged(object sender, Edge.Core.Services.ServiceStateChangedEventArgs e)
        {
            legacy.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;
            GridUpdateInstance(instance);
            LogText(string.Format("{0}: {1} is {2}", instance.AccountID, instance.Configuration.Name, e.StateAfter));

            if (e.StateAfter == legacy.ServiceState.Ready)
            {
                try { instance.Start(); }
                catch (Exception ex)
                {
                    string msg = String.Format("{1}: Failed to start service {0}", instance.Configuration.Name, instance.AccountID);
                    LogText(msg);
                    Log.Write(Program.LS, msg, ex);
                }
            }
        }
示例#14
0
        void LegacyInstance_ChildServiceRequested(object sender, Edge.Core.Services.ServiceRequestedEventArgs e)
        {
            try
            {
                legacy.ServiceInstance instance = (legacy.ServiceInstance)sender;

                this.Invoke(setLogMethod, new Object[] { string.Format("\nChild Service: {0} requestedd {1}\r\n", e.RequestedService.Configuration.Name, DateTime.Now.ToString("dd/MM/yy HH:mm")) });

                e.RequestedService.ChildServiceRequested += new EventHandler <legacy.ServiceRequestedEventArgs>(LegacyInstance_ChildServiceRequested);
                e.RequestedService.StateChanged          += new EventHandler <legacy.ServiceStateChangedEventArgs>(LegacyInstance_StateChanged);
                e.RequestedService.Initialize();
            }
            catch (Exception ex)
            {
                Edge.Core.Utilities.Log.Write("SchedulingControlForm", ex.Message, ex, Edge.Core.Utilities.LogMessageType.Error);
            }
        }
示例#15
0
        public ServiceInstanceInfo(ServiceInstance instance)
        {
            _guid           = instance.Guid;
            _accountID      = instance.AccountID;
            _instanceID     = instance.InstanceID;
            _priority       = instance.Priority;
            _config         = instance.Configuration;
            _configFileName = EdgeServicesConfiguration.CurrentFileName;
            _rule           = instance.ActiveSchedulingRule;
            _timeStarted    = instance.TimeStarted;
            _timeScheduled  = instance.TimeScheduled;
            _serviceUrl     = instance.ServiceUrl;

            if (instance.ParentInstance != null)
            {
                _parentInstanceData = new ServiceInstanceInfo(instance.ParentInstance);
            }
        }
        internal static ServiceInstance FromSqlData(IDataRecord record, ServiceEnvironment environment, ServiceInstance childInstance, bool stateInfoOnly)
        {
            ServiceInstance instance = new ServiceInstance()
            {
                InstanceID  = record.Convert <string, Guid>("InstanceID", raw => Guid.Parse(raw)),
                Environment = environment,
                StateInfo   = new ServiceStateInfo()
                {
                    Progress        = record.Get <double>("Progress"),
                    State           = record.Get <ServiceState>("State"),
                    Outcome         = record.Get <ServiceOutcome>("Outcome"),
                    TimeInitialized = record.Get <DateTime>("TimeInitialized"),
                    TimeStarted     = record.Get <DateTime>("TimeStarted"),
                    TimeEnded       = record.Get <DateTime>("TimeEnded"),
                    TimeLastPaused  = record.Get <DateTime>("TimeLastPaused"),
                    TimeLastResumed = record.Get <DateTime>("TimeLastResumed")
                }
            };

            if (!stateInfoOnly)
            {
                instance.SchedulingInfo = record.IsDBNull("Scheduling_Status", "Scheduling_Scope", "Scheduling_MaxDeviationBefore", "Scheduling_MaxDeviationAfter", "Scheduling_RequestedTime", "Scheduling_ExpectedStartTime", "Scheduling_ExpectedEndTime") ? null : new SchedulingInfo()
                {
                    SchedulingStatus   = record.Get <SchedulingStatus>("Scheduling_Status"),
                    SchedulingScope    = record.Get <SchedulingScope>("Scheduling_Scope"),
                    MaxDeviationBefore = new TimeSpan(0, 0, (int)record.Get <long>("Scheduling_MaxDeviationBefore")),
                    MaxDeviationAfter  = new TimeSpan(0, 0, (int)record.Get <long>("Scheduling_MaxDeviationAfter")),
                    RequestedTime      = record.Get <DateTime>("Scheduling_RequestedTime"),
                    ExpectedStartTime  = record.Get <DateTime>("Scheduling_ExpectedStartTime"),
                    ExpectedEndTime    = record.Get <DateTime>("Scheduling_ExpectedEndTime"),
                };

                var stringReader = new StringReader(record.Get <String>("Configuration"));
                using (var xmlReader = new XmlTextReader(stringReader))
                    instance.Configuration = (ServiceConfiguration) new NetDataContractSerializer().ReadObject(xmlReader);
            }

            if (childInstance != null)
            {
                childInstance.ParentInstance = instance;
            }

            return(instance);
        }
示例#17
0
        void child_instance_StateChanged(object sender, Edge.Core.Services.ServiceStateChangedEventArgs e)
        {
            Edge.Core.Services.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;

            Invoke(_updateProgressBar, new object[] { this.progressBar, 0, true });
            Invoke(_updateProgressBar, new object[] { this.progressBar, 60, true });
            //Invoke(_setLabelText, new object[] { ProgressBarTxt, string.Format("{0}-{1}", instance.Configuration.Name, e.StateAfter) });

            string log = string.Format("State Changed : {0} - Account ID: {2} - Service Channel ID: {1} ", e.StateAfter, instance.Configuration.GetOption("ChannelList", false), instance.Configuration.GetOption("AccountsList", false) == null ? instance.AccountID.ToString() : instance.Configuration.GetOption("AccountsList", false));

            Invoke(_updateLogBox, new object[] { log });

            if (e.StateAfter == ServiceState.Ready)
            {
                instance.Start();
            }

            if (e.StateAfter == ServiceState.Ended)
            {
                //Update current running services counter
                //Invoke(_incCounter, new object[] { this._runnigServices, -1 });


                if (instance.Configuration.Options.ContainsKey("OnEnd") && (instance.Configuration.Options["OnEnd"].ToString().Equals("GetValidationResults")))
                {
                    //Get Validations Results
                    List <ValidationResult> newResults = DataChecksModelView.GetValidationResultsByInstance(instance);

                    //TO DO : Add results to validation results view.
                    if (newResults.Capacity > 0)
                    {
                        Invoke(_updateResults, new object[] { newResults });

                        //Invoke(_setButton, new object[]  { this.report_btn, true, true });
                    }
                    else
                    {
                        //Writing To PMS validation  log
                        Invoke(_updateLogBox, new object[] { "Validation results werent found in DB !!" });
                    }
                }
            }
        }
示例#18
0
        void LegacyInstance_StateChanged(object sender, Edge.Core.Services.ServiceStateChangedEventArgs e)
        {
            try
            {
                legacy.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;
                instance.OutcomeReported += new EventHandler(instance_OutcomeReported);

                this.Invoke(updateGridMethod, new Object[] { instance });


                this.Invoke(setLogMethod, new Object[] { string.Format("\n{0}: {1} is {2} {3}\r\n", instance.AccountID, instance.Configuration.Name, e.StateAfter, DateTime.Now.ToString("dd/MM/yy HH:mm")) });
                if (e.StateAfter == legacy.ServiceState.Ready)
                {
                    instance.Start();
                }
            }
            catch (Exception ex)
            {
                Edge.Core.Utilities.Log.Write("SchedulingControlForm", ex.Message, ex, Edge.Core.Utilities.LogMessageType.Error);
            }
        }
示例#19
0
        private void UpdateGridData(legacy.ServiceInstance serviceInstance)
        {
            try
            {
                foreach (DataGridViewRow row in scheduleInfoGrid.Rows)
                {
                    if (Object.Equals(row.Tag, serviceInstance))
                    {
                        row.Cells["dynamicStaus"].Value  = serviceInstance.State;
                        row.Cells["outCome"].Value       = serviceInstance.Outcome;
                        row.Cells["actualEndTime"].Value = serviceInstance.TimeEnded.ToString("dd/MM/yyyy HH:mm:ss");
                        row.Cells["instanceID"].Value    = serviceInstance.InstanceID;

                        Color color = GetColorByState(serviceInstance.State, serviceInstance.Outcome);
                        row.DefaultCellStyle.BackColor = color;
                    }
                }
            }
            catch (Exception ex)
            {
                Edge.Core.Utilities.Log.Write("SchedulingControlForm", ex.Message, ex, Edge.Core.Utilities.LogMessageType.Error);
            }
        }
示例#20
0
        /// <summary>
        /// Get all service instances from the DB
        /// </summary>
        /// <returns></returns>
        public List <ServiceInstance> GetServiceInstanceActiveList()
        {
            var instanceList = new List <ServiceInstance>();

            using (var connection = new SqlConnection(EnvironmentConfiguration.ConnectionString))
            {
                var command = new SqlCommand(EnvironmentConfiguration.SP_InstanceActiveListGet, connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@timeframeStart", DateTime.Now);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var instance = ServiceInstance.FromSqlData(reader, this, null, false);
                        // all instances in DB are activated (scheduling status is not saved in DB)
                        instance.SchedulingInfo.SchedulingStatus = SchedulingStatus.Activated;
                        instanceList.Add(instance);
                    }
                }
            }
            return(instanceList);
        }
示例#21
0
        void instance_StateChanged(object sender, Edge.Core.Services.ServiceStateChangedEventArgs e)
        {
            Invoke(_updateProgressBar, new object[] { this.progressBar, 0, true });
            Invoke(_updateProgressBar, new object[] { this.progressBar, 60, true });

            Edge.Core.Services.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;

            string log = string.Format("State Changed : {0} - Account ID: {2} - Service Channel ID: {1} ", e.StateAfter, instance.Configuration.GetOption("ChannelList", false), instance.Configuration.GetOption("AccountsList", false) == null ? instance.AccountID.ToString() : instance.Configuration.GetOption("AccountsList", false));

            Invoke(_updateLogBox, new object[] { log });
            Invoke(_setLabelText, new object[] { ProgressBarTxt, string.Format("Account ID: {0}, Service Channel ID: {1}, State:{2}",
                                                                               instance.Configuration.GetOption("AccountsList", false) == null ? instance.AccountID.ToString() : instance.Configuration.GetOption("AccountsList", false),
                                                                               instance.Configuration.GetOption("ChannelList", false),
                                                                               e.StateAfter) });

            if (e.StateAfter == Edge.Core.Services.ServiceState.Ready)
            {
                instance.Start();
            }
            if (e.StateAfter == Edge.Core.Services.ServiceState.Ended)
            {
                Invoke(_updateProgressBar, new object[] { this.progressBar, 100, true });
            }
        }
示例#22
0
 /// <summary>
 ///
 /// </summary>
 public static ServiceInstance CreateInstance(EnabledConfigurationElement configuration, ServiceInstance parentInstance, int accountID)
 {
     return(ServiceInstance.Generate(configuration, parentInstance, accountID));
 }
示例#23
0
        /*=========================*/
        #endregion

        #region CreateInstance
        /*=========================*/

        /// <summary>
        ///
        /// </summary>
        public static ServiceInstance CreateInstance(EnabledConfigurationElement configuration)
        {
            return(ServiceInstance.Generate(configuration, null, -1));
        }
示例#24
0
        static void ActiveRuleProperty_Getting(object sender, ValueTranslationEventArgs e)
        {
            ServiceInstance current = (ServiceInstance)e.Entity;

            e.Output = current._activeRule;
        }
示例#25
0
 void instance_OutcomeReported(object sender, EventArgs e)
 {
     legacy.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;
     this.Invoke(updateGridMethod, new Object[] { instance });
 }
示例#26
0
 void LegacyInstance_OutcomeReported(object sender, EventArgs e)
 {
     legacy.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;
     GridUpdateInstance(instance);
     LogText(string.Format("{0}: {1} reported {2}", instance.AccountID, instance.Configuration.Name, instance.Outcome));
 }
        internal ServiceInstance(ServiceConfiguration configuration, ServiceEnvironment environment, ServiceInstance parentInstance)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (configuration.ConfigurationLevel == ServiceConfigurationLevel.Instance)
            {
                throw new ArgumentException("Cannot use an existing instance-level configuration to create a new instance. Use instance.Configuration.GetBaseConfiguration(..) instead.", "configuration");
            }

            ThrowExceptionOnError = false;

            this.Environment = environment;
            this.InstanceID  = Guid.NewGuid();
            if (parentInstance != null)
            {
                this.Configuration  = configuration.Derive(ServiceConfigurationLevel.Instance, parentInstance.Configuration);
                this.ParentInstance = parentInstance;
            }
            else
            {
                this.Configuration = configuration.Derive(ServiceConfigurationLevel.Instance, null);
            }

            if (String.IsNullOrEmpty(this.Configuration.HostName))
            {
                this.Configuration.HostName = Environment.EnvironmentConfiguration.DefaultHostName;
            }

            //((ILockable)this.Configuration).Lock();
        }
示例#28
0
 void GridUpdateInstance(legacy.ServiceInstance instance)
 {
     try { Invoke(_delegateGridUpdate, instance); }
     catch { }
 }
 internal ServiceInstance NewServiceInstance(ServiceConfiguration configuration, ServiceInstance parent)
 {
     return(new ServiceInstance(configuration, this, parent));
 }
示例#30
0
        /*================================================================================*/
        #endregion

        #region Services Events Handler Section
        /*=========================================================================*/
        void instance_OutcomeReported(object sender, EventArgs e)
        {
            Edge.Core.Services.ServiceInstance instance = (Edge.Core.Services.ServiceInstance)sender;
        }