public void Send <TCommand>(TCommand command) where TCommand : ICommand <TAuthenticationToken> { ICommandValidator <TAuthenticationToken, TCommand> commandValidator = null; try { commandValidator = DependencyResolver.Resolve <ICommandValidator <TAuthenticationToken, TCommand> >(); } catch (Exception exception) { Logger.LogDebug("Locating an ICommandValidator failed.", string.Format("{0}\\Handle({1})", GetType().FullName, command.GetType().FullName), exception); } if (commandValidator != null && !commandValidator.IsCommandValid(command)) { Logger.LogInfo("The provided command is not valid.", string.Format("{0}\\Handle({1})", GetType().FullName, command.GetType().FullName)); return; } if (command.AuthenticationToken == null) { command.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } command.CorrelationId = CorrelationIdHelper.GetCorrelationId(); ServiceBusPublisher.Send(new BrokeredMessage(MessageSerialiser.SerialiseCommand(command))); Logger.LogInfo(string.Format("A command was sent of type {0}.", command.GetType().FullName)); }
public virtual void Publish <TEvent>(TEvent @event) where TEvent : IEvent <TAuthenticationToken> { Type eventType = @event.GetType(); if (@event.Frameworks != null && @event.Frameworks.Contains("Built-In")) { Logger.LogInfo("The provided event has already been processed by the Built-In bus.", string.Format("{0}\\PrepareAndValidateEvent({1})", GetType().FullName, eventType.FullName)); return; } if (@event.AuthenticationToken == null || @event.AuthenticationToken.Equals(default(TAuthenticationToken))) { @event.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } @event.CorrelationId = CorrelationIdHelper.GetCorrelationId(); if (string.IsNullOrWhiteSpace(@event.OriginatingFramework)) { @event.TimeStamp = DateTimeOffset.UtcNow; @event.OriginatingFramework = "Built-In"; } var frameworks = new List <string>(); if (@event.Frameworks != null) { frameworks.AddRange(@event.Frameworks); } frameworks.Add("Built-In"); @event.Frameworks = frameworks; bool isRequired; if (!ConfigurationManager.TryGetSetting(string.Format("{0}.IsRequired", eventType.FullName), out isRequired)) { isRequired = true; } IEnumerable <Action <IMessage> > handlers = Routes.GetHandlers(@event, isRequired).Select(x => x.Delegate).ToList(); // This check doesn't require an isRequired check as there will be an exception raised above and handled below. if (!handlers.Any()) { Logger.LogDebug(string.Format("An event handler for '{0}' is not required.", eventType.FullName)); } foreach (Action <IMessage> handler in handlers) { IList <IEvent <TAuthenticationToken> > events; if (EventWaits.TryGetValue(@event.CorrelationId, out events)) { events.Add(@event); } handler(@event); } }
protected virtual void PrepareCommand <TCommand>(TCommand command) where TCommand : ICommand <TAuthenticationToken> { if (command.AuthenticationToken == null) { command.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } command.CorrelationId = CorrelationIdHelper.GetCorrelationId(); }
public virtual InvoicesQueryStrategy WithRsn(Guid rsn) { QueryPredicate = And(IsNotLogicallyDeleted()); QueryPredicate = And(WithPermissionScopeUser(AuthenticationTokenHelper.GetAuthenticationToken())); QueryPredicate = And(BuildQueryPredicate(WithRsn, rsn)); OnWithRsn(rsn); return(this); }
public virtual OrderQueryStrategy WithOrderId(int orderId) { QueryPredicate = And(IsNotLogicallyDeleted()); QueryPredicate = And(WithPermissionScopeUser(AuthenticationTokenHelper.GetAuthenticationToken())); QueryPredicate = And(BuildQueryPredicate(WithOrderId, orderId)); OnWithOrderId(orderId); return(this); }
public virtual void Send <TCommand>(TCommand command) where TCommand : ICommand <TAuthenticationToken> { Type commandType = command.GetType(); switch (command.Framework) { case FrameworkType.Akka: Logger.LogInfo(string.Format("A command arrived of the type '{0}' but was marked as coming from the '{1}' framework, so it was dropped.", commandType.FullName, command.Framework)); return; } ICommandValidator <TAuthenticationToken, TCommand> commandValidator = null; try { commandValidator = DependencyResolver.Resolve <ICommandValidator <TAuthenticationToken, TCommand> >(); } catch (Exception exception) { Logger.LogDebug("Locating an ICommandValidator failed.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName), exception); } if (commandValidator != null && !commandValidator.IsCommandValid(command)) { Logger.LogInfo("The provided command is not valid.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName)); return; } if (command.AuthenticationToken == null) { command.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } command.CorrelationId = CorrelationIdHelper.GetCorrelationId(); bool isRequired; if (!ConfigurationManager.TryGetSetting(string.Format("{0}.IsRequired", commandType.FullName), out isRequired)) { isRequired = true; } RouteHandlerDelegate commandHandler = Routes.GetSingleHandler(command, isRequired); // This check doesn't require an isRequired check as there will be an exception raised above and handled below. if (commandHandler == null) { Logger.LogDebug(string.Format("The command handler for '{0}' is not required.", commandType.FullName)); return; } Action <IMessage> handler = commandHandler.Delegate; handler(command); }
public virtual void Publish <TEvent>(TEvent @event) where TEvent : IEvent <TAuthenticationToken> { if (@event.AuthenticationToken == null) { @event.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } @event.CorrelationId = CorrelationIdHelper.GetCorrelationId(); @event.TimeStamp = DateTimeOffset.UtcNow; ServiceBusPublisher.Send(new BrokeredMessage(MessageSerialiser.SerialiseEvent(@event))); Logger.LogInfo(string.Format("An event was published with the id '{0}' was of type {1}.", @event.Id, @event.GetType().FullName)); }
protected virtual void PrepareCommand <TCommand>(TCommand command) where TCommand : ICommand <TAuthenticationToken> { if (command.AuthenticationToken == null) { command.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } command.CorrelationId = CorrelationIdHelper.GetCorrelationId(); if (string.IsNullOrWhiteSpace(command.OriginatingFramework)) { command.OriginatingFramework = "Akka"; } IList <string> frameworks = new List <string>(command.Frameworks); frameworks.Add("Akka"); command.Frameworks = frameworks; }
public virtual void Publish <TEvent>(TEvent @event) where TEvent : IEvent <TAuthenticationToken> { switch (@event.Framework) { case FrameworkType.Akka: Logger.LogInfo(string.Format("An event arrived of the type '{0}' but was marked as coming from the '{1}' framework, so it was dropped.", @event.GetType().FullName, @event.Framework)); return; } if (@event.AuthenticationToken == null) { @event.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } @event.CorrelationId = CorrelationIdHelper.GetCorrelationId(); @event.TimeStamp = DateTimeOffset.UtcNow; Type eventType = @event.GetType(); bool isRequired; if (!ConfigurationManager.TryGetSetting(string.Format("{0}.IsRequired", eventType.FullName), out isRequired)) { isRequired = true; } IEnumerable <Action <IMessage> > handlers = Routes.GetHandlers(@event, isRequired).Select(x => x.Delegate).ToList(); // This check doesn't require an isRequired check as there will be an exception raised above and handled below. if (!handlers.Any()) { Logger.LogDebug(string.Format("The event handler for '{0}' is not required.", eventType.FullName)); } foreach (Action <IMessage> handler in handlers) { IList <IEvent <TAuthenticationToken> > events; if (EventWaits.TryGetValue(@event.CorrelationId, out events)) { events.Add(@event); } handler(@event); } }
public virtual void PrepareCommand <TCommand>(TCommand command, string framework) where TCommand : ICommand <TAuthenticationToken> { if (command.AuthenticationToken == null) { command.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } command.CorrelationId = CorrelationIdHelper.GetCorrelationId(); if (string.IsNullOrWhiteSpace(command.OriginatingFramework)) { command.OriginatingFramework = framework; } var frameworks = new List <string>(); if (command.Frameworks != null) { frameworks.AddRange(command.Frameworks); } frameworks.Add("Azure-EventHub"); command.Frameworks = frameworks; }
public virtual void PrepareEvent <TEvent>(TEvent @event, string framework) where TEvent : IEvent <TAuthenticationToken> { if (@event.AuthenticationToken == null) { @event.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } @event.CorrelationId = CorrelationIdHelper.GetCorrelationId(); @event.TimeStamp = DateTimeOffset.UtcNow; if (string.IsNullOrWhiteSpace(@event.OriginatingFramework)) { @event.OriginatingFramework = framework; } var frameworks = new List <string>(); if (@event.Frameworks != null) { frameworks.AddRange(@event.Frameworks); } frameworks.Add("Azure-EventHub"); @event.Frameworks = frameworks; }
protected virtual void PrepareCommand <TCommand>(TCommand command) where TCommand : ICommand <TAuthenticationToken> { if (command.AuthenticationToken == null || command.AuthenticationToken.Equals(default(TAuthenticationToken))) { command.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } command.CorrelationId = CorrelationIdHelper.GetCorrelationId(); if (string.IsNullOrWhiteSpace(command.OriginatingFramework)) { command.OriginatingFramework = "Built-In"; } var frameworks = new List <string>(); if (command.Frameworks != null) { frameworks.AddRange(command.Frameworks); } frameworks.Add("Built-In"); command.Frameworks = frameworks; }
public virtual void Publish <TEvent>(TEvent @event) where TEvent : IEvent <TAuthenticationToken> { DateTimeOffset startedAt = DateTimeOffset.UtcNow; Stopwatch mainStopWatch = Stopwatch.StartNew(); string responseCode = "200"; bool wasSuccessfull = false; IDictionary <string, string> telemetryProperties = new Dictionary <string, string> { { "Type", "InProcessBus" } }; string telemetryName = string.Format("{0}/{1}", @event.GetType().FullName, @event.Id); var telemeteredEvent = @event as ITelemeteredMessage; if (telemeteredEvent != null) { telemetryName = telemeteredEvent.TelemetryName; } telemetryName = string.Format("Event/{0}", telemetryName); try { Type eventType = @event.GetType(); if (@event.Frameworks != null && @event.Frameworks.Contains("Built-In")) { Logger.LogInfo("The provided event has already been processed by the Built-In bus.", string.Format("{0}\\PrepareAndValidateEvent({1})", GetType().FullName, eventType.FullName)); return; } if (@event.AuthenticationToken == null || @event.AuthenticationToken.Equals(default(TAuthenticationToken))) { @event.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } @event.CorrelationId = CorrelationIdHelper.GetCorrelationId(); if (string.IsNullOrWhiteSpace(@event.OriginatingFramework)) { @event.TimeStamp = DateTimeOffset.UtcNow; @event.OriginatingFramework = "Built-In"; } var frameworks = new List <string>(); if (@event.Frameworks != null) { frameworks.AddRange(@event.Frameworks); } frameworks.Add("Built-In"); @event.Frameworks = frameworks; bool isRequired; if (!ConfigurationManager.TryGetSetting(string.Format("{0}.IsRequired", eventType.FullName), out isRequired)) { isRequired = true; } IEnumerable <Action <IMessage> > handlers = Routes.GetHandlers(@event, isRequired).Select(x => x.Delegate).ToList(); // This check doesn't require an isRequired check as there will be an exception raised above and handled below. if (!handlers.Any()) { Logger.LogDebug(string.Format("An event handler for '{0}' is not required.", eventType.FullName)); } foreach (Action <IMessage> handler in handlers) { IList <IEvent <TAuthenticationToken> > events; if (EventWaits.TryGetValue(@event.CorrelationId, out events)) { events.Add(@event); } handler(@event); } Logger.LogInfo(string.Format("An event was sent of type {0}.", eventType.FullName)); wasSuccessfull = true; } catch (Exception exception) { responseCode = "500"; Logger.LogError("An issue occurred while trying to publish an event.", exception: exception, metaData: new Dictionary <string, object> { { "Event", @event } }); throw; } finally { mainStopWatch.Stop(); TelemetryHelper.TrackDependency("InProcessBus/EventBus", "Event", telemetryName, null, startedAt, mainStopWatch.Elapsed, responseCode, wasSuccessfull, telemetryProperties); } }