コード例 #1
0
        /// <summary>
        /// Mocks <see cref="IRestartManagerService.ShutdownProcesses(int, RM_SHUTDOWN_TYPE, RM_WRITE_STATUS_CALLBACK)"/>.
        /// </summary>
        /// <param name="sessionId">Optional session ID to end. The default is 0.</param>
        /// <param name="force">Whether to force applications to shutdown if no response. The default is false.</param>
        /// <param name="onlyRegistered">Whether to only shut down applications if registered with Restart Manager. The default is false.</param>
        /// <param name="error">Optional error to return. The default is 0 (no error).</param>
        /// <returns>The current instance for fluent calls.</returns>
        public MockRestartManagerService ShutdownProcesses(int sessionId = DefaultSessionId, bool force = false, bool onlyRegistered = false, int error = NativeMethods.ERROR_SUCCESS)
        {
            RM_SHUTDOWN_TYPE shutdownType = 0;

            if (force)
            {
                shutdownType |= RM_SHUTDOWN_TYPE.RmForceShutdown;
            }

            if (onlyRegistered)
            {
                shutdownType |= RM_SHUTDOWN_TYPE.RmShutdownOnlyRegistered;
            }

            Mock.Setup(x => x.ShutdownProcesses(sessionId, shutdownType, It.IsAny <RM_WRITE_STATUS_CALLBACK>()))
            .Callback <int, RM_SHUTDOWN_TYPE, RM_WRITE_STATUS_CALLBACK>((sessionId_, shutdownType_, progress_) =>
            {
                // TODO: Consider uses whatever was actually registered above, default or otherwise.
                for (int i = 0, length = DefaultProcesses.Length; i < length; ++i)
                {
                    progress_?.Invoke(100 * i / length);
                }
            })
            .Returns(error)
            .Verifiable();

            return(this);
        }
コード例 #2
0
        /// <summary>
        /// Shuts down applications and services identity by the Restart Manager for registered resources.
        /// </summary>
        /// <param name="force">Whether to force applications to shutdown if no response. The default is false.</param>
        /// <param name="onlyRegistered">Whether to only shut down applications if registered with Restart Manager. The default is false.</param>
        /// <exception cref="ObjectDisposedException">This object has already been disposed.</exception>
        /// <exception cref="Win32Exception">An error occurred.</exception>
        /// <seealso cref="ShutdownProgress"/>
        internal void ShutdownProcesses(bool force = false, bool onlyRegistered = false)
        {
            ThrowIfDisposed();

            RM_SHUTDOWN_TYPE shutdownType = 0;

            if (force)
            {
                shutdownType |= RM_SHUTDOWN_TYPE.RmForceShutdown;
            }

            if (onlyRegistered)
            {
                shutdownType |= RM_SHUTDOWN_TYPE.RmShutdownOnlyRegistered;
            }

            var error = RestartManagerService.ShutdownProcesses(SessionId, shutdownType, OnShutdownProgress);

            ThrowOnError(error);
        }
コード例 #3
0
 /// <inheritdoc/>
 public int ShutdownProcesses(int sessionId, RM_SHUTDOWN_TYPE shutdownType, RM_WRITE_STATUS_CALLBACK progress) =>
 NativeMethods.RmShutdown(sessionId, shutdownType, progress);
コード例 #4
0
 protected static extern int RmShutdown(IntPtr pSessionHandle, RM_SHUTDOWN_TYPE lActionFlags, RM_WRITE_STATUS_CALLBACK fnStatus);
コード例 #5
0
 int IRestartManagerService.ShutdownProcesses(int sessionId, RM_SHUTDOWN_TYPE shutdownType, RM_WRITE_STATUS_CALLBACK progress)
 {
     return(Object.ShutdownProcesses(sessionId, shutdownType, progress));
 }
コード例 #6
0
 internal static extern int RmShutdown(
     [MarshalAs(UnmanagedType.U4)] int dwSessionHandle,
     [MarshalAs(UnmanagedType.U4)] RM_SHUTDOWN_TYPE lActionFlags,
     [MarshalAs(UnmanagedType.FunctionPtr)] RM_WRITE_STATUS_CALLBACK fnStatus);
コード例 #7
0
 public static extern int RmShutdown(IntPtr pSessionHandle, RM_SHUTDOWN_TYPE lActionFlags, PercentProgressCallback fnStatus);
コード例 #8
0
 public static extern int RmShutdown(IntPtr pSessionHandle, RM_SHUTDOWN_TYPE lActionFlags, PercentProgressCallback fnStatus);