Beispiel #1
0
        /// <summary>
        /// Stops the named virtual machine.
        /// </summary>
        /// <param name="machineName">The machine name.</param>
        /// <param name="turnOff">
        /// <para>
        /// Optionally just turns the VM off without performing a graceful shutdown first.
        /// </para>
        /// <note>
        /// <b>WARNING!</b> This could result in corruption or the the loss of unsaved data.
        /// </note>
        /// </param>
        public void StopVm(string machineName, bool turnOff = false)
        {
            if (isAdmin)
            {
                hypervClient.StopVm(machineName: machineName, turnOff: turnOff);
            }
            else
            {
                var request = new GrpcStopVmRequest(machineName: machineName, turnOff: turnOff);
                var reply   = desktopService.StopVmAsync(request).Result;

                reply.Error.EnsureSuccess();
            }
        }
Beispiel #2
0
        /// <inheritdoc/>
        public async Task <GrpcBaseReply> StopVmAsync(GrpcStopVmRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                hyperv.StopVm(machineName: request.MachineName, turnOff: request.TurnOff);

                return(new GrpcBaseReply());
            }
            catch (Exception e)
            {
                return(new GrpcBaseReply(e));
            }
        }