public async Task PublishInvoiceCreatedToEventGrid(InvoiceCreatedEvent invoiceCreatedEventData) { string TopicEndpoint = "https://invoicecreated.uksouth-1.eventgrid.azure.net/api/events"; //Configuration["AppSettings:TopicEndpoint"]; string TopicKey = "4B7Wi9qpCRyCtaq58iqGNI7POTChFHnFPLbYZPi0y/w="; //Configuration["AppSettings:TopicKey"]; string topicHostname = new Uri(TopicEndpoint).Host; TopicCredentials topicCredentials = new TopicCredentials(TopicKey); EventGridClient client = new EventGridClient(topicCredentials); EventGridEvent eventGridEvent = new EventGridEvent() { Id = Guid.NewGuid().ToString(), EventType = "invoiceCreated", Data = invoiceCreatedEventData, EventTime = DateTime.Now, Subject = "New Door", DataVersion = "2.0" }; List <EventGridEvent> events = new List <EventGridEvent>(); events.Add(eventGridEvent); await client.PublishEventsAsync(topicHostname, events); }
public void Handle(InvoiceCreatedEvent evt) { _logger.LogInformation(GetLogMessage("Invoice Created Event Triggered")); Parallel.Invoke(new List <Action> { () => InvoiceCreatedSendAccountManagerEmail(evt.InvoiceId), () => InvoiceCreatedSendAgencyOwnerEmail(evt.InvoiceId) }.ToArray()); }
public void When(InvoiceCreatedEvent @event) { switch (State) { case AddInvoiceWithItemsProcessState.NotStarted: var createCommand = GetCreateCommand(); AddCommand(createCommand); break; case AddInvoiceWithItemsProcessState.InvoiceCreated: break; default: throw new NotAllowedOperationException(); } }
public async Task ExecuteAsync(HookType type, IDomainEntityContext <Invoice> context, CancellationToken cancellationToken) { switch (context.EditMode) { case EditMode.Create: await context.AddEventAsync(InvoiceCreatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken); break; case EditMode.Update: await context.AddEventAsync(InvoiceUpdatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken); break; case EditMode.Delete: await context.AddEventAsync(InvoiceDeletedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken); break; } }
public Task PublishInvoiceCreatedEvent(Invoice invoice) { var newEvent = new InvoiceCreatedEvent { TotalPrice = invoice.TotalPrice, OrderCode = invoice.OrderCode.ToString(), Created = invoice.Created.ToString(Common.DTOs.Converters.DateTimeConverter.writeFormat, null), Zip = invoice.Zip, City = invoice.City, Street = invoice.Street, CountryCode = invoice.CountryCode, Email = invoice.Email }; var msg = JsonSerializer.Serialize(newEvent, Common.DTOs.JsonSerializationOptions.options); var body = Encoding.UTF8.GetBytes(msg); var factory = new ConnectionFactory() { HostName = rabbimqSettings.Host, UserName = rabbimqSettings.Username, Password = rabbimqSettings.Password }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { var props = channel.CreateBasicProperties(); props.ContentType = "application/json"; props.ContentEncoding = "UTF-8"; props.DeliveryMode = 2; channel.QueueDeclare(queue: rabbimqSettings.InvoiceCreatedQueue, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.BasicPublish(exchange: rabbimqSettings.InvoiceCreatedExchange, routingKey: rabbimqSettings.InvoiceCreatedRoutingkey, basicProperties: props, body: body); } return(Task.CompletedTask); }
public void ProcessMessage(IHandlerContext <CreateInvoiceCommand> context) { // simulate slow processing Thread.Sleep(1000); var message = context.Message; var invoice = new Invoice(message.OrderId) { AccountContact = new InvoiceAccountContact(message.AccountContactName, message.AccountContactEMail) }; foreach (var item in message.Items) { invoice.AddItem(item.Description, item.Price); } invoice.GenerateInvoiceNumber(); using (_databaseContextFactory.Create(InvoicingData.ConnectionStringName)) { _repository.Add(invoice); } var orderCreatedEvent = new InvoiceCreatedEvent { InvoiceId = invoice.Id, InvoiceNumber = invoice.InvoiceNumber, InvoiceDate = invoice.InvoiceDate, AccountContactName = message.AccountContactName, AccountContactEMail = message.AccountContactEMail }; orderCreatedEvent.Items.AddRange(message.Items); context.Publish(orderCreatedEvent); }
public void Apply(InvoiceCreatedEvent aggregateEvent) { InvoiceTitle = aggregateEvent.Title; }
internal void Apply(InvoiceCreatedEvent ev) { Id = ev.AggregateId; CustomerId = ev.CustomerId; }
protected void When(InvoiceCreatedEvent @event) { Id = @event.AggregateRootId; CustomerFullName = @event.CustomerFullName; CustomerAddress = @event.CustomerAddress; }
private void ApplyInvoiceCreated(InvoiceCreatedEvent createdEvent) { InvoiceNumber = createdEvent.InvoiceNumber; _invoiceLines = createdEvent.InvoiceLines.ToList(); _invoiceHistory.Add("Invoice created"); }