示例#1
0
        private ICommandModel CreateFromValidLengthRawData(string data)
        {
            var hostId   = GetHostId(data);
            var type     = GetCommandTypeValue(data);
            var id       = GetID(type, data);
            var dataPack = GetDataPack(type, data);

            return(_factory.Create(type, id, Timestamp.TimestampNow, dataPack, hostId));
        }
示例#2
0
        public IMessageModel GenerateConfirmationOf(IMessageModel message)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message), "ConfirmationFactory - GenerateConfirmationOf: Cannot create confirmation of NULL");
            }

            IMessageModel confirmation = _messageFactory.CreateNew(Direction.Outgoing,
                                                                   MessageType.Confirmation,
                                                                   message.Id);

            confirmation.Add(_commandFactory.Create(CommandType.HandShake));
            confirmation.Add(_commandFactory.Create(CommandType.Confirmation));

            foreach (var c in message)
            {
                ICommandModel responseCommand = _commandFactory.Create(timestampOverride: confirmation.Timestamp);
                switch (c.CommandType)
                {
                case CommandType.Error:
                    responseCommand.CommandType = CommandType.ReceivedAsError;
                    break;

                case CommandType.Unknown:
                    responseCommand.CommandType = CommandType.ReceivedAsUnknown;
                    break;

                case CommandType.Partial:
                    responseCommand.CommandType = CommandType.ReceivedAsPartial;
                    break;

                default:
                    responseCommand.CommandType = CommandType.ReceivedAsCorrect;
                    break;
                }
                confirmation.Add(responseCommand);
            }

            if (message.Errors.HasFlag(Errors.CompletitionTimeout))
            {
                confirmation.Add(_commandFactory.Create(CommandType.CompletitionTimeoutOccured));
            }

            if (message.Errors.HasFlag(Errors.ConfirmationTimeout))
            {
                confirmation.Add(_commandFactory.Create(CommandType.ConfirmationTimeoutOccurred));
            }

            confirmation.Add(_commandFactory.Create(CommandType.EndMessage));

            // Assigns id also to all commands inside
            confirmation.AssaignID(message.Id);
            confirmation.AssighHostID(_hostId);

            return(confirmation);
        }
        public ICommandModel CreateModel(ICommandModelFactory commandModelFactory)
        {
            ICommandModel commandModel = commandModelFactory.Create(CommandType);

            if (commandModel == null)
            {
                throw new InvalidCommandException();
            }

            foreach (CommandParameterSeed parameterInfo in ParametersSeeds)
            {
                parameterInfo.SetPropertyValueOn(commandModel);
            }

            return(commandModel);
        }