/// <summary>
        /// Saves the Audit Entry.
        /// </summary>
        /// <param name="auditEntry">The audit entry.</param>
        /// <returns></returns>
        public static int SaveAuditEntry(MessageAuditEntry auditEntry)
        {
            try
            {
                if (auditEntry.IsValid)
                {
                    // Save entity
                    auditEntry.Id = DataAccessProvider.Instance().SaveAuditEntry(auditEntry);
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(auditEntry);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            return(auditEntry.Id);
        }
Exemplo n.º 2
0
 public void SaveAuditEntryTestConstraint()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         MessageAuditEntry auditEntry = PopulateNewItem();
         SaveItem(auditEntry);
         SaveItem(auditEntry);
     }
 }
Exemplo n.º 3
0
 public void TestSaveAuditEntry()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         MessageAuditEntry auditEntry = PopulateNewItem();
         int Id = SaveItem(auditEntry);
         Assert.IsTrue(Id != -1);
     }
 }
Exemplo n.º 4
0
        public void TestGetAuditEntry()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                MessageAuditEntry auditEntry = PopulateNewItem();
                int Id = SaveItem(auditEntry);

                if (Id != -1)
                {
                    Assert.IsNotNull(GetItem(Id));
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Populates the new item.
        /// </summary>
        /// <returns></returns>
        internal MessageAuditEntry PopulateNewItem()
        {
            MessageAuditEntry auditEntry = new MessageAuditEntry();

            auditEntry.SourceSystem      = "TestSource";
            auditEntry.DestinationSystem = "TestDestination";
            auditEntry.ReceivedDate      = DateTime.Today;
            auditEntry.Message           = "Message";
            auditEntry.Sequence          = 1;
            auditEntry.Type      = "TestType";
            auditEntry.Name      = "TestName";
            auditEntry.Label     = "TestLabel";
            auditEntry.UpdatedBy = "TDC Team";
            return(auditEntry);
        }
Exemplo n.º 6
0
        public void TestUpdateAuditEntry()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                MessageAuditEntry auditEntry = PopulateNewItem();
                auditEntry.SourceSystem = "Original";
                auditEntry.Id           = SaveItem(auditEntry);
                auditEntry = GetItem(auditEntry.Id);
                //change a value
                auditEntry.SourceSystem = "Updated";

                SaveItem(auditEntry);
                auditEntry = GetItem(auditEntry.Id);
                Assert.IsTrue(auditEntry.SourceSystem == "Updated");
            }
        }
Exemplo n.º 7
0
 //[ExpectedException(typeof (ConcurrencyException))]
 public void UpdateAuditEntryConcurrencyTest()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         MessageAuditEntry auditEntry = PopulateNewItem();
         auditEntry.Id = SaveItem(auditEntry);
         //We didn't get the new checksum so when we save again an exception should be thrown
         try
         {
             SaveItem(auditEntry);
         }
         catch (DiscoveryException e)
         {
             Assert.IsInstanceOfType(typeof(ConcurrencyException), e.InnerException);
             throw e;
         }
     }
 }
Exemplo n.º 8
0
        public void TestGetDestinationSystemList()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                MessageAuditEntry auditEntry = PopulateNewItem();
                SaveItem(auditEntry);

                auditEntry.Id                = -1;
                auditEntry.SourceSystem      = "TestSource2";
                auditEntry.DestinationSystem = "TestDestination2";
                auditEntry.ReceivedDate      = DateTime.Today;
                auditEntry.Message           = "Message2";
                auditEntry.Sequence          = 2;
                auditEntry.Type              = "TestType2";
                auditEntry.Name              = "TestName2";
                auditEntry.Label             = "TestLabel2";
                SaveItem(auditEntry);

                Assert.IsTrue(GetDestinationSystemList().Count != 1);
            }
        }
Exemplo n.º 9
0
        public void TestGetAuditEntries()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                MessageAuditEntry auditEntry = PopulateNewItem();
                SaveItem(auditEntry);
                auditEntry.Id                = -1;
                auditEntry.SourceSystem      = "TestSource2";
                auditEntry.DestinationSystem = "TestDestination2";
                auditEntry.ReceivedDate      = DateTime.Today;
                auditEntry.Message           = "Message2";
                auditEntry.Sequence          = 2;
                auditEntry.Type              = "TestType2";
                auditEntry.Name              = "TestName2";
                auditEntry.Label             = "TestLabel2";
                auditEntry.UpdatedBy         = "TDC Team";
                SaveItem(auditEntry);

                List <MessageAuditEntry> auditEntryList = GetAllItems();
                Assert.IsTrue(auditEntryList.Count != 0);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="requestMessage">The request message.</param>
        public override void ProcessRequest(RequestMessage requestMessage)
        {
            try
            {
                // Create a new audit entry
                MessageAuditEntry AuditEntry = new MessageAuditEntry();

                // Seed values
                AuditEntry.Id                = -1;
                AuditEntry.SourceSystem      = requestMessage.SourceSystem;
                AuditEntry.DestinationSystem = requestMessage.DestinationSystem;
                AuditEntry.ReceivedDate      = DateTime.Now;
                AuditEntry.Message           = requestMessage.Body;
                AuditEntry.Sequence          = requestMessage.Sequence;
                AuditEntry.Type              = requestMessage.Type;
                AuditEntry.Name              = requestMessage.Name;
                AuditEntry.Label             = requestMessage.Label;
                AuditEntry.UpdatedBy         = this.GetType().FullName;

                // Save the audit entry to the db
                AuditEntryController.SaveAuditEntry(AuditEntry);

                // Cache the audit entry for later use
                this.RequestProcessor.RequestDictionary["AuditEntry"] = AuditEntry;

                // All done
                Status = SubscriberStatusEnum.Processed;
            }
            catch (Exception ex)
            {
                // Store last error
                LastError = ex;

                // Failed
                Status = SubscriberStatusEnum.Failed;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="requestMessage">The request message.</param>
        public override void ProcessRequest(RequestMessage requestMessage)
        {
            try
            {
                // Get the opco shipment from the request processor
                if (!RequestProcessor.RequestDictionary.ContainsKey("OpCoShipment") ||
                    RequestProcessor.RequestDictionary["OpCoShipment"] == null)
                {
                    // Failed to retrieve the opco shipment from the processor
                    throw new Exception("Attempting to map an Op Co Shipment but it was not found in the Request Processor.  Make sure that the shipment parser has been subscribed before the shipment mapper.");
                }

                // Get the cached opco shipment from the processor
                opCoShipment = (OpCoShipment)RequestProcessor.RequestDictionary["OpCoShipment"];

                // Get the audit entry from the processor if we have one (optional)
                if (RequestProcessor.RequestDictionary.ContainsKey("AuditEntry") &&
                    RequestProcessor.RequestDictionary["AuditEntry"] != null)
                {
                    // Get the cached audit entry from the processor
                    auditEntry = (MessageAuditEntry)RequestProcessor.RequestDictionary["AuditEntry"];
                }

                // *****************************************************************
                // ** SEE IF WE HAVE AN EXISTING OPCO SHIPMENT
                // *****************************************************************

                // See if we already have the shipment in the db
                existingOpCoShipment = OpCoShipmentController.GetShipment(
                    opCoShipment.OpCoCode,
                    opCoShipment.ShipmentNumber,
                    opCoShipment.DespatchNumber);

                // Did we find an existing opco shipment
                if (null != existingOpCoShipment)
                {
                    // We've found the shipment, make sure that our sequence number is later
                    if (existingOpCoShipment.OpCoSequenceNumber >= opCoShipment.OpCoSequenceNumber)
                    {
                        // Consume the message as it's old
                        Status = SubscriberStatusEnum.Processed;

                        // Log that the shipment cannot be updated
                        Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry(
                            string.Format("Unable to update existing opco shipment {0} - {1} for for opco {2}.  The request sequence number is {3} but sequence {4} has already been processed.",
                                          opCoShipment.ShipmentNumber,
                                          opCoShipment.DespatchNumber,
                                          opCoShipment.OpCoCode,
                                          opCoShipment.OpCoSequenceNumber,
                                          existingOpCoShipment.OpCoSequenceNumber),
                            "Request Management",
                            0,
                            0,
                            TraceEventType.Information,
                            "Request Management",
                            null);

                        // Write to the log
                        Logger.Write(logEntry);

                        // done
                        return;
                    }
                    else
                    {
                        // See if we need to update the tdc shipment
                        if (existingOpCoShipment.Status == Shipment.StatusEnum.Mapped)
                        {
                            // *****************************************************************
                            // ** SEE IF WE HAVE AN EXISTING TDC SHIPMENT
                            // *****************************************************************

                            // Get the existing tdc shipment
                            existingTDCShipment = TDCShipmentController.GetShipment(
                                opCoShipment.OpCoCode,
                                opCoShipment.ShipmentNumber,
                                opCoShipment.DespatchNumber);

                            // Did we find an existing tdc shipment?
                            if (null != existingTDCShipment)
                            {
                                // See if the tdc shipment can be updated
                                if (existingTDCShipment.Status != Shipment.StatusEnum.Mapped)
                                {
                                    // Consume the message, we can't make the update
                                    Status = SubscriberStatusEnum.Consumed;

                                    // Log that the shipment cannot be updated
                                    Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry(
                                        string.Format("Unable to update existing tdc shipment {0} - {1} for for opco {2}.  The status of the existing tdc shipment is {3} disallowing this update.",
                                                      existingTDCShipment.ShipmentNumber,
                                                      existingTDCShipment.DespatchNumber,
                                                      existingTDCShipment.OpCoCode,
                                                      existingTDCShipment.Status),
                                        "Request Management",
                                        0,
                                        0,
                                        TraceEventType.Information,
                                        "Request Management",
                                        null);

                                    // Write to the log
                                    Logger.Write(logEntry);

                                    // done
                                    return;
                                }
                            }
                            else
                            {
                                // We should have found the tdc shipment
                                Status = SubscriberStatusEnum.Failed;

                                // Log that the tdc shipment cannot be updated
                                Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry(
                                    string.Concat("Unable to update tdc shipment ", opCoShipment.ShipmentNumber, "-", opCoShipment.DespatchNumber, " for opco ", opCoShipment.OpCoCode, ".  The tdc shipment was not found."),
                                    "Request Management",
                                    0,
                                    0,
                                    TraceEventType.Error,
                                    "Request Management",
                                    null);

                                // Write to the log
                                Logger.Write(logEntry);

                                // done
                                return;
                            }
                        }
                    }
                }

                // *****************************************************************
                // ** SAVE OR UPDATE THE OPCO SHIPMENT
                // *****************************************************************

                // See if we have an existing opco shipment
                if (null != existingOpCoShipment)
                {
                    // Update existing opco shipment
                    opCoShipment = (OpCoShipment)existingOpCoShipment.UpdateFromShipment(opCoShipment);
                }

                // Specify that the shipment was updated by this subscriber
                opCoShipment.UpdatedBy = this.GetType().FullName;

                // See if the shipment has been cancelled
                if (0 == opCoShipment.TotalLineQuantity)
                {
                    // Cancel the shipment
                    opCoShipment.Status = Shipment.StatusEnum.Cancelled;
                }
                else if (opCoShipment.OpCoHeld)
                {
                    // Hold the shipment
                    opCoShipment.Status = Shipment.StatusEnum.Held;
                }

                // See if we have an audit entry (not required)
                if (null != auditEntry)
                {
                    // Store the audit entry id
                    opCoShipment.AuditId = auditEntry.Id;
                }

                // Save the opco shipment to the db
                if (-1 != OpCoShipmentController.SaveShipment(opCoShipment))
                {
                    // Cache the opco shipment for other subscribers
                    RequestProcessor.RequestDictionary["OpCoShipment"] = opCoShipment;

                    // *****************************************************************
                    // ** MAP AND SAVE THE TDC SHIPMENT
                    // *****************************************************************

                    // We only create the TDC Shipment if the OpCo Shipment has not been cancelled
                    // If it has been cancelled and we have an existing TDC Shipment we still update it
                    if (opCoShipment.Status != Shipment.StatusEnum.Cancelled || null != existingTDCShipment)
                    {
                        try
                        {
                            // Map the opco shipment to a new tdc shipment
                            tdcShipment = opCoShipment.MapToTDC(existingTDCShipment, this.GetType().FullName, true);

                            // Store the tdc shipment for other subscribers
                            RequestProcessor.RequestDictionary["TDCShipment"] = tdcShipment;
                        }
                        catch (Exception ex)
                        {
                            // Log that the shipment cannot be updated
                            Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry(
                                string.Format("The opco shipment {0} - {1} for opco {2} has a status of NOTMAPPED.  The error was {3}", opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber, opCoShipment.OpCoCode, ex.Message),
                                "Request Management",
                                0,
                                0,
                                TraceEventType.Error,
                                "Request Management",
                                null);

                            // Write to the log
                            Logger.Write(logEntry);
                        }
                    }

                    // Processed
                    Status = SubscriberStatusEnum.Processed;
                }
                else
                {
                    // We failed to save the op co shipment
                }
            }
            catch (Exception ex)
            {
                // Store the exception
                LastError = ex;

                // Failed
                Status = SubscriberStatusEnum.Failed;
            }
            finally
            {
                // Cleanup
                existingOpCoShipment = null;
                existingTDCShipment  = null;
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Saves the item.
 /// </summary>
 /// <param name="auditEntry">The audit entry.</param>
 /// <returns></returns>
 internal int SaveItem(MessageAuditEntry auditEntry)
 {
     return(AuditEntryController.SaveAuditEntry(auditEntry));
 }