コード例 #1
0
 /// <summary>
 /// Object constructor.
 /// </summary>
 public ServiceState(IErrorHandler errorHandler, ILogger logger, ServiceStateType initialState = ServiceStateType.Down)
 {
     _errorHandler = errorHandler;
     _logger       = logger;
     _state        = initialState;
     _timer        = new Timer(Timer_Callback, null, TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(60));
 }
コード例 #2
0
ファイル: LxnaService.cs プロジェクト: lulzzz/lxna
        internal void InternalStart()
        {
            if (this.StateType != ServiceStateType.Stopped)
            {
                return;
            }
            _state = ServiceStateType.Starting;

            _state = ServiceStateType.Running;
        }
コード例 #3
0
 /// <summary>
 /// Sets the state of the service.
 /// </summary>
 public void SetState(ServiceStateType state)
 {
     try
     {
         _logger?.WriteMessage("ServiceState", $"Setting state: {state}");
         lock (_lock)
         {
             _state = state;
         }
     }
     catch (Exception ex)
     {
         _errorHandler?.LogError(ex);
     }
 }
コード例 #4
0
ファイル: DownloadManager.cs プロジェクト: abd0ahmed/xeus
        public override void Stop()
        {
            lock (_stateLockObject)
            {
                lock (_lockObject)
                {
                    if (this.StateType == ManagerState.Stop)
                    {
                        return;
                    }
                    _state = ManagerState.Stop;
                }

                _downloadTaskManager.Stop();

                foreach (var taskManager in _decodeTaskManagers)
                {
                    taskManager.Stop();
                }
            }
        }
コード例 #5
0
        private void ControlHostInstances(string query)
        {
            //Create EnumerationOptions and run wql query
            EnumerationOptions enumOptions = new EnumerationOptions();

            enumOptions.ReturnImmediately = false;
            enumOptions.Rewindable        = false;

            //Search for all HostInstances of 'InProcess' type in the Biztalk namespace scope
            using (ManagementObjectSearcher searchObject =
                       new ManagementObjectSearcher("root\\MicrosoftBizTalkServer", query, enumOptions))
            {
                string activeNodeName = null;

                //Enumerate through the result set and start each HostInstance if it is already stopped
                foreach (ManagementObject inst in searchObject.Get())
                {
                    string runningServer = (string)inst["RunningServer"];
                    string hostName      = (string)inst["HostName"];

                    if ((bool)inst["IsDisabled"])
                    {
                        this.Log.LogMessage("Skipping disabled host instance: " + hostName + " on " + runningServer);
                        continue;
                    }

                    ServiceStateType    currentServiceState = (ServiceStateType)(uint)inst["ServiceState"];
                    ClusterInstanceType clusterInstanceType = (ClusterInstanceType)(uint)inst["ClusterInstanceType"];

                    // Handle clustered host instances
                    if (clusterInstanceType == ClusterInstanceType.Clustered || clusterInstanceType == ClusterInstanceType.ClusteredVirtual)
                    {
                        this.Log.LogMessage("Host instance " + hostName + " has cluster type " + clusterInstanceType.ToString() + ".");

                        if (string.IsNullOrEmpty(activeNodeName))
                        {
                            activeNodeName = GetActiveClusterNodeName();
                        }

                        if (string.Compare(activeNodeName, runningServer, true) != 0)
                        {
                            this.Log.LogMessage("Skipping passive clustered host instance: " + hostName + " on " + runningServer);
                            continue;
                        }
                    }

                    //Check if ServiceState is not 'Stop Pending' and 'Stopped'
                    if ((_mode == ModeType.Restart || _mode == ModeType.Stop) &&
                        (currentServiceState != ServiceStateType.Stopped && currentServiceState != ServiceStateType.StopPending))
                    {
                        if (_mode == ModeType.Stop)
                        {
                            this.Log.LogMessage("Stopping host instance: " + hostName + " on " + runningServer);
                        }
                        else if (_mode == ModeType.Restart)
                        {
                            this.Log.LogMessage("Restarting host instance: " + hostName + " on " + runningServer);
                        }

                        try
                        {
                            inst.InvokeMethod("Stop", null);
                        }
                        catch (Exception ex)
                        {
                            if (!ex.Message.ToLowerInvariant().Contains("overlapped i/o operation is in progress".ToLowerInvariant()))
                            {
                                throw;
                            }
                        }

                        if (_mode == ModeType.Stop)
                        {
                            this.Log.LogMessage("Stopped host instance : " + hostName + " on " + runningServer);
                        }

                        inst.Get();
                        currentServiceState = (ServiceStateType)(uint)inst["ServiceState"];
                        runningServer       = (string)inst["RunningServer"];
                    }

                    //Check if ServiceState is not 'Start Pending' and 'Running'
                    if ((_mode == ModeType.Restart || _mode == ModeType.Start) &&
                        (currentServiceState != ServiceStateType.Running &&
                         currentServiceState != ServiceStateType.StartPending &&
                         currentServiceState != ServiceStateType.ContinuePending))
                    {
                        if (_mode == ModeType.Start)
                        {
                            this.Log.LogMessage("Starting host instance: " + hostName + " on " + runningServer);
                        }

                        try
                        {
                            inst.InvokeMethod("Start", null);
                        }
                        catch (Exception ex)
                        {
                            if (!ex.Message.ToLowerInvariant().Contains("the cluster which this is part of was brought online".ToLowerInvariant()))
                            {
                                throw;
                            }
                            else
                            {
                                this.Log.LogMessage(ex.Message);
                            }
                        }

                        if (_mode == ModeType.Start)
                        {
                            this.Log.LogMessage("Started host instance : " + hostName + " on " + runningServer);
                        }
                        else if (_mode == ModeType.Restart)
                        {
                            this.Log.LogMessage("Restarted host instance : " + hostName + " on " + runningServer);
                        }
                    }
                }
            }
        }