コード例 #1
0
        /// <summary>
        ///     Changes the <see cref="State"/> of the Manager to the specified <see cref="State"/> and fires the StateChanged event.
        /// </summary>
        /// <param name="state">The State to which the <see cref="State"/> property is to be changed.</param>
        /// <param name="message">The optional message describing the nature or reason for the change.</param>
        /// <param name="stopType">The <see cref="StopType"/> enumeration corresponding to the nature of the stoppage.</param>
        protected void ChangeState(State state, string message = "", StopType stopType = StopType.Stop)
        {
            logger.EnterMethod(xLogger.Params(state, message, stopType));

            State previousState = State;

            State = state;

            // if the new State is State.Faulted, ensure StopType is Abnormal
            if (State == State.Faulted && !stopType.HasFlag(StopType.Exception))
            {
                // if the Restart flag was passed in, ensure it remains
                if (stopType.HasFlag(StopType.Restart))
                {
                    stopType = StopType.Exception | StopType.Restart;
                }
                else
                {
                    stopType = StopType.Exception;
                }
            }

            StateChanged?.Invoke(this, new StateChangedEventArgs(State, previousState, message, stopType));

            logger.ExitMethod();
        }
コード例 #2
0
        /// <summary>
        ///     <para>Executed upon shutdown of the Manager.</para>
        ///     <para>
        ///         If the specified <see cref="StopType"/> is not <see cref="StopType.Exception"/>, saves the configuration to disk.
        ///     </para>
        /// </summary>
        /// <param name="stopType">The nature of the stoppage.</param>
        /// <returns>A Result containing the result of the operation.</returns>
        protected override IResult Shutdown(StopType stopType = StopType.Stop)
        {
            Guid guid = logger.EnterMethod(true);

            logger.Debug("Performing Shutdown for '" + GetType().Name + "'...");
            Result retVal = new Result();

            if (!stopType.HasFlag(StopType.Exception))
            {
                SaveConfiguration();
            }

            retVal.LogResult(logger.Debug);
            logger.ExitMethod(retVal, guid);
            return(retVal);
        }
コード例 #3
0
        /// <summary>
        ///     Stops the Manager.
        /// </summary>
        /// <param name="stopType">The nature of the stoppage.</param>
        /// <returns>A Result containing the result of the operation.</returns>
        /// <exception cref="ManagerStopException">
        ///     Thrown when an exception is encountered during the Stop or Shutdown routines.
        /// </exception>
        public IResult Stop(StopType stopType = StopType.Stop)
        {
            Guid guid = logger.EnterMethod(xLogger.Params(stopType), true);

            logger.Info("Stopping the " + ManagerName + "...");
            IResult retVal = new Result();

            if (!IsInState(State.Running, State.Faulted))
            {
                return(retVal.AddError("The Manager can not be stopped when it is in the " + State + " state."));
            }

            ChangeState(State.Stopping, stopType);

            // invoke the manager-specific shutdown routine
            try
            {
                retVal.Incorporate(Shutdown(stopType));
            }
            catch (Exception ex)
            {
                throw new ManagerStopException("Exception encountered while stopping Manager '" + GetType().Name + "'.  See inner exception for details.", ex);
            }

            // if the restartPending flag is set, start the restart timer this timer will continuously attempt to restart the
            // Manager until all dependencies are satisfied, after which point it will start.
            if (stopType.HasFlag(StopType.Restart))
            {
                logger.Info("The " + ManagerName + " will continue to attempt to restart.");
                restartTimer.Elapsed += RestartTimerElapsed;
                restartTimer.Start();
            }

            if (retVal.ResultCode != ResultCode.Failure)
            {
                ChangeState(State.Stopped, stopType);
            }
            else
            {
                ChangeState(State.Faulted, "Error stopping Manager: " + retVal.GetLastError(), StopType.Exception);
            }

            retVal.LogResult(logger);
            logger.ExitMethod(retVal, guid);
            return(retVal);
        }
コード例 #4
0
        /// <summary>
        ///     Stops the Connector.
        /// </summary>
        /// <remarks>
        ///     The State property should be set to <see cref="State.Stopping"/> at the beginning of the method, and should either
        ///     be set to <see cref="State.Stopped"/> or <see cref="State.Faulted"/> pending the outcome of the operation.
        /// </remarks>
        /// <remarks>
        ///     The Plugin configuration should be saved within this method, but only if the supplied <see cref="StopType"/>
        ///     parameter is <see cref="StopType.Normal"/>.
        /// </remarks>
        /// <remarks>Any changes to the State property should fire the <see cref="StateChanged"/> event.</remarks>
        /// <returns>A Result containing the result of the operation.</returns>
        public Result Stop(StopType stopType = StopType.Stop)
        {
            Guid guid = logger.EnterMethod(true);

            // instantiate a new Result and set the State to State.Stopping
            Result retVal = new Result();

            ChangeState(State.Stopping);

            // place the shutdown code in a try/catch to be sure we won't have issues
            try
            {
                timer.Stop();

                if (!stopType.HasFlag(StopType.Exception))
                {
                    SaveConfiguration();
                }
            }
            catch (Exception ex)
            {
                retVal.AddError("Failed to stop the Plugin: " + ex.Message);
            }

            // examine the Result to make sure we didn't encounter any issues. warnings are ok here, we'll send the messages back
            // to the caller in the Result.
            if (retVal.ResultCode != ResultCode.Failure)
            {
                ChangeState(State.Stopped);
            }
            else
            {
                ChangeState(State.Faulted);
            }

            retVal.LogResult(logger);
            logger.ExitMethod(retVal, guid);
            return(retVal);
        }