예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task OpenInputChannelAsync(uint desktopWidth, uint desktopHeight)
        {
            if (!ProtocolInitialized)
            {
                throw new NanoException("Protocol is not initialized");
            }

            // We have to generate ChannelOpenData to send to the console
            var inputChannelOpenData = new ChannelOpen(new byte[0]);

            Input         = new InputChannel(_transport, inputChannelOpenData);
            InputFeedback = new InputFeedbackChannel(_transport, inputChannelOpenData,
                                                     FireInputFeedbackFrameAvailable);

            // Send ControllerEvent.Added
            await _transport.WaitForMessageAsync <ChannelCreate>(
                TimeSpan.FromSeconds(3),
                async() => await Control.SendControllerEventAsync(
                    ControllerEventType.Added, 0),
                p => p.Channel == NanoChannel.Input);

            await Task.WhenAll(
                Input.OpenAsync(),
                InputFeedback.OpenAsync(desktopWidth, desktopHeight)
                );
        }
        public async Task OnConnectedAsync(FramingConnection connection)
        {
            var be  = connection.ServiceDispatcher.Binding.CreateBindingElements();
            var tbe = be.Find <TransportBindingElement>();
            ITransportFactorySettings settings = new NetFramingTransportSettings
            {
                CloseTimeout           = connection.ServiceDispatcher.Binding.CloseTimeout,
                OpenTimeout            = connection.ServiceDispatcher.Binding.OpenTimeout,
                ReceiveTimeout         = connection.ServiceDispatcher.Binding.ReceiveTimeout,
                SendTimeout            = connection.ServiceDispatcher.Binding.SendTimeout,
                ManualAddressing       = tbe.ManualAddressing,
                BufferManager          = connection.BufferManager,
                MaxReceivedMessageSize = tbe.MaxReceivedMessageSize,
                MessageEncoderFactory  = connection.MessageEncoderFactory
            };
            var timeoutHelper = new TimeoutHelper(settings.ReceiveTimeout);
            var channel       = new InputChannel(settings, null, _servicesScopeFactory.CreateScope().ServiceProvider);
            await channel.OpenAsync();

            var channelDispatcher = connection.ServiceDispatcher.CreateServiceChannelDispatcher(channel);

            // TODO: I think that the receive timeout starts counting at the start of the preamble on .NET Framework. This implementation basically resets the timer
            // after the preamble has completed. This probably needs to be addressed otherwise worse case you could end up taking 2X as long to timeout.
            // I believe the preamble should really use the OpenTimeout but that's not how this is implemented on .NET Framework.

            var requestContext = (StreamedFramingRequestContext) await ReceiveRequestAsync(connection, timeoutHelper.RemainingTime());

            _ = channelDispatcher.DispatchAsync(requestContext, CancellationToken.None);
            await requestContext.ReplySent;
            await Task.Delay(5);
        }
예제 #3
0
 private void Input_OnClose(object sender, ChannelCloseEventArgs e)
 {
     try
     {
         logger?.LogWarning("Input channel closed.");
         logger?.LogInformation("Restarting input channel.");
         ExecuteInputRetryPolicy();
         InputChannel.OpenAsync().GetAwaiter();
     }
     catch (Exception ex)
     {
         logger?.LogError(ex, "Fault restarting module input channel.");
         throw ex;
     }
 }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task OpenInputChannelAsync(uint desktopWidth, uint desktopHeight)
        {
            if (!ProtocolInitialized)
            {
                throw new NanoException("Protocol is not initialized");
            }

            Input         = new InputChannel(_transport, new byte[] { });
            InputFeedback = new InputFeedbackChannel(_transport, new byte[] { });

            // Send ControllerEvent.Added
            await _transport.WaitForMessageAsync <ChannelCreate>(
                TimeSpan.FromSeconds(3),
                async() => await Control.SendControllerEventAsync(
                    ControllerEventType.Added, 0),
                p => p.Channel == NanoChannel.Input);

            await Task.WhenAll(
                Input.OpenAsync(),
                InputFeedback.OpenAsync(desktopWidth, desktopHeight)
                );
        }
예제 #5
0
        public override void Execute()
        {
            //wire up events
            InputChannel.OnOpen    += Input_OnOpen;
            InputChannel.OnReceive += Input_OnReceive;
            InputChannel.OnError   += Input_OnError;
            InputChannel.OnClose   += Input_OnClose;

            OutputChannel.OnClose   += Output_OnClose;
            OutputChannel.OnError   += Output_OnError;
            OutputChannel.OnReceive += Output_OnReceive;
            OutputChannel.OnOpen    += Output_OnOpen;

            try
            {
                InputChannel.OpenAsync().GetAwaiter();
                OutputChannel.OpenAsync().GetAwaiter();
            }
            catch (Exception ex)
            {
                OnPipelineError?.Invoke(this, new PipelineErrorEventArgs(Id, ex));
            }
        }
예제 #6
0
        public override void Execute()
        {
            InputChannel.OnOpen    += Input_OnOpen;
            InputChannel.OnReceive += Input_OnReceive;
            InputChannel.OnError   += Input_OnError;
            InputChannel.OnClose   += Input_OnClose;

            OutputChannel.OnClose   += Output_OnClose;
            OutputChannel.OnError   += Output_OnError;
            OutputChannel.OnReceive += Output_OnReceive;
            OutputChannel.OnOpen    += Output_OnOpen;

            if (!InputChannel.IsConnected)
            {
                InputChannel.OpenAsync().GetAwaiter();
            }

            if (!OutputChannel.IsConnected)
            {
                OutputChannel.OpenAsync().GetAwaiter();
                //OutputChannel.ReceiveAsync().GetAwaiter();
            }
        }