/// <summary>
        /// Headers the record found.
        /// </summary>
        /// <param name="currentLineNumber">The current line number.</param>
        /// <param name="textFields">The text fields.</param>
        /// <param name="lineText">The line text.</param>
        void HeaderRecordFound(ref int currentLineNumber, TextFieldCollection textFields, string lineText)
        {
            // A matching header has been found, we need to create an instance of the opco shipment
            opcoShipment = new OpCoShipment();

            // Fill the opco shipment using the parsed header
            TextFieldParser.FillObject(opcoShipment, textFields);

            int Hrs, Mins;

            string[] HHMMSS;

            // We need manual conversion here for CheckInTimeHHMMSS as passed on interface in some ridiculous format
            HHMMSS = textFields["CheckInTimeHHMMSS"].Value.ToString().Split(':');
            Hrs    = Convert.ToInt32(HHMMSS[0]);
            Mins   = Convert.ToInt32(HHMMSS[1]);
            opcoShipment.CheckInTime = (Hrs * 60) + Mins;

            // We need manual conversion here for the current time, we need to add it to the generated date
            HHMMSS = textFields["GeneratedTimeHHMMSS"].Value.ToString().Split(':');
            opcoShipment.GeneratedDateTime = opcoShipment.GeneratedDateTime.AddHours(Convert.ToInt32(HHMMSS[0]));
            opcoShipment.GeneratedDateTime = opcoShipment.GeneratedDateTime.AddMinutes(Convert.ToInt32(HHMMSS[1]));
            opcoShipment.GeneratedDateTime = opcoShipment.GeneratedDateTime.AddSeconds(Convert.ToInt32(HHMMSS[2]));

            // Unwire event handlers for header
            shipmentParser.RecordFailed -= new TextFieldParser.RecordFailedHandler(HeaderRecordFailed);
            shipmentParser.RecordFound  -= new TextFieldParser.RecordFoundHandler(HeaderRecordFound);

            // Wire up event handlers for line
            shipmentParser.RecordFailed += new TextFieldParser.RecordFailedHandler(LineRecordFailed);
            shipmentParser.RecordFound  += new TextFieldParser.RecordFoundHandler(LineRecordFound);

            // Seed fields for line
            OpCoShipmentLine.SetParserSchema(shipmentParser.TextFields);
        }
Exemple #2
0
 public void SaveItem()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         OpCoShipment opCoShipment = PopulateNewItem();
         opCoShipment.Id = SaveItem(opCoShipment);
         Assert.IsTrue(opCoShipment.Id != -1);
     }
 }
Exemple #3
0
 public void DeleteItem()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         OpCoShipment opCoShipment = PopulateNewItem();
         int          id           = SaveItem(opCoShipment);
         Assert.IsTrue(DeleteItem(id));
     }
     //call delete lines test
 }
Exemple #4
0
        public void GetItem()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                OpCoShipment opCoShipment = PopulateNewItem();
                int          id           = SaveItem(opCoShipment);


                Assert.IsNotNull(GetItem(id, true));
            }
        }
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="requestMessage">The request message.</param>
        public override void ProcessRequest(RequestMessage requestMessage)
        {
            try
            {
                // Text field parser for reading request
                shipmentParser = new TextFieldParser(TextFieldParser.FileFormat.Delimited);

                // Specify the delimiter
                shipmentParser.Delimiter = '|';

                // Specify that we want to trim strings, this is a problem with the interface file format
                shipmentParser.TrimWhiteSpace = true;

                // Wire up event handlers for header
                shipmentParser.RecordFailed += new TextFieldParser.RecordFailedHandler(HeaderRecordFailed);
                shipmentParser.RecordFound  += new TextFieldParser.RecordFoundHandler(HeaderRecordFound);

                // Seed fields for header
                OpCoShipment.SetParserSchema(shipmentParser.TextFields);

                // Parse the header and lines
                shipmentParser.ParseFileContents(requestMessage.Body);

                // Store the opco shipment in the request processor for other subscribers
                if (RequestProcessor != null)
                {
                    RequestProcessor.RequestDictionary["OpCoShipment"] = opcoShipment;
                }

                // All worked ok
                Status = SubscriberStatusEnum.Processed;
            }
            catch (Exception ex)
            {
                // Store the exception
                LastError = ex;

                //raise an exception because parsing has failed, depending on how the handling is configured this
                //exception will probably be emailed to a user at the opco who could address the problem and resubmit the shipment
                ExceptionPolicy.HandleException
                (
                    new FailedShipmentParsingException(RequestProcessor.RequestMessage.SourceSystem, ex.Message),
                    "Business Logic"
                );

                // Failed
                Status = SubscriberStatusEnum.Failed;
            }
        }
Exemple #6
0
        public void UpdateItem()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                OpCoShipment item = PopulateNewItem();

                item.CustomerName = "Original";
                item.Id           = SaveItem(item);
                item = GetItem(item.Id, true);
                //change a value
                item.CustomerName = "Updated";

                SaveItem(item);
                item = GetItem(item.Id, true);
                Assert.IsTrue(item.CustomerName == "Updated");
            }
        }
        // Custom object hydration
        /// <summary>
        /// Customs the shipment fill.
        /// </summary>
        /// <param name="shipment">The shipment.</param>
        /// <param name="dataReader">The data reader.</param>
        /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param>
        private static void CustomShipmentFill(OpCoShipment shipment, IDataReader dataReader, bool fullyPopulate)
        {
            // See if we fully populate this entity
            if (fullyPopulate)
            {
                // Populate shipment lines
                List <OpCoShipmentLine> opCoLines = OpCoShipmentLineController.GetLines(shipment.Id);
                // The total number of lines
                int TotalLines = opCoLines.Count;
                // Clear existing lines
                shipment.ShipmentLines.Clear();
                // Add new lines
                foreach (OpCoShipmentLine opCoLine in opCoLines)
                {
                    // Specify any derived columns that we need
                    opCoLine.TotalLines = TotalLines;
                    // Add the line
                    shipment.ShipmentLines.Add(opCoLine);
                }
            }

            // Populate opco contact
            shipment.OpCoContact.Email = dataReader["OpCoContactEmail"].ToString();
            shipment.OpCoContact.Name  = dataReader["OpCoContactName"].ToString();

            // Populate shipment contact
            shipment.ShipmentContact.Email           = dataReader["ShipmentContactEmail"].ToString();
            shipment.ShipmentContact.Name            = dataReader["ShipmentContactName"].ToString();
            shipment.ShipmentContact.TelephoneNumber = dataReader["ShipmentContactTel"].ToString();

            // Populate shipment address
            shipment.ShipmentAddress.Line1    = dataReader["ShipmentAddress1"].ToString();
            shipment.ShipmentAddress.Line2    = dataReader["ShipmentAddress2"].ToString();
            shipment.ShipmentAddress.Line3    = dataReader["ShipmentAddress3"].ToString();
            shipment.ShipmentAddress.Line4    = dataReader["ShipmentAddress4"].ToString();
            shipment.ShipmentAddress.Line5    = dataReader["ShipmentAddress5"].ToString();
            shipment.ShipmentAddress.PostCode = dataReader["ShipmentPostCode"].ToString();

            // Populate customer address
            shipment.CustomerAddress.Line1    = dataReader["CustomerAddress1"].ToString();
            shipment.CustomerAddress.Line2    = dataReader["CustomerAddress2"].ToString();
            shipment.CustomerAddress.Line3    = dataReader["CustomerAddress3"].ToString();
            shipment.CustomerAddress.Line4    = dataReader["CustomerAddress4"].ToString();
            shipment.CustomerAddress.Line5    = dataReader["CustomerAddress5"].ToString();
            shipment.CustomerAddress.PostCode = dataReader["CustomerPostCode"].ToString();
        }
Exemple #8
0
        internal static OpCoShipment PopulateNewItem()
        {
            // Populate and Create an OpCo with default values
            OpCo opCo = OpcoTests.PopulateNewItem();

            opCo.Id = OpcoTests.SaveItem(opCo);

            OpCoShipment opCoShipment = new OpCoShipment();

            //populate item and lines
            opCoShipment.OpCoCode                 = opCo.Code;
            opCoShipment.OpCoSequenceNumber       = 1;
            opCoShipment.OpCoContact.Email        = "*****@*****.**";
            opCoShipment.OpCoContact.Name         = "TDC Test Team";
            opCoShipment.DespatchNumber           = "Despatch";
            opCoShipment.RequiredShipmentDate     = DateTime.Today;
            opCoShipment.TransactionTypeCode      = "TransType";
            opCoShipment.RouteCode                = "NHST";
            opCoShipment.CustomerNumber           = "CustNo";
            opCoShipment.CustomerReference        = "ref";
            opCoShipment.CustomerName             = "Robert Horne Group Ltd.";
            opCoShipment.CustomerAddress.Line1    = "Mansion House";
            opCoShipment.CustomerAddress.PostCode = "NN3 6JL";
            opCoShipment.ShipmentNumber           = "ShipNo";
            opCoShipment.ShipmentName             = "Shipment Name";
            opCoShipment.ShipmentAddress.Line1    = "Shipment Address Line 1";
            opCoShipment.ShipmentAddress.PostCode = "NN3 6JL";
            opCoShipment.SalesBranchCode          = "BBI";
            opCoShipment.AfterTime                = "08:30:00";
            opCoShipment.BeforeTime               = "23:59:59";
            opCoShipment.TailLiftRequired         = true;
            opCoShipment.VehicleMaxWeight         = (decimal)1.1;
            opCoShipment.CheckInTime              = 5;
            opCoShipment.DeliveryWarehouseCode    = "HNH";
            opCoShipment.StockWarehouseCode       = "XYZ";
            opCoShipment.DivisionCode             = "00";
            opCoShipment.GeneratedDateTime        = DateTime.Today;
            opCoShipment.Status       = 0;
            opCoShipment.UpdatedDate  = DateTime.Today;
            opCoShipment.UpdatedBy    = "TDC Test Team";
            opCoShipment.Instructions = "Instructions";

            return(opCoShipment);
        }
        /// <summary>
        /// Saves the shipment.
        /// </summary>
        /// <param name="shipment">The shipment.</param>
        /// <returns></returns>
        public static int SaveShipment(OpCoShipment shipment)
        {
            try
            {
                // Make sure the shipment is valid
                if (shipment.IsValid)
                {
                    // Save the shipment to the db and update the id, this will update the shipment lines if required
                    shipment.Id = DataAccessProvider.Instance().SaveOpCoShipment(shipment);

                    // Get the checksum for the entity
                    FrameworkController.GetChecksum(shipment);

                    // Save the shipment lines to the db
                    foreach (OpCoShipmentLine opCoShipmentLine in shipment.ShipmentLines)
                    {
                        // Save the shipment line and update the shipment line id if required
                        opCoShipmentLine.Id = OpCoShipmentLineController.SaveLine(opCoShipmentLine);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(shipment);
                }
            }
            catch (Exception ex)
            {
                // Generate a new exception
                ex = new Exception(string.Format("Failed to save OpCo shipment {0} - {1} for OpCo {2}.  {3}", shipment.ShipmentNumber, shipment.DespatchNumber, shipment.OpCoCode, ex.Message));

                // Log an throw if configured to do so
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw ex;
                }

                // We failed to save the shipment
                return(-1);
            }

            // Done
            return(shipment.Id);
        }
        /// <summary>
        /// Updates the shipment status.
        /// </summary>
        /// <param name="shipment">The shipment.</param>
        public static void UpdateShipmentStatus(OpCoShipment shipment)
        {
            try
            {
                // Get an instance of the data access provider
                DataAccessProvider dataAccessProvider = DataAccessProvider.Instance();

                // Update the status of the opco shipment in the db
                dataAccessProvider.UpdateOpCoShipmentStatus(shipment);
            }
            catch (Exception ex)
            {
                // Log an throw if configured to do so
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
        }
Exemple #11
0
        public void TestGetOpCoStockWarehouseCodes()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                // Populate and Create an OpCo Shipment with default values
                OpCoShipment opCoShipment = OpcoShipmentTests.PopulateNewItem();
                OpCoShipmentController.SaveShipment(opCoShipment);

                // Save the OpCo Code
                string SaveOpCoCode = opCoShipment.OpCoCode;

                // Create a second OpCo Shipment with the same OpCo Code, but a different stock warehouse code
                opCoShipment.Id                 = -1;
                opCoShipment.OpCoCode           = SaveOpCoCode;
                opCoShipment.StockWarehouseCode = "ZZZ";
                opCoShipment.ShipmentNumber     = "Ship2";
                opCoShipment.DespatchNumber     = "Despatch2";

                OpCoShipmentController.SaveShipment(opCoShipment);

                List <Warehouse> warehouseList = WarehouseController.GetOpCoStockWarehouseCodes(SaveOpCoCode);
                Assert.IsTrue(warehouseList.Count == 2);
            }
        }
Exemple #12
0
        public void Map()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                if (MappingController.DeleteAllMappings())
                {
                    if (MappingController.DeleteAllMappingSystems())
                    {
                        if (MappingController.DeleteAllMappingPropertyAssociations())
                        {
                            if (MappingController.DeleteAllMappingClassAssociations())
                            {
                                //add a mapping for route code
                                Mapping mapping;
                                mapping                  = PopulateMappingItem();
                                mapping.SourceValue      = "OpcoValue";
                                mapping.DestinationValue = "TDCValue";
                                MappingController.SaveMapping(mapping);


                                //set up source object to map to destination
                                OpCoShipment sourceObject = OpcoShipmentTests.PopulateNewItem();
                                sourceObject.RouteCode = mapping.SourceValue;

                                //set up a new instance of a TDC shipment to map the new values into
                                TDCShipment destinationObject = new TDCShipment();

                                //perform the mapping
                                MappingController.Map(sourceObject, destinationObject, mapping.SourceSystem.Name, mapping.DestinationSystem.Name, DoLines);


                                Assert.IsTrue
                                (
                                    destinationObject.GetType().GetProperty(mapping.MappingPropertyAssociation.DestinationProperty).
                                    GetValue(destinationObject,
                                             null).Equals(
                                        mapping.DestinationValue) &&
                                    ((sourceObject.ShipmentLines == null || sourceObject.ShipmentLines.Count == 0) || destinationObject.ShipmentLines.Count > 0) &&
                                    ((destinationObject.ShipmentLines == null || destinationObject.ShipmentLines.Count == 0) || destinationObject.ShipmentLines[0] is TDCShipmentLine) &&
                                    ((sourceObject.ShipmentLines == null || sourceObject.ShipmentLines.Count == 0) || sourceObject.ShipmentLines[0].ConversionQuantity == destinationObject.ShipmentLines[0].ConversionQuantity) &&
                                    sourceObject.CustomerAddress != null &&
                                    sourceObject.OpCoContact != null &&
                                    sourceObject.AfterTime == destinationObject.AfterTime &&
                                    sourceObject.BeforeTime == destinationObject.BeforeTime &&
                                    sourceObject.CheckInTime == destinationObject.CheckInTime &&
                                    sourceObject.CustomerAddress.Line1 == destinationObject.CustomerAddress.Line1 &&
                                    sourceObject.CustomerName == destinationObject.CustomerName &&
                                    sourceObject.CustomerNumber == destinationObject.CustomerNumber &&
                                    sourceObject.CustomerReference == destinationObject.CustomerReference &&
                                    sourceObject.DeliveryWarehouseCode == destinationObject.DeliveryWarehouseCode &&
                                    sourceObject.DespatchNumber == destinationObject.DespatchNumber &&
                                    sourceObject.DivisionCode == destinationObject.DivisionCode &&
                                    sourceObject.GeneratedDateTime == destinationObject.GeneratedDateTime &&
                                    sourceObject.Instructions == destinationObject.Instructions &&
                                    sourceObject.OpCoCode == destinationObject.OpCoCode &&
                                    sourceObject.OpCoContact.Email == destinationObject.OpCoContact.Email &&
                                    sourceObject.OpCoHeld == destinationObject.OpCoHeld &&
                                    sourceObject.OpCoSequenceNumber == destinationObject.OpCoSequenceNumber &&
                                    sourceObject.RequiredShipmentDate == destinationObject.RequiredShipmentDate &&
                                    // sourceObject.RouteCode == destinationObject.RouteCode &&
                                    sourceObject.SalesBranchCode == destinationObject.SalesBranchCode &&

                                    sourceObject.ShipmentName == destinationObject.ShipmentName &&
                                    sourceObject.ShipmentNumber == destinationObject.ShipmentNumber &&
                                    sourceObject.Status == destinationObject.Status &&
                                    sourceObject.StockWarehouseCode == destinationObject.StockWarehouseCode &&
                                    sourceObject.TailLiftRequired == destinationObject.TailLiftRequired &&
                                    sourceObject.TotalLineQuantity == destinationObject.TotalLineQuantity &&
                                    sourceObject.TransactionTypeCode == destinationObject.TransactionTypeCode &&
                                    sourceObject.VehicleMaxWeight == destinationObject.VehicleMaxWeight
                                );
                            }
                        }
                    }
                }
            }
        }
Exemple #13
0
        static internal TDCShipment PopulateItem()
        {
            TDCShipment  tdcShipment  = new TDCShipment();
            OpCoShipment opCoShipment = OpcoShipmentTests.PopulateNewItem();

            try
            {
                tdcShipment.OpCoShipmentId = OpCoShipmentController.SaveShipment(opCoShipment);
            }
            catch (InValidBusinessObjectException e)
            {
                Console.Write(e.ValidatableObject.ValidationMessages);
            }

            tdcShipment.OpCoCode           = opCoShipment.OpCoCode;
            tdcShipment.OpCoSequenceNumber = 1;

            tdcShipment.OpCoContact.Email        = "Email";
            tdcShipment.OpCoContact.Name         = "Name";
            tdcShipment.DespatchNumber           = "Number";
            tdcShipment.RequiredShipmentDate     = DateTime.Now;
            tdcShipment.CustomerNumber           = "CustNo";
            tdcShipment.CustomerName             = "CustomerName";
            tdcShipment.CustomerReference        = "ref";
            tdcShipment.CustomerAddress.Line1    = "Line1";
            tdcShipment.CustomerAddress.PostCode = "NN8 1NB";
            tdcShipment.ShipmentNumber           = "ShipNo";
            tdcShipment.ShipmentName             = "ShipmentName";
            tdcShipment.ShipmentAddress.Line1    = "Line1";
            tdcShipment.ShipmentAddress.PostCode = "NN8 1NB";
            tdcShipment.SalesBranchCode          = "BranchCode";
            tdcShipment.AfterTime           = "11:11";
            tdcShipment.BeforeTime          = "10:10";
            tdcShipment.TailLiftRequired    = false;
            tdcShipment.CheckInTime         = 1;
            tdcShipment.DivisionCode        = "Div";
            tdcShipment.GeneratedDateTime   = DateTime.Now;
            tdcShipment.Status              = Shipment.StatusEnum.Mapped;
            tdcShipment.IsRecurring         = false;
            tdcShipment.IsValidAddress      = false;
            tdcShipment.PAFAddress.Line1    = "Line1";
            tdcShipment.PAFAddress.PostCode = "PostCode";
            tdcShipment.UpdatedBy           = "UpdatedBy";
            tdcShipment.Instructions        = "Instructions";
            tdcShipment.VehicleMaxWeight    = (decimal)1.1;
            OpCoDivision division = OpcoDivisionTests.PopulateNewItem();

            OpcoDivisionTests.SaveItem(division);
            tdcShipment.DivisionCode = division.Code;

            Warehouse deliveryWarehouse = WarehouseTests.PopulateNewItem();

            WarehouseTests.SaveItem(deliveryWarehouse);
            tdcShipment.DeliveryWarehouseCode = deliveryWarehouse.Code;

            Warehouse stockWarehouse = WarehouseTests.PopulateNewItem();

            WarehouseTests.SaveItem(stockWarehouse);
            tdcShipment.StockWarehouseCode = stockWarehouse.Code;

            Route route = RouteTests.PopulateNewItem();

            RouteTests.SaveItem(route);
            tdcShipment.RouteCode = route.Code;

            TransactionType transactionType = TransactionTypeTests.PopulateNewItem();

            TransactionTypeTests.SaveItem(transactionType);
            tdcShipment.TransactionTypeCode = transactionType.Code;

            TransactionSubType transactionSubType = TransactionSubTypeTests.PopulateNewItem();

            TransactionSubTypeTests.SaveItem(transactionSubType);
            tdcShipment.TransactionSubTypeCode = transactionSubType.Code;

            return(tdcShipment);
        }
Exemple #14
0
 internal int SaveItem(OpCoShipment opCoShipment)
 {
     return(OpCoShipmentController.SaveShipment(opCoShipment));
 }
        /// <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;
            }
        }