コード例 #1
0
 internal void SetMessageResult(IMessageResult messageResult)
 {
     if (Interlocked.CompareExchange(ref this.messageResult, messageResult, null) != null)
     {
         throw new InvalidOperationException("A message-result is already assigned");
     }
 }
コード例 #2
0
        internal virtual void Complete(RedisResult result)
        {
#if VERBOSE
            Trace.WriteLine("< " + command);
#endif
            IMessageResult snapshot = Interlocked.Exchange(ref messageResult, null); // only run once
            ChangeState(MessageState.Sent, MessageState.Complete);
            if (snapshot != null)
            {
                snapshot.Complete(result);
            }
        }
コード例 #3
0
            // avoid lots of delegate creations

            internal override sealed IEnumerable <RedisMessage> CreateMessages()
            {
                yield return(RedisMessage.Create(db, RedisLiteral.WATCH, key));

                IMessageResult msgResult = CreateMessageResult(this);

                msgResult.Task.ContinueWith(testEquality);
                RedisMessage message = hashField == null
                                           ? RedisMessage.Create(db, RedisLiteral.GET, key)
                                           : RedisMessage.Create(db, RedisLiteral.HGET, key, hashField);

                message.SetMessageResult(msgResult);
                yield return(message);
            }
コード例 #4
0
        private async Task <Result> Execute(IMessage command, Func <Task <Result> > func)
        {
            IMessageResult messageResult = null;

            try
            {
                var result = await func();

                messageResult = GetLogFromResult(command, result);
                return(result);
            }
            catch (Exception ex)
            {
                messageResult = GetLogFromError(command, ex);
                return(Result.Failure(ex.Message));
            }
            finally
            {
                await SaveCommand(messageResult);
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="receiverByte"></param>
        private void ParseUBX(byte receiverByte)
        {
            switch (_ubxState)
            {
            case UBXState.Start:
                _parserMessage.SetLength(0);
                _ubxCrcA  = 0x00;
                _ubxCrcB  = 0x00;
                _ubxState = UBXState.Sync2;
                break;

            case UBXState.Sync2:
                if (receiverByte == 0x62)
                {
                    _ubxState = UBXState.Class;
                }
                else
                {
                    Debug.WriteLine("UBX Message Resetting: Sync2 failed");
                    _ubxState = UBXState.Start;
                    return;
                }
                break;

            case UBXState.Class:
                _ubxCrcA += receiverByte;
                _ubxCrcB += _ubxCrcA;
                _ubxState = UBXState.ID;
                break;

            case UBXState.ID:
                _ubxCrcA += receiverByte;
                _ubxCrcB += _ubxCrcA;
                _ubxState = UBXState.Length1;
                break;

            case UBXState.Length1:
                _ubxCrcA  += receiverByte;
                _ubxCrcB  += _ubxCrcA;
                _ubxLength = receiverByte;
                _ubxState  = UBXState.Length2;
                break;

            case UBXState.Length2:
                _ubxCrcA   += receiverByte;
                _ubxCrcB   += _ubxCrcA;
                _ubxLength += (ushort)(receiverByte << 8);
                _ubxState   = UBXState.Payload;
                break;

            case UBXState.Payload:
                _ubxCrcA += receiverByte;
                _ubxCrcB += _ubxCrcA;
                if (_ubxLength + 5 == _parserMessage.Position)
                {
                    _ubxState = UBXState.ChecksumA;
                }
                if (_parserMessage.Position >= 1022)
                {
                    Debug.WriteLine("UBX Message Resetting: Payload is too large");
                    _ubxState = UBXState.Start;
                    return;
                }
                break;

            case UBXState.ChecksumA:
                if (_ubxCrcA == receiverByte)
                {
                    _ubxState = UBXState.ChecksumB;
                }
                else
                {
                    Debug.WriteLine("UBX Message Resetting: Checksum A failed");
                    _ubxState = UBXState.Start;
                    return;
                }
                break;

            case UBXState.ChecksumB:
                if (_ubxCrcB == receiverByte)
                {
                    _ubxState = UBXState.End;
                }
                else
                {
                    Debug.WriteLine("UBX Message Resetting: Checksum B failed");
                    _ubxState = UBXState.Start;
                    return;
                }
                break;
            }

            _parserMessage.WriteByte(receiverByte);

            if (_ubxState == UBXState.End)
            {
                // Sending the received message after getting the last checksum

                byte[]         message       = _parserMessage.ToArray();
                IMessageResult messageObject = _messageFactory.Invoke(message);

                messageObject.TryParse(message);

                MessageReceived?.Invoke(this, new MessageReceivedEventArgs(message, messageObject, MessageProtocol.UBX));
                _ubxState = UBXState.Start;
            }
        }
コード例 #6
0
ファイル: RedisCommand.cs プロジェクト: raycode/booksleeve
 internal void SetMessageResult(IMessageResult messageResult)
 {
     if (Interlocked.CompareExchange(ref this.messageResult, messageResult, null) != null)
     {
         throw new InvalidOperationException("A message-result is already assigned");
     }
 }
コード例 #7
0
 /// <summary>
 /// Instantiate MessageReceivedEventArgs.
 /// </summary>
 /// <param name="message">The received message bytes.</param>
 /// <param name="result">The received message object.</param>
 /// <param name="type">The received message protocol type.</param>
 internal MessageReceivedEventArgs(byte[] message, IMessageResult result, MessageProtocol type)
 {
     Message         = message;
     MessageResult   = result;
     MessageProtocol = type;
 }
コード例 #8
0
 private Task SaveCommand(IMessageResult msgResult)
 {
     _storage.Add(msgResult);
     return(_storage.Save());
 }
コード例 #9
0
ファイル: SimpleMsgBus.cs プロジェクト: adwaer/infrastructure
 private Task SaveCommand(IMessageResult msgResult)
 {
     _crudUow.Add(msgResult);
     return(_crudUow.Save());
 }