public override bool IsHandler(ReceiveCommand command)
 {
     if (command.GetType() == typeof(ReceiveCommand))
     {
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 static async Task HandleInput(string input)
 {
     if (input.StartsWith("connect", StringComparison.OrdinalIgnoreCase))
     {
         await ConnectCommand.HandleCommand(input);
     }
     if (input.StartsWith("receive", StringComparison.OrdinalIgnoreCase))
     {
         ReceiveCommand.HandleCommand(input);
     }
     if (input.StartsWith("say", StringComparison.OrdinalIgnoreCase))
     {
         SayCommand.HandleCommand(input);
     }
 }
        private void ReadMessage()
        {
            string message = "";
            bool   isReply = false;
            int    id      = 0;

            lock (_receiverLock)
            {
                if (_receiverAccessor == null)
                {
                    return;
                }

                short messageType = _receiverAccessor.ReadInt16(2);
                isReply = messageType > 0;
                id      = _receiverAccessor.ReadInt32(4);
                int bodyLength = _receiverAccessor.ReadInt32(8);

                _receiverAccessor.ReadArray(12, _readBuffer, 0, bodyLength);
                message = Encoding.UTF8.GetString(_readBuffer, 0, bodyLength);
                _receiverAccessor.Write(0, (byte)0);
            }


            //3パターンある
            // - こちらが投げたQueryの返答が戻ってきた
            // - Commandを受け取った
            // - Queryを受け取った
            if (isReply)
            {
                if (_sendedQueries.TryRemove(id, out var src))
                {
                    //戻ってきた結果によってTaskが完了となる
                    src.SetResult(message);
                }
            }
            else if (id == 0)
            {
                ReceiveCommand?.Invoke(this, new ReceiveCommandEventArgs(message));
            }
            else
            {
                var query = new ReceivedQuery(message, id, this);
                ReceiveQuery?.Invoke(this, new ReceiveQueryEventArgs(query));
            }
        }
Beispiel #4
0
        public void ExecuteRemoteCommand()
        {
            ReceiveCommand GetCmd           = new ReceiveCommand();
            PacketElements CmdPacketElement = GetCmd.GetCommandPacket();

            Command = CmdPacketElement.ActualCommand;
            IResult             ExecResult    = Execute();
            ResultPacketElement ResultElement = new ResultPacketElement();

            ResultElement.ActualResult = ExecResult;
            ResultElement.Header       = int.Parse(ConfigurationSettings.AppSettings["ResultHeader"]);
            PackResult PackRes = new PackResult();

            PackRes.ResultPacketElements = ResultElement;
            byte[]         ResultPacket = PackRes.ResultPack;
            TransmitResult SendResult   = new TransmitResult();

            SendResult.DataPacket       = ResultPacket;
            SendResult.RemoteSystemName = GetCmd.SenderIP;
            SendResult.SendResult();
        }
Beispiel #5
0
        /// <summary>Create a new RefUpdate copying the batch settings.</summary>
        /// <remarks>Create a new RefUpdate copying the batch settings.</remarks>
        /// <param name="cmd">specific command the update should be created to copy.</param>
        /// <returns>a single reference update command.</returns>
        /// <exception cref="System.IO.IOException">
        /// the reference database cannot make a new update object for
        /// the given reference.
        /// </exception>
        protected internal virtual RefUpdate NewUpdate(ReceiveCommand cmd)
        {
            RefUpdate ru = refdb.NewUpdate(cmd.GetRefName(), false);

            if (IsRefLogDisabled())
            {
                ru.DisableRefLog();
            }
            else
            {
                ru.SetRefLogIdent(refLogIdent);
                ru.SetRefLogMessage(refLogMessage, refLogIncludeResult);
            }
            switch (cmd.GetType())
            {
            case ReceiveCommand.Type.DELETE:
            {
                if (!ObjectId.ZeroId.Equals(cmd.GetOldId()))
                {
                    ru.SetExpectedOldObjectId(cmd.GetOldId());
                }
                ru.SetForceUpdate(true);
                return(ru);
            }

            case ReceiveCommand.Type.CREATE:
            case ReceiveCommand.Type.UPDATE:
            case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
            default:
            {
                ru.SetForceUpdate(IsAllowNonFastForwards());
                ru.SetExpectedOldObjectId(cmd.GetOldId());
                ru.SetNewObjectId(cmd.GetNewId());
                return(ru);

                break;
            }
            }
        }
        public byte[] ReadMessage()
        {
            ReceiveCommand message   = ReceiveCommand.None;
            int            readData1 = 0;
            int            readData2 = 0;

            try
            {
                // Expected byte 0x02 (Start byte)
                readData1 = interfaceStream.ReadByte();
                if (readData1 != StartByte)
                {
                    throw new InvalidDataException(String.Format("Unexpected data {0}", readData1));
                }

                // Expected bytes 0x01 ff (Command bytes)
                readData1 = interfaceStream.ReadByte();
                readData2 = interfaceStream.ReadByte();
                message   = (ReceiveCommand)((readData1 << 8) | (readData2));

                // Payload if applicable
                readData1 = interfaceStream.ReadByte();
                byte[] payload = new byte[readData1];
                for (byte i = 0; i < readData1; i++)
                {
                    payload[i] = (byte)interfaceStream.ReadByte();
                }

                // Checksum
                readData1 = interfaceStream.ReadByte();

                // Check values
                readData1 ^= StartByte;
                readData1 ^= (ushort)message >> 8;
                readData1 ^= (ushort)message & 0xff;
                readData1 ^= payload.Length;

                for (byte n = 0; n < payload.Length; n++)
                {
                    readData1 ^= payload[n];
                }

                if (readData1 != 0x00)
                {
                    throw new InvalidDataException("Unexpected checksum");
                }

                // Expected byte 0x03 (Stop byte)
                readData1 = interfaceStream.ReadByte();
                if (readData1 != StopByte)
                {
                    throw new InvalidDataException(String.Format("Unexpected data {0}", readData1));
                }

                return(payload);
            }
            catch (TimeoutException)
            {
                return(null);
            }
        }
        public override void HandleRequest(ReceiveCommand command)
        {
            new UIAlertView("Scanned", command.ReceiveString.ToString(), null, "OK", null).Show();

            Controller.OnBarcodeScanAsync(command.ReceiveString.ToString());
        }
Beispiel #8
0
 /// <summary>Add a single command to this batch update.</summary>
 /// <remarks>Add a single command to this batch update.</remarks>
 /// <param name="cmd">the command to add, must not be null.</param>
 /// <returns>
 ///
 /// <code>this</code>
 /// .
 /// </returns>
 public virtual NGit.BatchRefUpdate AddCommand(ReceiveCommand cmd)
 {
     commands.AddItem(cmd);
     return(this);
 }