Exemplo n.º 1
0
 private void Button1_Tapped_1(object sender, TappedRoutedEventArgs e)
 {
     if (DirectCommand != null)
     {
         DirectCommand.Execute(null);
     }
 }
Exemplo n.º 2
0
        void HandleSendEvent(DirectCommand directCommand)
        {
            var eventId   = (byte)directCommand.EventId;
            var eventData = CodecUtils.DeserializePlayObject(directCommand.Msg);
            var senderId  = directCommand.FromActorId;

            Client.OnCustomEvent?.Invoke(eventId, eventData, senderId);
        }
Exemplo n.º 3
0
 public MainViewModel(MainWindow window)
 {
     this.window        = window;
     this.DirectCommand = new DirectCommand(() => new PropertyObservableTest().ShowDialog());
     this.DirectCommand.RaiseCanExecuteChanged();
     PropertyObservableNullReferenceCommand = new DirectCommand(() => new PropertyObservableNullReferenceTest().ShowDialog());
     ConcurrencyTestCommand = new DirectCommand(() => new General.MainWindow().ShowDialog());
 }
Exemplo n.º 4
0
 public IActionResult Post(DirectCommand directCommand)
 {
     try
     {
         if (directCommand.Command != null)
         {
             return(Ok(management.Commander(directCommand)));
         }
         return(BadRequest("failed"));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public MainViewModel(MainWindow window)
        {
            this.window = window;
            var command = new DirectCommand(this.Execute, this.CanExecute);

            command.RaiseCanExecuteChanged();
            this.TestCommand = command;
            this.timer       = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(1)
            };
            this.timer.Tick += (e, a) =>
            {
                this.Text = DateTime.Now.ToLongTimeString();
                command.RaiseCanExecuteChanged();
                window.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            };
        }
Exemplo n.º 6
0
        internal Task SendEvent(byte eventId, PlayObject eventData, SendEventOptions options)
        {
            var direct = new DirectCommand {
                EventId = eventId
            };

            if (eventData != null)
            {
                direct.Msg = ByteString.CopyFrom(CodecUtils.SerializePlayObject(eventData));
            }
            direct.ReceiverGroup = (int)options.ReceiverGroup;
            if (options.TargetActorIds != null)
            {
                direct.ToActorIds.AddRange(options.TargetActorIds);
            }
            _ = Send(CommandType.Direct, OpType.None, new Body {
                Direct = direct
            });
            return(Task.FromResult(true));
        }
Exemplo n.º 7
0
        private async Task OnMessaage(GenericCommand notification)
        {
            DirectCommand direct = notification.DirectMessage;
            // 反序列化消息
            LCIMMessage message;

            if (direct.HasBinaryMsg)
            {
                // 二进制消息
                byte[] bytes = direct.BinaryMsg.ToByteArray();
                message = LCIMBinaryMessage.Deserialize(bytes);
            }
            else
            {
                // 类型消息
                message = LCIMTypedMessage.Deserialize(direct.Msg);
            }
            // 填充消息数据
            message.ConversationId = direct.Cid;
            message.Id             = direct.Id;
            message.FromClientId   = direct.FromPeerId;
            message.SentTimestamp  = direct.Timestamp;
            message.MentionAll     = direct.MentionAll;
            message.MentionIdList  = direct.MentionPids.ToList();
            message.Mentioned      = message.MentionAll ||
                                     message.MentionIdList.Contains(Client.Id);
            message.PatchedTimestamp = direct.PatchTimestamp;
            message.IsTransient      = direct.Transient;
            // 获取对话
            LCIMConversation conversation = await Client.GetOrQueryConversation(direct.Cid);

            conversation.Unread++;
            conversation.LastMessage = message;
            // 通知服务端已接收
            if (!(conversation is LCIMChatRoom) && !message.IsTransient)
            {
                // 只有非暂态消息才需要发送 ack
                _ = Ack(message.ConversationId, message.Id);
            }
            Client.OnMessage?.Invoke(conversation, message);
        }
Exemplo n.º 8
0
    public void RegisterCommand(string command, object instance, MethodInfo method)
    {
        DirectCommand value = default(DirectCommand);

        value.command            = command;
        value.instance           = new WeakReference(instance, false);
        value.method             = method;
        value.parameterCount     = method.GetParameters().Length;
        value.variableParamCount = false;
        ParameterInfo[] parameters = method.GetParameters();
        for (int i = 0; i < parameters.Length; i++)
        {
            ParameterInfo parameterInfo = parameters[i];
            if (parameterInfo.GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0)
            {
                value.variableParamCount = true;
                break;
            }
        }
        directCommands[command] = value;
    }
Exemplo n.º 9
0
        internal Task <AVIMMessage> SendMessageAsync(AVIMClient client, AVIMConversation conversation, AVIMMessage message)
        {
            var tcs     = new TaskCompletionSource <AVIMMessage>();
            var sendMsg = new DirectCommand {
                // TODO 完善消息体
                Cid = conversation.convId,
                Msg = message.ToString()
            };
            var cmd = commandFactory.NewRequest(client.ClientId, CommandType.Direct);

            cmd.directMessage = sendMsg;
            SendRequest(cmd).ContinueWith(t => {
                if (t.IsFaulted)
                {
                    tcs.SetException(t.Exception.InnerException);
                }
                else
                {
                    tcs.SetResult(message);
                }
            });
            return(tcs.Task);
        }
Exemplo n.º 10
0
 /// <summary>
 /// The constructor.
 /// </summary>
 public API(Robot _robot)
     : base(_robot)
 {
     DirectCommand = new NXT.API.DirectCommand(_robot);
     SystemCommand = new NXT.API.SystemCommand(_robot);
 }
Exemplo n.º 11
0
 public void Send(DirectCommand command)
 {
     Send((Command)command);
 }
Exemplo n.º 12
0
 /// <summary>
 /// The constructor.
 /// </summary>
 public API(Robot _robot)
     : base(_robot)
 {
     DirectCommand = new NXT.API.DirectCommand(_robot);
     SystemCommand = new NXT.API.SystemCommand(_robot);
 }
Exemplo n.º 13
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.myview);

            var btnForward  = FindViewById <Button>(Resource.Id.myview_btnforward);
            var btnBackward = FindViewById <Button>(Resource.Id.myview_btnbackward);
            var btnLeft     = FindViewById <Button>(Resource.Id.myview_btnleft);
            var btnRight    = FindViewById <Button>(Resource.Id.myview_btnright);

            var btnGo   = FindViewById <Button>(Resource.Id.myview_btngo);
            var btnStop = FindViewById <Button>(Resource.Id.myview_btnstop);

            //
            var communication = new BluetoothCommunication(@"PPAP09");


            var brick   = new Brick(communication);
            var command = new DirectCommand(brick);

            brick.ConnectAsync();

            communication.ReportReceived += (object sender, ReportReceivedEventArgs e) => {
                WriteLine("Connected");

                Connected = true;
            };


            brick.Ports[InputPort.One].SetMode(ColorMode.ReflectiveRgb);
            brick.Ports[InputPort.One].PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                WriteLine(brick.Ports[InputPort.One].SIValue);
            };


            btnForward.Click += async(sender, e) => {
                WriteLine("前");
                IsForward = true;
                if (Connected)
                {
                    // 兩輪向前
                    await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed);

                    await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed);
                }
            };

            btnBackward.Click += async(sender, e) => {
                WriteLine("後");
                IsForward = false;
                if (Connected)
                {
                    // 兩輪向後
                    await command.TurnMotorAtSpeedAsync(OutputPort.A, -Speed);

                    await command.TurnMotorAtSpeedAsync(OutputPort.B, -Speed);
                }
            };

            btnLeft.Click += async(sender, e) => {
                WriteLine("左");

                if (Connected)
                {
                    // 左輪向後,右輪向前
                    await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed);

                    await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed);
                }
            };

            btnRight.Click += async(sender, e) => {
                WriteLine("右");

                if (Connected)
                {
                    // 左輪向前,右輪向後
                    await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed);

                    await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed);
                }
            };

            btnGo.Click += async(sender, e) => {
                WriteLine("油門");

                Speed += 5;

                if (Speed >= 50)
                {
                    Speed = 50;
                }

                if (Connected)
                {
                    if (IsForward)
                    {
                        await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed);

                        await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed);
                    }
                    else
                    {
                        await command.TurnMotorAtSpeedAsync(OutputPort.A, -Speed);

                        await command.TurnMotorAtSpeedAsync(OutputPort.B, -Speed);
                    }
                }
            };

            btnStop.Click += async(sender, e) => {
                WriteLine("煞車");

                if (Connected)
                {
                    // 兩輪停止
                    await command.StopMotorAsync(OutputPort.A, true);

                    await command.StopMotorAsync(OutputPort.B, true);
                }
            };

            Connected = false;
            IsForward = true;
            Speed     = 20;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Check command and verify them
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="cardNum"></param>
        /// <returns>True (Success) or False (Failed)</returns>
        public string Commander(DirectCommand command)
        {
            if (!GetConnected(command.CardReader.IP, command.CardReader.Port))
            {
                return("Failed to connect! Please check and try again.");
            }
            switch (command.Command)
            {
            case "OpnDoor":
                while (!OpenDoor(command.CardReader.CrAddress))
                {
                    ;
                }
                return("The door is open now!");

            case "AddAdmin":
                AddNewAdmin(command.CardReader.IP, command.CardNum);
                return("add " + command.CardNum + " as admin!");

            case "ClrUser":
                while (!ClearPm(command.CardReader.CrAddress))
                {
                    ;
                }
                return("Delete all user has done!");

            case "DelAdmin":
                RemoveAdmin(command.CardReader.CrAddress, command.CardNum);
                return("Delete admin has done!");

            case "RstCr":
                while (!SetDate(command.CardReader.CrAddress))
                {
                    ;
                }
                while (!SetTime(command.CardReader.CrAddress))
                {
                    ;
                }

                while (!ClearPm(command.CardReader.CrAddress))
                {
                    ;
                }
                while (!ClearZm(command.CardReader.CrAddress))
                {
                    ;
                }
                while (!ClearAg(command.CardReader.CrAddress))
                {
                    ;
                }
                while (!ClearCo(command.CardReader.CrAddress))
                {
                    ;
                }

                while (!EnablePm(command.CardReader.CrAddress))
                {
                    ;
                }
                while (!EnableZm(command.CardReader.CrAddress))
                {
                    ;
                }
                return("Reset has done!");

            case "SetDate":
                while (!SetDate(command.CardReader.CrAddress))
                {
                    ;
                }
                return("Set date has done!");

            case "SetTime":
                while (!SetTime(command.CardReader.CrAddress))
                {
                    ;
                }
                return("Set time has done!");

            case "F4Function":
                while (!F4Function(command.CardReader.CrAddress, command.FuncNo))
                {
                    ;
                }
                return("Function sent done!");
            }
            return("Command error!");
        }
Exemplo n.º 15
0
        internal async Task <LCIMMessage> Send(string convId,
                                               LCIMMessage message,
                                               LCIMMessageSendOptions options)
        {
            DirectCommand direct = new DirectCommand {
                FromPeerId = Client.Id,
                Cid        = convId,
            };

            if (message is LCIMTypedMessage typedMessage)
            {
                direct.Msg = JsonConvert.SerializeObject(typedMessage.Encode());
            }
            else if (message is LCIMBinaryMessage binaryMessage)
            {
                direct.BinaryMsg = ByteString.CopyFrom(binaryMessage.Data);
            }
            else
            {
                throw new ArgumentException("Message MUST be LCIMTypedMessage or LCIMBinaryMessage.");
            }
            // 暂态消息
            if (options.Transient)
            {
                direct.Transient = options.Transient;
            }
            // 消息接收回执
            if (options.Receipt)
            {
                direct.R = options.Receipt;
            }
            // 遗愿消息
            if (options.Will)
            {
                direct.Will = options.Will;
            }
            // 推送数据
            if (options.PushData != null)
            {
                direct.PushData = JsonConvert.SerializeObject(options.PushData);
            }
            // 提醒所有人
            if (message.MentionAll)
            {
                direct.MentionAll = message.MentionAll;
            }
            // 提醒用户列表
            if (message.MentionIdList != null &&
                message.MentionIdList.Count > 0)
            {
                direct.MentionPids.AddRange(message.MentionIdList);
            }
            GenericCommand command = NewCommand(CommandType.Direct);

            command.DirectMessage = direct;
            // 优先级
            if (command.Priority > 0)
            {
                command.Priority = (int)options.Priority;
            }
            GenericCommand response = await Connection.SendRequest(command);

            // 消息发送应答
            AckCommand ack = response.AckMessage;

            message.Id            = ack.Uid;
            message.SentTimestamp = ack.T;
            message.FromClientId  = Client.Id;
            return(message);
        }
Exemplo n.º 16
0
 protected void SendDirectCommand(DirectCommand directCommand)
 {
     _ = Send(CommandType.Direct, OpType.None, new Body {
         Direct = directCommand
     });
 }
Exemplo n.º 17
0
 public bool Send(DirectCommand command)
 {
     byte[] data = new byte[2];
     data[0] = 0x00;
     data[1] = (byte)command;
     return Send(data);
 }
Exemplo n.º 18
0
 public void SendDirectCommand(InsteonAddress addr, DirectCommand command1, byte command2 = 0)
 {
     var b = new byte[] { 0x02, 0x62, addr.AddressBytes[0], addr.AddressBytes[1], addr.AddressBytes[2], 0xf, (byte)command1, command2 };
     this.port.Write(b, 0, b.Length);
     Thread.Sleep(200);
 }