Ejemplo n.º 1
0
        public void WriteAndReadPersonObject()
        {
            var person = new Person()
            {
                Id        = 1,
                FirstName = "John",
                LastName  = "Smith"
            };

            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));

            output.Write(person);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            var result = channel.Read();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Person));

            var newperson = (Person)result;

            Assert.AreEqual(person.Id, newperson.Id);
            Assert.AreEqual(person.FirstName, newperson.FirstName);
            Assert.AreEqual(person.LastName, newperson.LastName);
        }
Ejemplo n.º 2
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)
                );
        }
Ejemplo n.º 3
0
        public void LoadInput(int channel)
        {
            // Remove previous triggers
            Brain.KB.Sources.DetachAllEvents(this.Trigger);

            if (channel >= Brain.KB.ChannelCount)
                return;

            SelectedIndex = channel;
            ui.TabControlWaves.SelectedIndex = channel;

            if (channel < 0)
                return;

            CurrentChannel = (InputChannel)Brain.KB.Sources.InputChannels[channel];

            ui.propertyGrid1.SelectedObject = CurrentChannel.Config;
            ui.velocityMapControl1.Map = ((InputChannelConfig)CurrentChannel.Config).Velocity;
            ui.textBoxHits.Text = "0";
            ui.textBoxVelocity.Text = "";

            // Subscribe to the trigger event
            var triggerEvent = CurrentChannel.Events.First(x => x.Name == InputChannel.TRIGGER_EVENT);
            triggerEvent.Add(this.Trigger, null);

            ui.velocityMapControl1.Invalidate();
        }
Ejemplo n.º 4
0
        public void SerializeDeserializeType()
        {
            var serializer = new TypeSerializer(typeof(Person));

            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));

            output.Write(serializer);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            var result = channel.Read(true);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(TypeSerializer));

            var newserializer = (TypeSerializer)result;
            var props         = newserializer.Properties;

            Assert.IsNotNull(props);
            Assert.AreEqual(3, props.Count);

            Assert.AreEqual("Id", props[0].Name);
            Assert.AreEqual(Types.Integer, props[0].Type);
            Assert.IsNull(props[0].TypeName);

            Assert.AreEqual("FirstName", props[1].Name);
            Assert.AreEqual(Types.String, props[1].Type);
            Assert.IsNull(props[1].TypeName);

            Assert.AreEqual("LastName", props[2].Name);
            Assert.AreEqual(Types.String, props[2].Type);
            Assert.IsNull(props[2].TypeName);
        }
        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);
        }
Ejemplo n.º 6
0
        public void RaisingChannelValueUpdatedEventForGraphedChannelAddsPoint()
        {
            var eventAggregator = A.Fake <IEventAggregator>();

            var evt = new AddToGraphEvent();

            A.CallTo(() => eventAggregator.GetEvent <AddToGraphEvent>()).Returns(evt);
            A.CallTo(() => eventAggregator.GetEvent <GraphCreatedEvent>()).Returns(new GraphCreatedEvent());

            var dataAquisition = A.Fake <IDataAquisition>();

            var channel = new InputChannel();

            var viewModel = new GraphsViewModel(eventAggregator, dataAquisition);

            evt.Publish((channel, 0));

            var time = DateTime.Now;

            dataAquisition.ChannelValueUpdated += Raise.With(new ChannelValueUpdatedEventArgs(channel, 3.0, time));

            Assert.IsType <LineSeries>(viewModel.Graphs[0].Series[0]);
            var lineSeries = (LineSeries)viewModel.Graphs[0].Series[0];
            var point      = lineSeries.Points[0];

            Assert.Equal(DateTimeAxis.ToDouble(time), point.X);
            Assert.Equal(3.0, point.Y);
        }
Ejemplo n.º 7
0
        private void Input_OnReceive(object sender, ChannelReceivedEventArgs e)
        {
            MbapHeader header = MbapHeader.Decode(e.Message);

            if (header == null)
            {
                logger?.LogWarning("MBAP Header returned null");
                return; //assume keep alive
            }

            if (!map.HasItem(header.UnitId))
            {
                byte[] errorMsg = ModbusErrorMessage.Create(e.Message, ErrorCode.GatewayPathsNotAvailable);
                InputChannel.SendAsync(errorMsg).GetAwaiter();
                return;
            }

            if (!map.GetItem(header.UnitId).Authorize(e.Message))
            {
                byte[] errorMsg = ModbusErrorMessage.Create(e.Message, ErrorCode.IllegalAddress);
                InputChannel.SendAsync(errorMsg).GetAwaiter();
                return;
            }

            byte[] message = e.Message;
            byte[] msg     = null;

            foreach (var filter in InputFilters)
            {
                msg = filter.Execute(message);
                msg ??= message;
            }

            OutputChannel.SendAsync(msg).GetAwaiter();
        }
Ejemplo n.º 8
0
        public void LoadInput(int channel)
        {
            // Remove previous triggers
            Brain.KB.Sources.DetachAllEvents(this.Trigger);


            if (channel >= Brain.KB.ChannelCount)
            {
                return;
            }

            SelectedIndex = channel;
            ui.TabControlWaves.SelectedIndex = channel;

            if (channel < 0)
            {
                return;
            }

            CurrentChannel = (InputChannel)Brain.KB.Sources.InputChannels[channel];

            ui.propertyGrid1.SelectedObject = CurrentChannel.Config;
            ui.velocityMapControl1.Map      = ((InputChannelConfig)CurrentChannel.Config).Velocity;
            ui.textBoxHits.Text             = "0";
            ui.textBoxVelocity.Text         = "";

            // Subscribe to the trigger event
            var triggerEvent = CurrentChannel.Events.First(x => x.Name == InputChannel.TRIGGER_EVENT);

            triggerEvent.Add(this.Trigger, null);

            ui.velocityMapControl1.Invalidate();
        }
        private async Task OpenChannels()
        {
            InputChannel = new InputChannel(
                await StartChannelAsync(ServiceType.SystemInput));

            /*
             *  InputTvRemoteChannel fails when connecting non-authenticated
             *  (Either a bug or feature from Microsoft!)
             *  Simply disabling it for now - it serves no use anyways atm
             * InputTvRemoteChannel = new InputTVRemoteChannel(
             *  await StartChannelAsync(ServiceType.SystemInputTVRemote));
             */
            MediaChannel = new MediaChannel(
                await StartChannelAsync(ServiceType.SystemMedia));
            TextChannel = new TextChannel(
                await StartChannelAsync(ServiceType.SystemText));
            BroadcastChannel = new BroadcastChannel(
                await StartChannelAsync(ServiceType.SystemBroadcast));
            if (this.connectedAuthenticated)
            {
                InputTvRemoteChannel = new InputTVRemoteChannel(
                    await StartChannelAsync(ServiceType.SystemInputTVRemote)
                    );
            }
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        protected override void OnSendInMessage(Message message)
        {
            if (!InputChannel.IsOpened)
            {
                InputChannel.Open();
            }

            InputChannel.SendInMessage(message);
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            if (!InputChannel.IsOpened())
            {
                InputChannel.Open();
            }

            return(InputChannel.SendInMessage(message));
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        public override void SendInMessage(Message message)
        {
            if (!InputChannel.IsOpened)
            {
                InputChannel.Open();
            }

            InputChannel.SendInMessage(message);
        }
Ejemplo n.º 13
0
        void IMessageChannel.SendInMessage(Message message)
        {
            if (!InputChannel.IsOpened)
            {
                InputChannel.Open();
            }

            InputChannel.SendInMessage(message);
        }
Ejemplo n.º 14
0
        public async Task <Updates> editTitle(InputChannel channel, string title)
        {
            var request = new TL.ChannelsEditTitleRequest(channel, title);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 15
0
        public async Task <Updates> updatePinnedMessage(InputChannel channel, True silent, int id)
        {
            var request = new TL.ChannelsUpdatePinnedMessageRequest(silent, channel, id);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 16
0
        public async Task <Updates> toggleSignatures(InputChannel channel, bool enabled)
        {
            var request = new TL.ChannelsToggleSignaturesRequest(channel, enabled);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 17
0
        public async Task <ExportedMessageLink> exportMessageLink(InputChannel channel, int id)
        {
            var request = new TL.ChannelsExportMessageLinkRequest(channel, id);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 18
0
        public async Task <Updates> deleteChannel(InputChannel channel)
        {
            var request = new TL.ChannelsDeleteChannelRequest(channel);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 19
0
        public async Task <bool> editAbout(InputChannel channel, string about)
        {
            var request = new TL.ChannelsEditAboutRequest(channel, about);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 20
0
        public async Task <Updates> kickFromChannel(InputChannel channel, InputUser user_id, bool kicked)
        {
            var request = new TL.ChannelsKickFromChannelRequest(channel, user_id, kicked);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 21
0
        public async Task <Updates> inviteToChannel(InputChannel channel, List <InputUser> users)
        {
            var request = new TL.ChannelsInviteToChannelRequest(channel, users);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 22
0
        public async Task <bool> updateUsername(InputChannel channel, string username)
        {
            var request = new TL.ChannelsUpdateUsernameRequest(channel, username);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 23
0
        public async Task <Updates> editPhoto(InputChannel channel, InputChatPhoto photo)
        {
            var request = new TL.ChannelsEditPhotoRequest(channel, photo);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 24
0
        public async Task <bool> readHistory(InputChannel channel, int max_id)
        {
            var request = new TL.ChannelsReadHistoryRequest(channel, max_id);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 25
0
        public async Task <ExportedChatInvite> exportInvite(InputChannel channel)
        {
            var request = new TL.ChannelsExportInviteRequest(channel);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 26
0
        public async Task <bool> reportSpam(InputChannel channel, InputUser user_id, List <int> id)
        {
            var request = new TL.ChannelsReportSpamRequest(channel, user_id, id);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 27
0
        public async Task <Updates> editAdmin(InputChannel channel, InputUser user_id, ChannelParticipantRole role)
        {
            var request = new TL.ChannelsEditAdminRequest(channel, user_id, role);

            await _sender.Send(request);

            await _sender.Receive(request);

            return(request.Result);
        }
Ejemplo n.º 28
0
        public void Receive_Deserializes_Input_From_Buffer()
        {
            string expectedInput = "1234567";
            var buffer = new ArrayBuffer(Encoding.UTF8.GetBytes(expectedInput), 0, expectedInput.Length);
            var reader = A.Fake<IBufferedReader>();
            A.CallTo(() => reader.Read()).Returns(buffer);
            var channel = new InputChannel<string>(reader, new StringDeserializer());

            string actualInput = channel.Receive();

            Assert.That(actualInput, Is.EqualTo(expectedInput));
        }
Ejemplo n.º 29
0
        public async Task <Tuple <List <User>, ChannelParticipant> > getParticipant(InputChannel channel, InputUser user_id)
        {
            var request = new TL.ChannelsGetParticipantRequest(channel, user_id);

            await _sender.Send(request);

            await _sender.Receive(request);

            var result = (TL.ChannelsChannelParticipantType)request.Result;

            return(new Tuple <List <User>, ChannelParticipant>(result.Users, result.Participant));
        }
Ejemplo n.º 30
0
        public void ReadInteger()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));

            output.Write(123);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.AreEqual(123, channel.Read());
        }
Ejemplo n.º 31
0
        getParticipants(InputChannel channel, ChannelParticipantsFilter filter, int offset, int limit)
        {
            var request = new TL.ChannelsGetParticipantsRequest(channel, filter, offset, limit);

            await _sender.Send(request);

            await _sender.Receive(request);

            var result = (TL.ChannelsChannelParticipantsType)request.Result;

            return(new Tuple <List <User>, List <ChannelParticipant> >(result.Users, result.Participants));
        }
Ejemplo n.º 32
0
        public void ReadNull()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));

            output.Write(null);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.IsNull(channel.Read());
        }