public void SendAccountChangedEvent(string source, IAccount account, AccountChangedEventTypeContract eventType, string operationId, AccountBalanceChangeContract balanceChangeContract = null, IAccount previousSnapshot = null, string orderId = null) { var metadata = new AccountChangeMetadata { OrderId = orderId }; if (previousSnapshot != null) { metadata.PreviousAccountSnapshot = _convertService.Convert <IAccount, AccountContract>(previousSnapshot); } CqrsEngine.PublishEvent( new AccountChangedEvent( account.ModificationTimestamp, source, _convertService.Convert <IAccount, AccountContract>(account), eventType, balanceChangeContract, operationId, metadata.ToJson()), _contextNames.AccountsManagement); }
/// <summary> /// OperationId is defined optional just to extend the message pack object - the parameter is still mandatory. /// </summary> public AccountChangedEvent(DateTime changeTimestamp, [NotNull] string source, [NotNull] AccountContract account, AccountChangedEventTypeContract eventType, AccountBalanceChangeContract balanceChange = null, string operationId = null, string activitiesMetadata = null) { if (!Enum.IsDefined(typeof(AccountChangedEventTypeContract), eventType)) { throw new InvalidEnumArgumentException( nameof(eventType), (int)eventType, typeof(AccountChangedEventTypeContract)); } if (changeTimestamp == default(DateTime)) { throw new ArgumentOutOfRangeException(nameof(changeTimestamp)); } Source = source; ChangeTimestamp = changeTimestamp; Account = account ?? throw new ArgumentNullException(nameof(account)); EventType = eventType; ActivitiesMetadata = activitiesMetadata; BalanceChange = balanceChange; OperationId = operationId; }