Пример #1
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);
        }
Пример #2
0
        public IMessageModel CreateNew(
            Enums.Direction direction = Enums.Direction.Unknown,
            Enums.MessageType type    = Enums.MessageType.Unknown,
            string idOverride         = "",
            string hostIdOverride     = "",
            long timestampOverride    = 0)
        {
            IMessageModel output = _messageFactory();

            output.AssaignID(string.IsNullOrWhiteSpace(idOverride) ? string.Empty : idOverride);
            output.AssighHostID(string.IsNullOrWhiteSpace(hostIdOverride)? string.Empty : hostIdOverride);
            output.Type      = type;
            output.Direction = direction;
            output.Timestamp = timestampOverride < 0 ? Timestamp.TimestampNow : timestampOverride;
            return(output);
        }