public void OnSuccess(ICommandMessage commandMessage, object result) { if (_parameterType.IsInstanceOfType(result) || result == null) { _delegate.OnSuccess(commandMessage, result); } }
public void OnFailure(ICommandMessage commandMessage, Exception cause) { foreach (var callback in _callbacks) { callback.OnFailure(commandMessage, cause); } }
public void OnSuccess(ICommandMessage commandMessage, object result) { foreach (var callback in _callbacks) { callback.OnSuccess(commandMessage, result); } }
public IMessage CreateMessage(ICommandMessage command) { if (command == null) { return(null); } IMessage message = Factory.GetInstance <IMessage>(); DataContractSerializer serializer = new DataContractSerializer(command.GetType()); StringBuilder output = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(output, this.xmlWriterSettings)) { serializer.WriteObject(writer, command); writer.Flush(); message.Text = output.ToString(); message.ExtraProperties = command.GetProperties(); message.TtlInMinutes = command.TtlInMinutes; } /*using (MemoryStream memoryStream = new MemoryStream()) * { * serializer.WriteObject(memoryStream, command); * memoryStream.Position = 0; * * using (StreamReader reader = new StreamReader(memoryStream)) * { * message.Text = reader.ReadToEnd(); * } * }*/ message.Type = command.CommandName; message.SentDate = command.SendingDate; return(message); }
public void RegisterCommand(ICommandMessage command) { lock (lockObject) { commands.Add(command); } }
public void HandleCommand( ILog log, ICommandMessage com ) { switch (com.Command) { case Command.GetHeader: com.SetReply( log .LogParameters .LogItemTextFormatter .GetColumns()); break; case Command.GetHeaderText: com.SetReply( log .LogParameters .LogItemTextFormatter .GetHeader()); break; default: com.SetReply($"unknown command '{com.Command}'"); break; } }
/// <inheritdoc cref="SendAsync{TQueue, TMessage}(TMessage)"/> public static Task SendAsync <TQueue>(ICommandMessage <TQueue> message, Type messageType) where TQueue : ISendCommandQueue, new() { RockLogger.Log.Debug(RockLogDomains.Core, "Send Message Async: {@message} Message Type: {1}", message, messageType); if (!IsReady()) { ExceptionLogService.LogException($"A message was sent before the message bus was ready: {RockMessage.GetLogString( message )}"); return(Task.CompletedTask); } var queue = RockQueue.Get <TQueue>(); var endpoint = _transportComponent.GetSendEndpoint(_bus, queue.NameForConfiguration); message.SenderNodeName = NodeName; // NOTE: Use Task.Run to wrap an async instead of directly using async, otherwise async will get an exception if it isn't done before the HttpContext is disposed. return(Task.Run(async() => { await endpoint.Send(message, messageType, context => { context.TimeToLive = RockQueue.GetTimeToLive(queue); }); })); }
public VersionedAggregateIdentifier ResolveTarget(ICommandMessage command) { string aggregateIdentifier; long? aggregateVersion; try { aggregateIdentifier = FindIdentifier(command); aggregateVersion = FindVersion(command); } catch (FormatException e) { throw new ArgumentException("The value provided for the version is not a number.", e); } catch (Exception e) { if (e is TargetInvocationException || e is TargetException) { throw new ArgumentException("An exception occurred while extracting aggregate information form a command", e); } throw; } if (aggregateIdentifier == null) { throw new ArgumentException("Invalid command. It does not identify the target aggregate. " + $"Make sure at least one of the fields or methods in the {command.PayloadType.Name} class contains the " + "[TargetAggregateIdentifier] attribute and that it returns a non-null value."); } return(new VersionedAggregateIdentifier(aggregateIdentifier, aggregateVersion)); }
public object Handle(ICommandMessage msg) { return(ExecuteWithResult(() => { var interceptors = _inspector.CommandHandlerInterceptors .Where(chi => chi.CanHandle(msg)) .OrderBy(x => x.Priority) .Select(x => new AnnotatedCommandHandlerInterceptor(x, _aggregateRoot)) .ToList(); var handler = _inspector.CommandHandlers.GetValueOrDefault(msg.CommandName); object result; if (interceptors.IsEmpty()) { result = handler.Handle(msg, _aggregateRoot); } else { result = new DefaultInterceptorChain(CurrentUnitOfWork.Get(), interceptors.GetEnumerator(), MessageHandler <ICommandMessage> .Create(m => handler.Handle(msg, _aggregateRoot))).Proceed(); } if (_aggregateRoot == null) { _aggregateRoot = (T)result; return this.IdentifierAsString(); } return result; })); }
public ServerCommand(ID id, ID?target, ICommandMessage message) : this() { ID = id; M.ApplyChange(new CreatedBuilder { Target = target, Message = message }); }
private static BsonDocument SerializeBson(ContractTypeSerializer serializer, ICommandMessage message) { BsonDocument result = new BsonDocument(); using var writer = new BsonDocumentWriter(result); serializer.Serialize(new MongoWriterAdapter(writer), message); return(result); }
private void CommandReceivedHandler(object sender, CommandReceivedEventArgs e) { if (sender is IChatClient chatClient) { ICommandMessage commandMessage = _commandMessages.FirstOrDefault(c => c.CommandText == e.CommandWord); commandMessage?.Process(chatClient, e); } }
protected override object ResolveCommandTarget(ICommandMessage msg, object parent, PropertyInfo field, IEntityModel childEntityModel) { var commandHandlerRoutingKeys = ExtractCommandHandlerRoutingKeys(field, childEntityModel); var routingValue = commandHandlerRoutingKeys.GetValueOrDefault(msg.CommandName).GetValue <object>(msg.Payload); var fieldValue = field.GetValue(parent); return(fieldValue == null ? null : fieldValue.GetOrDefault(routingValue)); }
public void OnFailure(ICommandMessage commandMessage, Exception cause) { if (cause == null) { throw new ArgumentNullException(nameof(cause)); } _tcs.SetException(cause); }
public void Dispatch(ICommandMessage command) { var cmdType = command.GetType(); var handler = Activator.CreateInstance(handlers[cmdType]); var genericMethod = dispatchCommand.MakeGenericMethod(cmdType); genericMethod.Invoke(this, new object[] { handler, command }); }
public void OnFailure(ICommandMessage commandMessage, Exception cause) { _messageMonitorCallback.ReportFailure(cause); if (_delegate != null) { _delegate.OnFailure(commandMessage, cause); } }
public void OnSuccess(ICommandMessage commandMessage, object result) { _messageMonitorCallback.ReportSuccess(); if (_delegate != null) { _delegate.OnSuccess(commandMessage, result); } }
public VersionedAggregateIdentifier ResolveTarget(ICommandMessage command) { var identifier = (string)command.MetaData[_identifierKey]; Assert.NotNull(identifier, () => "The MetaData for the command does not exist or contains a null value"); var version = (long?)(_versionKey == null ? null : command.MetaData[_versionKey]); return(new VersionedAggregateIdentifier(identifier, version)); }
protected ICommandMessage ProcessInterceptors(ICommandMessage commandMessage) { var message = commandMessage; foreach (var dispatchInterceptor in _dispatchInterceptors) { message = dispatchInterceptor.Handle(message); } return(message); }
protected override object ResolveCommandTarget(ICommandMessage msg, object parent, PropertyInfo field, IEntityModel childEntityModel) { var commandHandlerRoutingKeys = ExtractCommandHandlerRoutingKeys(field, childEntityModel); var routingValue = commandHandlerRoutingKeys.GetValueOrDefault(msg.CommandName).GetValue <object>(msg.Payload); var enumerable = (IEnumerable)field.GetValue(parent); return(enumerable .Cast <object>() .FirstOrDefault(i => Equals(routingValue, childEntityModel.GetIdentifier(i)))); }
private void RetryDispatch(ICommandMessage commandMessage) { try { _commandBus.Dispatch(commandMessage, this); } catch (Exception e) { OnFailure(commandMessage, e); } }
public void ReportMessage(ICommandMessage message) { if (message.Type == CommandMessageType.Error) { ReportError(message.Message); } else { ReportInformation(message.Message); } }
public void Send(ICommandMessage domainCommand) { try { _subject.OnNext(domainCommand); } catch (Exception e) { _subject.OnError(e); } }
private ICommandMessage Intercept(ICommandMessage command) { var commandToDispatch = command; foreach (var interceptor in _dispatchInterceptors.Keys) { commandToDispatch = interceptor.Handle(commandToDispatch); } return(commandToDispatch); }
protected override void Handle(ICommandMessage command, IMessageHandler <ICommandMessage> handler, ICommandCallback callback) { lock (_lock) { if (!_shuttingDown) { var task = Task.Run(() => base.Handle(command, handler, callback), _cancellationTokenSource.Token); task.ContinueWith(x => _tasks.Remove(task)); _tasks.Add(task); } } }
private string FindIdentifier(ICommandMessage command) { foreach (var property in command.PayloadType.GetProperties()) { if (property.IsDefined(typeof(TargetAggregateIdentifierAttribute), true)) { return(property.GetValue(command)?.ToString()); } } return(null); }
public CommandBusTest() { commandBus = new CommandBus(); Mock <ICommandMessage> commandMock = new Mock <ICommandMessage>(); commandMock.Setup(c => c.GetType()).Returns(typeof(ICommandMessage)); command = commandMock.Object; handlerMock = new Mock <IHandler <ICommandMessage> >(); handler = handlerMock.Object; }
private void DoDisptach(ICommandMessage command, ICommandCallback callback) { var monitorCallback = _messageMonitor.OnMessageIngested(command); var handler = FindCommandHandlerFor(command).OrElseThrow(() => { var exception = new NoHandlerForCommandException($"No handler was subscribed to command {command.CommandName}"); monitorCallback.ReportFailure(exception); return(exception); }); Handle(command, handler, new MonitorAwareCallback(callback, monitorCallback)); }
private ServerCommand() { M.Apply <Created>(e => { Target = e.Target; Message = e.Message; _state = State.Created; }); M.Apply <Queued>(e => _state = State.Queued); M.Apply <Started>(e => _state = State.Started); M.Apply <Succeeded>(e => _state = State.Succeeded); M.Apply <Failed>(e => _state = State.Failed); }
public override async Task <ICommandMessage> Request(string queueName, ICommandMessage request, CancellationToken cancellationToken) { try { var handle = _commandConsumers.Single(x => x.Key == queueName).Value; return(await((InMemoryCommandService)handle).Consume(request)); } catch (Exception) { throw new ReceiveEndpointNotConnectedException($"{queueName} has no connected ReceiveEndpoint"); } }
public Task Send(ICommandMessage message) { _messages.OnNext(message); return Task.FromResult(true); }
public async Task Send(ICommandMessage message) { var queueClient = QueueClient.CreateFromConnectionString(_connectionString, message.GetType().FullName); await queueClient.SendAsync(BuildBrokeredMessage(message)); }
public Task Send(ICommandMessage message) { return _sender.Send(message); }