Beispiel #1
0
        /// <summary>
        /// <para>
        /// Compacts a dynamic VHD or VHDX virtual disk file.
        /// </para>
        /// <note>
        /// The disk may be mounted to a VM but the VM cannot be running.
        /// </note>
        /// </summary>
        /// <param name="drivePath">Path to the virtual drive file.</param>
        public void CompactDrive(string drivePath)
        {
            if (isAdmin)
            {
                hypervClient.CompactDrive(drivePath: drivePath);
            }
            else
            {
                var request = new GrpcCompactDriveRequest(drivePath: drivePath);
                var reply   = desktopService.CompactDriveRequestAsync(request).Result;

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

            try
            {
                hyperv.CompactDrive(drivePath: request.DrivePath);

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