Example #1
0
        public async Task <bool> SendAsync(IConfirmable order)
        {
            var errorState = ErrorState.Unchecked().Valid();

            try
            {
                if (!IsReady)
                {
                    errorState = errorState.DeviceDisconnected();
                }
                else if (!await _deviceHandler.SendAsync(_commandTranslator.TranslateToCommand(order)).ConfigureAwait(false))
                {
                    errorState = errorState.SendFailure();
                }
            }
            catch (DeviceDisconnectedException)
            {
                errorState = errorState.DeviceDisconnected();
            }

            if (errorState != ErrorState.Unchecked().Valid())
            {
                _awaiterDispatch.AddResponse(_confirmationFactory.Create(order, errorState));
            }

            return(true);
        }
Example #2
0
        public async Task <bool> Confirm(IConfirmable message, ErrorState errors = null)
        {
            var state        = errors ?? ErrorState.Unchecked().Valid();
            var confirmation = _confirmationFactory.Create(message, state);

            return(await SendAsync(confirmation).ConfigureAwait(false));
        }
Example #3
0
        public Command(IPart id, IPart hostID, IPart target, IPart order, IPart data, Timestamp timestamp)
        {
            _executeValidation = Validate;
            ID         = id;
            HostID     = hostID;
            Target     = target;
            Order      = order;
            Data       = data;
            Timestamp  = timestamp;
            ErrorState = ErrorState.Unchecked();

            SetUpStateToValidationMap();
            SetupPartCollection(ID, HostID, Target, Order, Data);
        }
Example #4
0
        public void When_informed_by_DeviceHandler_about_new_received_confirmation_type_command_provides_proper_confirmation_to_ResponseAwaiterDispatch()
        {
            Order receivedOrder = null;

            ProtocolHandler.OrderReceived += (_, order) => receivedOrder = order;

            RaiseNewCommandEventOnDevice(CommandsTestObjects.GetProperTestCommand_order("ID01"));
            RaiseNewCommandEventOnDevice(CommandsTestObjects.GetProperTestCommand_confirmation("ID01"));
            var receivedConfirmation = ResponseAwaiterDispatch.ConfirmationOf(receivedOrder);

            Assert.True(receivedOrder.ID == receivedConfirmation.Confirms);
            Assert.IsType <ErrorState>(receivedConfirmation.ContainedErrors);
            Assert.True(receivedConfirmation.IsValid);
            Assert.True(receivedConfirmation.ContainedErrors == ErrorState.Unchecked().Valid());
        }
Example #5
0
 public static Confirmation GetNormalConfirmation(string id)
 {
     return(new Confirmation(id, ErrorState.Unchecked().Valid(), TimestampFactory.Timestamp));
 }