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); }
/// <summary> /// Process single command by trying to inject it into existing / new message and checking this message for completition / timeout.<br/> /// Using this method does not guarantee first priority of processing if <see cref="StartProcessingCommands"/> is running. /// </summary> /// <param name="command">Command to be processed</param> public void Process(ICommandModel command) { if (IsMessageAlreadyComplete(command.Id)) { HandleBadCommand(command); } else { IMessageModel message = GetMessageToWorkWithBasedOn(command); if (!message?.Add(command) ?? true) { HandleBadCommand(command); } if (IsComplete(message)) { PushFromIncompleteToProcessed(message); } } }