public void SubmitChanges(CreditNote document, BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); CreateCommand createCommand= commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); // _commandRouter.RouteDocumentCommand(createCommand); List<AfterCreateCommand> lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>().ToList(); foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); //_commandRouter.RouteDocumentCommand(item); } ConfirmCreditNoteCommand confirmCreditNoteCommand = commandsToExecute.OfType<ConfirmCreditNoteCommand>().FirstOrDefault(); if (confirmCreditNoteCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCreditNoteCommand)); // _commandRouter.RouteDocumentCommand(confirmCreditNoteCommand); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); }
public void SubmitChanges(CommodityPurchaseNote document) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); CreateCommand createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); //_commandRouter.RouteDocumentCommand(createCommand); List<AfterCreateCommand> lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>().ToList(); foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); // _commandRouter.RouteDocumentCommand(item); } ConfirmCommodityPurchaseCommand confirmCommand = commandsToExecute.OfType<ConfirmCommodityPurchaseCommand>().FirstOrDefault(); if (confirmCommand != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommand)); // _commandRouter.RouteDocumentCommand(confirmCommand); //_notifyService.SubmitCommodityPurchase(document); } _commandEnvelopeRouter.RouteCommandEnvelope(envelope); _auditLogWFManager.AuditLogEntry("Commodity Purchase", "Created and confirmed commodity purchase note " + document.DocumentReference + "; id " + document.Id + " with " + document.LineItems.Count + " line items"); }
public void Submit(InventoryAdjustmentNote note) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(note); List<DocumentCommand> commandsToExecute = note.GetDocumentCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().First(); if (createCommand != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); } var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } var co = commandsToExecute.OfType<ConfirmCommand>().First(); if (co != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); } AddToMongoDB(envelope); }
public void RouteCommandEnvelope(CommandEnvelope envelope) { _log.InfoFormat("RouteCommandEnvelope -- DocumentId {0} -- commandid {1} -- documentid {1} -- ", envelope.DocumentTypeId, envelope.Id, envelope.DocumentId); if (_envelopeQueueRepository.GetByEnvelopeId(envelope.Id) != null) return; var queueItem = new OutGoingCommandEnvelopeQueueItemLocal() { DocumentId = envelope.DocumentId, DocumentType = (DocumentType) envelope.DocumentTypeId, DateInserted = DateTime.Now, IsEnvelopeSent = false, DateSent = DateTime.Now, JsonEnvelope = JsonConvert.SerializeObject(envelope, new IsoDateTimeConverter()), EnvelopeId = envelope.Id, }; _envelopeQueueRepository.Add(queueItem); if (!envelope.IsSystemEnvelope) { foreach (var commandEnvelopeItem in envelope.CommandsList) { CommandType commandType = _resolveCommand.Get(commandEnvelopeItem.Command).CommandType; _executeCommandLocally.ExecuteCommand(commandType, commandEnvelopeItem.Command); } } }
public void SubmitChanges(CommodityTransferNote document) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); var commandsToExecute = document.GetDocumentCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>().ToList(); foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); } var confirmCommodityDeliveryCommand = commandsToExecute.OfType<ConfirmCommodityTransferCommand>().FirstOrDefault(); if (confirmCommodityDeliveryCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommodityDeliveryCommand)); var approveCommodityTransferCommand = commandsToExecute.OfType<ApproveCommodityTransferCommand>().FirstOrDefault(); if (approveCommodityTransferCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, approveCommodityTransferCommand)); var transferedCommodityStorageCommand = commandsToExecute.OfType<TransferedCommodityStorageLineItemCommand>().FirstOrDefault(); if (transferedCommodityStorageCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, transferedCommodityStorageCommand)); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); }
public void SubmitChanges(InventoryAdjustmentNote document, BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); envelope.OtherRecipientCostCentreList.Add(Guid.NewGuid()); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().First(); // _commandRouter.RouteDocumentCommand(createCommand); envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence,createCommand)); _auditLogWFManager.AuditLogEntry("Inventory Adjustment", string.Format("Created IAN document: {0};", document.Id)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { var item = _item as AddInventoryAdjustmentNoteLineItemCommand; envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); _auditLogWFManager.AuditLogEntry("Inventory Adjustment", string.Format("Adjusted Product: {1}; quantity from: {2}; to: {3}; for IAN document: {0};", document.Id, item.ProductId, item.Actual, item.Actual)); } var co = commandsToExecute.OfType<ConfirmCommand>().First(); envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); _auditLogWFManager.AuditLogEntry("Inventory Adjustment", string.Format("Confirmed IAN document: {0};", document.Id)); }
public void AddCommandEnvelopeRouteCentre(CommandEnvelope envelope) { //add recepient List<Guid> centreList = new List<Guid>(); centreList.Add(envelope.RecipientCostCentreId); centreList.Add(envelope.GeneratedByCostCentreId); if (envelope.OtherRecipientCostCentreList != null && envelope.OtherRecipientCostCentreList.Count > 0) { envelope.OtherRecipientCostCentreList.ForEach(centreList.Add); } foreach (var centreId in centreList.Distinct().ToList()) { _commandEnvelopeRouteOnRequestCostcentreCollection.Save( new CommandEnvelopeRouteOnRequestCostcentre { CostCentreId = centreId, DocumentType = ((DocumentType)envelope.DocumentTypeId).ToString(), DateAdded = DateTime.Now, EnvelopeId = envelope.Id, IsRetired = false, IsValid = true, Id = Guid.NewGuid(), EnvelopeArrivalAtServerTick = envelope.EnvelopeArrivedAtServerTick, EnvelopeRoutePriority = EnvelopeRoutePriority.Level1, EnvelopeRoutedAtServerTick = DateTime.Now.Ticks, GeneratedByCostCentreApplicationId = envelope.GeneratedByCostCentreApplicationId, DocumentId = envelope.DocumentId, ParentDocumentId = envelope.ParentDocumentId }); } }
public void SubmitChanges(InventoryTransferNote document, BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().First(); envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); //_commandRouter.RouteDocumentCommand(createCommand); _auditLogWFManager.AuditLogEntry("Inventory Transfer", string.Format("Created Inventory Transfer: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { var item = _item as AddInventoryTransferNoteLineItemCommand; envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); // _commandRouter.RouteDocumentCommand(_item); _auditLogWFManager.AuditLogEntry("Inventory Transfer", string.Format("Transferred Product: {0}; Quantity: {1}; for Inventory Transfer: {2};", item.ProductId, item.Qty, document.Id)); } var co = commandsToExecute.OfType<ConfirmCommand>().First(); envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); //_commandRouter.RouteDocumentCommand(co); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); _auditLogWFManager.AuditLogEntry("Inventory Transfer", string.Format("Confirmed Inventory Transfer: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name)); }
public void SubmitChanges(PaymentNote document, BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); _auditLogWFManager.AuditLogEntry("PaymentNote", string.Format("Created PaymentNote: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault(); if (co != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); _auditLogWFManager.AuditLogEntry("PaymentNote", string.Format("Confirmed PaymentNote: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name)); }
//This should always be called as part of a wider database transaction public void RouteCommandEnvelope(CommandEnvelope envelope) { var json = JsonConvert.SerializeObject(envelope, Formatting.Indented); var commandEnvelope = new LocalCommandEnvelope { Id = Guid.NewGuid(), ParentDoucmentGuid = envelope.ParentDocumentId, DocumentType = (DocumentType) envelope.DocumentTypeId, Contents = json, RoutingStatus = RoutingStatus.Pending, ProcessingOrder = OrderFor(envelope.DocumentTypeId), RoutingDirection = RoutingDirection.Outgoing }; localCommandEnvelopeRepository.Save(commandEnvelope); }
public bool IsSatisfied(CommandEnvelope envelope, int index) { Assert.AreEqual((int)TypeOfDocumentToCheck, envelope.DocumentTypeId, "Document type at index {0}", index); var actualCommands = envelope.CommandsList; for (var i =0; i < CommandTypesToCheck.Length; i++) { var expectedCommandType = CommandTypesToCheck[i].ToString(); var actualType = actualCommands[i].Command.CommandTypeRef; Console.WriteLine(actualType); Assert.AreEqual(expectedCommandType, actualType, "Command Type"); } return true; }
public void Submit(MainOrder order) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(order); List<DocumentCommand> commandsToExecute = order.GetSubOrderCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } var editlineItemCommands = commandsToExecute.OfType<ChangeMainOrderLineItemCommand>(); foreach (var _editeditem in editlineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _editeditem)); } var removedLineitem = commandsToExecute.OfType<RemoveMainOrderLineItemCommand>(); foreach (var _removeditem in removedLineitem) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _removeditem)); } var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault(); if (co != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); var rco = commandsToExecute.OfType<RejectMainOrderCommand>().FirstOrDefault(); if (rco != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, rco)); var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>(); foreach (var _item in approvedlineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } var aop = commandsToExecute.OfType<ApproveCommand>().FirstOrDefault(); if (aop != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, aop)); var closecommand = commandsToExecute.OfType<CloseOrderCommand>().FirstOrDefault(); if (closecommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, closecommand)); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); }
public void SubmitChanges(Domain.Transactional.DocumentEntities.Invoice document, BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); CreateCommand createCommand; //= commandsToExecute.OfType<CreateCommand>().First(); if (TryGetCreateCommand(commandsToExecute, out createCommand)) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); //_commandRouter.RouteDocumentCommand(createCommand); _auditLogWFManager.AuditLogEntry("Invoice", string.Format("Created Invoice: {0}; for Order: {1}", document.Id, document.OrderId)); } List<AfterCreateCommand> lineItemCommands; if (TryGetAfterCreateCommands(commandsToExecute, out lineItemCommands)) { foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); // _commandRouter.RouteDocumentCommand(item); var _item = item as AddInvoiceLineItemCommand; _auditLogWFManager.AuditLogEntry("Invoice", string.Format( "Added Product: {0}; Quantity: {1}; for Invoice: {2};", _item.ProductId, _item.Qty, document.Id)); } } ConfirmCommand confirmCommand; if (TryGetConfirmCommand(commandsToExecute, out confirmCommand)) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommand)); // _commandRouter.RouteDocumentCommand(confirmCommand); //send notification // _notifyService.SubmitInvoiceNotification(document); _auditLogWFManager.AuditLogEntry("Invoice", string.Format("Confirmed Invoice: {0}; for Order: {1}", document.Id, document.OrderId)); } _commandEnvelopeRouter.RouteCommandEnvelope(envelope); document.CallClearCommands(); }
public void SubmitChanges(Receipt document,BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); CreateCommand createCommand; //= commandsToExecute.OfType<CreateCommand>().First(); if (TryGetCreateCommand(commandsToExecute, out createCommand)) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); // _commandRouter.RouteDocumentCommand(createCommand); _auditLogWFManager.AuditLogEntry("Receipt", string.Format("Created Receipt: {0}; for invoice: {1}", document.Id, document.InvoiceId)); } List<AfterCreateCommand> lineItemCommands; if (TryGetAfterCreateCommands(commandsToExecute, out lineItemCommands)) { foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); // _commandRouter.RouteDocumentCommand(item); var _item = item as AddReceiptLineItemCommand; _auditLogWFManager.AuditLogEntry("Receipt", string.Format( "Added Product type: {0}; Quantity: {1}; for Invoice: {2};", _item.LineItemType, _item.Value, document.InvoiceId)); } } ConfirmCommand confirmCommand; if (TryGetConfirmCommand(commandsToExecute, out confirmCommand)) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommand)); // _commandRouter.RouteDocumentCommand(confirmCommand); _auditLogWFManager.AuditLogEntry("Receipt", string.Format("Confirmed Receipt: {0}; for Invoice: {1}", document.Id, document.InvoiceId)); // _notifyService.SubmitRecieptNotification(document); } _commandEnvelopeRouter.RouteCommandEnvelope(envelope); document.CallClearCommands(); }
public void SubmitChanges(CommodityWarehouseStorageNote document) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); CreateCommand createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); List<AfterCreateCommand> lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>().ToList(); foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); } List<AfterConfirmCommand> lineItemConfirmCommands = commandsToExecute.OfType<AfterConfirmCommand>().ToList(); foreach (var item in lineItemConfirmCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); } ConfirmCommodityWarehouseStorageCommand confirmCommodityWarehouseStorageCommand = commandsToExecute.OfType<ConfirmCommodityWarehouseStorageCommand>().FirstOrDefault(); if (confirmCommodityWarehouseStorageCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommodityWarehouseStorageCommand)); ApproveCommodityWarehouseStorageCommand approveCommand = commandsToExecute.OfType<ApproveCommodityWarehouseStorageCommand>().FirstOrDefault(); if (approveCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, approveCommand)); StoreCommodityWarehouseStorageCommand storeCommand = commandsToExecute.OfType<StoreCommodityWarehouseStorageCommand>().FirstOrDefault(); if (storeCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, storeCommand)); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); }
public void SubmitChanges(DispatchNote document, BasicConfig config) { //document.Confirm(); int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); CreateCommand createCommand; if (TryGetCreateCommand(commandsToExecute, out createCommand)) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); // _commandRouter.RouteDocumentCommand(createCommand); _auditLogWFManager.AuditLogEntry("Dispatch Note", string.Format("Dispatch Note Document No: {0}; to: {1}; Created", document.Id, document.DocumentRecipientCostCentre.Name)); } List<AfterCreateCommand> lineItemCommands; if (TryGetAfterCreateCommands(commandsToExecute, out lineItemCommands)) { foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); //_commandRouter.RouteDocumentCommand(item); var _item = item as AddDispatchNoteLineItemCommand; _auditLogWFManager.AuditLogEntry("Dispatch Note", string.Format("Added Product: {1}; Quantity: {2}; Value: {3}; to Dispatch Note document: {0}", document.Id, item.Description, _item.Qty, _item.Value)); } } ConfirmCommand confirmCommand; if (TryGetConfirmCommand(commandsToExecute, out confirmCommand)) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommand)); //_commandRouter.RouteDocumentCommand(confirmCommand); _auditLogWFManager.AuditLogEntry("Dispatch Note", string.Format("Confirmed Dispatch Note document: {0}", document.Id)); // _notifyService.SubmitDispatch(document); } _commandEnvelopeRouter.RouteCommandEnvelope(envelope); document.CallClearCommands(); }
public void SubmitChanges(ReCollection document) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Id = Guid.NewGuid(); envelope.EnvelopeGeneratedTick = DateTime.Now.Ticks; envelope.GeneratedByCostCentreId = document.CostCentreId; envelope.RecipientCostCentreId = document.RecepientCostCentreId; envelope.DocumentTypeId = (int)DocumentType.RecollectionNote; envelope.GeneratedByCostCentreApplicationId = document.CostCentreApplicationId; envelope.ParentDocumentId = document.Id; envelope.DocumentId = document.Id; List<DocumentCommand> commandsToExecute = document.GetRecollectionCommandsToExecute(); var lineItemCommands = commandsToExecute.OfType<ReCollectionCommand>(); foreach (var _item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } _commandEnvelopeRouter.RouteCommandEnvelope(envelope); }
public void SubmitChanges(CommodityDeliveryNote document) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(document); List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute(); CreateCommand createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); // _commandRouter.RouteDocumentCommand(createCommand); List<AfterCreateCommand> lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>().ToList(); foreach (var item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); //_commandRouter.RouteDocumentCommand(item); } List<WeighedCommodityDeliveryLineItemCommand> weighed = commandsToExecute.OfType<WeighedCommodityDeliveryLineItemCommand>().ToList(); foreach (var item in weighed) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item)); // _commandRouter.RouteDocumentCommand(item); } ConfirmCommodityDeliveryCommand confirmCommodityDeliveryCommand = commandsToExecute.OfType<ConfirmCommodityDeliveryCommand>().FirstOrDefault(); if (confirmCommodityDeliveryCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommodityDeliveryCommand)); // _commandRouter.RouteDocumentCommand(confirmCommodityDeliveryCommand); ApproveDeliveryCommand receivedDeliveryCommand = commandsToExecute.OfType<ApproveDeliveryCommand>().FirstOrDefault(); if (receivedDeliveryCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, receivedDeliveryCommand)); //_commandRouter.RouteDocumentCommand(receivedDeliveryCommand); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); }
private void AddToMongoDB(CommandEnvelope envelope) { envelope.EnvelopeArrivedAtServerTick = DateTime.Now.Ticks; var envelopeProcessingAudit = new CommandEnvelopeProcessingAudit { GeneratedByCostCentreApplicationId =Guid.Empty, DateInserted = DateTime.Now, Id = envelope.Id, JsonEnvelope = JsonConvert.SerializeObject(envelope), RetryCounter = 0, Status = EnvelopeProcessingStatus.OnQueue, DocumentId = envelope.DocumentId, ParentDocumentId = envelope.ParentDocumentId, DocumentType = (DocumentType)envelope.DocumentTypeId, EnvelopeGeneratedTick = envelope.EnvelopeGeneratedTick, EnvelopeArrivalAtServerTick = DateTime.Now.Ticks, EnvelopeProcessOnServerTick = 0, GeneratedByCostCentreId = envelope.GeneratedByCostCentreId, RecipientCostCentreId = envelope.RecipientCostCentreId, LastExecutedCommand = 0, NumberOfCommand = envelope.CommandsList.Count }; envelopeProcessingAudit.DocumentTypeName = envelopeProcessingAudit.DocumentType.ToString(); _commandEnvelopeProcessingAuditRepository.AddCommand(envelopeProcessingAudit); var message = new EnvelopeBusMessage { DocumentTypeId = envelope.DocumentTypeId, MessageId = envelope.Id, BodyJson = JsonConvert.SerializeObject(envelope), SendDateTime = DateTime.Now.ToString(), }; _busPublisher.Publish(message); }
public void SubmitChanges(InventoryReceivedNote irn,BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(irn); List<DocumentCommand> commandsToExecute = irn.GetDocumentCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().First(); envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); _auditLogWFManager.AuditLogEntry("Receive Inventory", string.Format("Created Goods Received Note: {0}; for Purchase Orders: {1}", irn.Id, irn.OrderReferences)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var li in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, li)); AddInventoryReceivedNoteLineItemCommand c = li as AddInventoryReceivedNoteLineItemCommand; _auditLogWFManager.AuditLogEntry("Receive Inventory", string.Format("Received Product: {0}; Quantity: {1}; for Goods Received Note: {2};", c.ProductId, c.Qty, irn.Id)); } var co = commandsToExecute.OfType<ConfirmCommand>().First(); envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); _auditLogWFManager.AuditLogEntry("Receive Inventory", string.Format("Confirmed Goods Received Note: {0}; for Purchase Orders: {1}", irn.Id, irn.OrderReferences)); }
public void Submit(MainOrder order) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.GeneratedByCostCentreApplicationId = Guid.Empty; envelope.Initialize(order); List<DocumentCommand> commandsToExecute = order.GetSubOrderCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); //AddToMongoDB(createCommand); } var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); //AddToMongoDB(_item); //_busPublisher.WrapAndPublish(_item, (CommandType)Enum.Parse(typeof(CommandType), _item.CommandTypeRef)); } var editlineItemCommands = commandsToExecute.OfType<ChangeMainOrderLineItemCommand>(); foreach (var _editeditem in editlineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _editeditem)); } var removedLineitem = commandsToExecute.OfType<RemoveMainOrderLineItemCommand>(); foreach (var _removeditem in removedLineitem) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _removeditem)); } var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault(); if (co != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); } var rco = commandsToExecute.OfType<RejectMainOrderCommand>().FirstOrDefault(); if (rco != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, rco)); } var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>(); foreach (var _item in approvedlineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } var aop = commandsToExecute.OfType<ApproveCommand>().FirstOrDefault(); if (aop != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, aop)); } AddToMongoDB(envelope); }
public async Task<bool> SendCommandEnvelope(CommandEnvelope envelope) { bool success = false; string urlSuffix = "api/commandenvelope/run"; HttpClient client = setupClient(); _log.InfoFormat("Attempting to post Envelope with id {0} to {1}", envelope.Id, client.BaseAddress + urlSuffix); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { //var response = client.PostAsJsonAsync(urlSuffix, command).Result; var response = await client.PostAsJsonAsync(urlSuffix, envelope); response.EnsureSuccessStatusCode(); ResponseBasic _response = await response.Content.ReadAsAsync<ResponseBasic>(); if (_response == null) { _log.InfoFormat("Sent Envelope id {0} Failed", envelope.Id); return success; } if (_response.Result.Equals("Envelope Processed") && response.IsSuccessStatusCode) { _log.InfoFormat("Sent Envelope id {0} success", envelope.Id); success = true; } else { _log.InfoFormat("Sent Envelope id {0} Failed, ResultInfo= {1}, ErrorInfo= {2} ", envelope.Id, _response.ResultInfo, _response.ErrorInfo); } } catch (Exception ex) { _log.ErrorFormat("Failed to send Envelope {0}", envelope.Id); _log.Error("Failed to send Envelope", ex); throw ex; } return success; }
private async Task ProcessDispatch(OrderDispatchItemSummary item) { await Task.Run(() => { using(var c = NestedContainer) { var mainOrderRepository = Using<IMainOrderRepository>(c); var mainOrderworkflow = Using<IOrderWorkflow>(c); MainOrder order = mainOrderRepository.GetById(item.OrderId); Config config = Using<IConfigService>(c).Load(); Guid costCentreApplicationid = config.CostCentreApplicationId; order.ChangeccId(costCentreApplicationid); if(item.ChangeToSalesman!=null) { var envelope = new CommandEnvelope(); envelope.DocumentId = order.Id; envelope.RecipientCostCentreId = item.ChangeToSalesman.Id; envelope.DocumentTypeId = (int) DocumentType.Order; envelope.EnvelopeGeneratedTick = DateTime.Now.Ticks; envelope.GeneratedByCostCentreId = config.CostCentreId; envelope.Id = Guid.NewGuid(); envelope.ParentDocumentId = order.Id; envelope.IsSystemEnvelope = true; var commandEnvelopeRouter = Using< IOutgoingCommandEnvelopeRouter >(c); order.ChangeSaleman(item.ChangeToSalesman); ReRouteDocumentCommand cmd = new ReRouteDocumentCommand(); cmd.CommandGeneratedByCostCentreApplicationId = config.CostCentreApplicationId; cmd.CommandId = Guid.NewGuid(); cmd.DocumentId = order.Id; cmd.ReciepientCostCentreId = item.ChangeToSalesman.Id; envelope.CommandsList.Add(new CommandEnvelopeItem(1, cmd)); commandEnvelopeRouter.RouteCommandEnvelope(envelope); } order.DispatchPendingLineItems(); mainOrderworkflow.Submit(order,config); } } ).ConfigureAwait(false); //t.Wait(); // return t; }
public void HandleCommandEnvelope( CommandEnvelope envelope) { try { var envelopeToSave = new InComingCommandEnvelopeQueueItemLocal { EnvelopeId = envelope.Id, DocumentType =(DocumentType) envelope.DocumentTypeId, DateInserted = DateTime.Now, DocumentId = envelope.DocumentId, Processed = false, JsonEnvelope = JsonConvert.SerializeObject(envelope), NoOfRetry = 0, Info = "" }; _incomingCommandEnvelopeQueueRepository.Add(envelopeToSave); foreach (var cmdItem in envelope.CommandsList.OrderBy(s => s.Order)) { var cmd = cmdItem.Command; ResolveCommandItem rc = _resolveCommand.Get(cmd); _executeCommandLocally.ExecuteCommand(rc.CommandType, cmd); // _auditLogWFManager.AuditLogEntry("HandleCommand", string.Format("Command {0} Successfully Executed. Command Type {1} ", commandRouteItemId, commandType)); // } _incomingCommandEnvelopeQueueRepository.MarkAsProcessed(envelope.Id); if (_incomingCommandEnvelopeQueueRepository.GetByEnvelopeId(envelope.Id) != null) { _configRepository.AddDeliveredCommandEnvelopeId(envelope.Id); } } catch (Exception ex) { } }
CommandEnvelope CommandsToEnvelope(Guid envelopeId, Guid documentId, DocumentType documentType, long generatedTick, Guid parentId, Guid? recipientCCId, DocumentCommand[] commands) { DocumentCommand refC = commands.First(); List<CommandEnvelopeItem> cei = commands.Select((n, i) => new CommandEnvelopeItem(i + 1, n)).ToList(); var ce = new CommandEnvelope { Id = envelopeId, DocumentId = documentId, DocumentTypeId = (int)documentType, GeneratedByCostCentreId = refC.CommandGeneratedByCostCentreId, RecipientCostCentreId = recipientCCId ?? Guid.Empty, GeneratedByCostCentreApplicationId = refC.CommandGeneratedByCostCentreApplicationId, ParentDocumentId = parentId, CommandsList = cei, EnvelopeGeneratedTick = generatedTick, EnvelopeArrivedAtServerTick = generatedTick }; return ce; }
public void Submit(MainOrder order,BasicConfig config) { int sequence = 0; var envelope = new CommandEnvelope(); envelope.Initialize(order); List<DocumentCommand> commandsToExecute = order.GetSubOrderCommandsToExecute(); var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault(); if (createCommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand)); var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>(); foreach (var _item in lineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); // _commandRouter.RouteDocumentCommand(_item); } var editlineItemCommands = commandsToExecute.OfType<ChangeMainOrderLineItemCommand>(); foreach (var _editeditem in editlineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _editeditem)); //_commandRouter.RouteDocumentCommand(_editeditem); } var removedLineitem = commandsToExecute.OfType<RemoveMainOrderLineItemCommand>(); foreach (var _removeditem in removedLineitem) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _removeditem)); } var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault(); if (co != null) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co)); //_commandRouter.RouteDocumentCommand(co); _notifyService.SubmitOrderSaleNotification(order); } var rco = commandsToExecute.OfType<RejectMainOrderCommand>().FirstOrDefault(); if (rco != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, rco)); //adjust inventory from distributor Guid invoiceId; var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>(); foreach (var _item in approvedlineItemCommands) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item)); } HandleApprovedCommand(order,config,out invoiceId); var aop = commandsToExecute.OfType<ApproveCommand>().FirstOrDefault(); if (aop != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, aop)); var closecommand = commandsToExecute.OfType<CloseOrderCommand>().FirstOrDefault(); if (closecommand != null) envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, closecommand)); var orderpaymentInfoitem = order.GetSubOrderCommandsToExecute().OfType<AddOrderPaymentInfoCommand>(); foreach (var paymentInfo in orderpaymentInfoitem) { envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, paymentInfo)); } HandlePayments(order,invoiceId, config); _commandEnvelopeRouter.RouteCommandEnvelope(envelope); }
public void RouteCommandEnvelope(CommandEnvelope envelope) { var json = JsonConvert.SerializeObject(envelope); }
public void RouteCommandEnvelope(CommandEnvelope envelope) { throw new NotImplementedException(); }
public static void CheckDocumentCommandReferences(List<DocumentCommand> documentCommands, CommandEnvelope commandEnvelope, IEnvelopeContext context) { documentCommands.ForEach(c => { Assert.AreEqual(commandEnvelope.ParentDocumentId, c.PDCommandId, "PDCommandId in command {0}", c.CommandTypeRef); Assert.AreEqual(commandEnvelope.DocumentId, c.DocumentId, "DocumentId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByUserId, c.CommandGeneratedByUserId, "GeneratedByUserId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByCostCentreId, c.CommandGeneratedByCostCentreId, "CommandGeneratedByCostCentreId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByCostCentreApplicationId, c.CommandGeneratedByCostCentreApplicationId, "CommandGeneratedByCostCentreApplicationId in command {0}", c.CommandTypeRef); var createCommand = c as CreateCommand; if (createCommand != null) { Assert.AreEqual(context.GeneratedByCostCentreId, createCommand.DocumentIssuerCostCentreId, "DocumentIssuerCostCentreId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByUserId, createCommand.DocIssuerUserId, "DocIssuerUserId in command {0}", c.CommandTypeRef); } }); }
private void RouteDocumentExternalRef(Guid documentId, Guid generatedByCostCentreId, Guid recipientCostCentreId, CommandEnvelopeItem envelopeItem) { _documentHelper.GetExternalRef(envelopeItem.Command); var command = GetExternalCommnandRef(envelopeItem.Command); if (command != null) { var env = new CommandEnvelope(); env.Id = Guid.NewGuid(); env.EnvelopeGeneratedTick = DateTime.Now.Ticks; env.GeneratedByCostCentreId = generatedByCostCentreId; env.RecipientCostCentreId = recipientCostCentreId; env.DocumentTypeId = (int)DocumentType.Order; env.GeneratedByCostCentreApplicationId = Guid.Empty; env.ParentDocumentId = documentId; env.DocumentId = documentId; env.CommandsList.Add(new CommandEnvelopeItem(1, command)); env.EnvelopeArrivedAtServerTick = DateTime.Now.Ticks; var audit = new CommandEnvelopeProcessingAudit { GeneratedByCostCentreApplicationId = env.GeneratedByCostCentreApplicationId, DateInserted = DateTime.Now, Id = env.Id, JsonEnvelope = JsonConvert.SerializeObject(env), RetryCounter = 0, Status = EnvelopeProcessingStatus.OnQueue, DocumentId = env.DocumentId, ParentDocumentId = env.ParentDocumentId, DocumentType = (DocumentType)env.DocumentTypeId, EnvelopeGeneratedTick = env.EnvelopeGeneratedTick, EnvelopeArrivalAtServerTick = DateTime.Now.Ticks, EnvelopeProcessOnServerTick = 0, GeneratedByCostCentreId = env.GeneratedByCostCentreId, RecipientCostCentreId = env.RecipientCostCentreId, LastExecutedCommand = 1, NumberOfCommand = env.CommandsList.Count, }; audit.EnvelopeArrivalAtServerTick = DateTime.Now.Ticks; audit.DocumentTypeName = audit.DocumentType.ToString(); _runCommandOnRequestInHostedEnvironment.RunCommandInHostedenvironment(command); _envelopeProcessingAuditRepository.AddCommand(audit); _commandEnvelopeRouteOn.AddCommandEnvelopeRouteCentre(env); } }