Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <GrpcGetSwitchReply> GetSwitchAsync(GrpcGetSwitchRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                return(new GrpcGetSwitchReply(@switch: hyperv.GetSwitch(request.SwitchName).ToProto()));
            }
            catch (Exception e)
            {
                return(new GrpcGetSwitchReply(e));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns information for a Hyper-V switch by name.
        /// </summary>
        /// <param name="switchName">The switch name.</param>
        /// <returns>The <see cref="VirtualSwitch"/> when present or <c>null</c>.</returns>
        public VirtualSwitch GetSwitch(string switchName)
        {
            if (isAdmin)
            {
                return(hypervClient.GetSwitch(switchName: switchName));
            }
            else
            {
                var request = new GrpcGetSwitchRequest(switchName: switchName);
                var reply   = desktopService.GetSwitchAsync(request).Result;

                reply.Error.EnsureSuccess();

                return(reply.Switch.ToLocal());
            }
        }