Ejemplo n.º 1
0
        /// <summary>
        /// Adds a virtual Hyper-V switch that has external connectivity.
        /// </summary>
        /// <param name="switchName">The new switch name.</param>
        /// <param name="gateway">Address of the LAN gateway, used to identify the connected network interface.</param>
        public void NewExternalSwitch(string switchName, IPAddress gateway)
        {
            if (isAdmin)
            {
                hypervClient.NewExternalSwitch(switchName: switchName, gateway: gateway);
            }
            else
            {
                var request = new GrpcNewExternalSwitchRequest(switchName: switchName, gateway: gateway);
                var reply   = desktopService.NewExternalSwitchAsync(request).Result;

                reply.Error.EnsureSuccess();
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task <GrpcBaseReply> NewExternalSwitchAsync(GrpcNewExternalSwitchRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                hyperv.NewExternalSwitch(switchName: request.SwitchName, IPAddress.Parse(request.Gateway));

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