/// <summary> /// Processes the request. /// </summary> /// <param name="requestMessage">The request message.</param> public override void ProcessRequest(RequestMessage requestMessage) { ShipmentDropLine.SetDropLineSchema(textFieldParser.TextFields); try { textFieldParser.FirstLineIsHeader = true; textFieldParser.TrimWhiteSpace = true; textFieldParser.Delimiter = '|'; textFieldParser.FileType = TextFieldParser.FileFormat.Delimited; // Set up event handlers for when a row is read and when a row is read but failes to match the expected schema textFieldParser.RecordFound += new TextFieldParser.RecordFoundHandler(textFieldParser_RecordFound); textFieldParser.RecordFailed += new TextFieldParser.RecordFailedHandler(RecordFailed); // parse the message textFieldParser.ParseFileContents(requestMessage.Body); // Processed Status = SaveDropLines(); } catch (Exception ex) { // Store the exception LastError = ex; // Failed Status = SubscriberStatusEnum.Failed; } }
/// <summary> /// Populates the commander sales order from the item values held in the TextFieldCollection.. /// </summary> /// <param name="fields">The fields.</param> /// <returns></returns> private ShipmentDropLine PopulateDropLine(TextFieldCollection fields) { ShipmentDropLine shipmentDropLine = new ShipmentDropLine(); PopulateProperties(fields, shipmentDropLine); return(shipmentDropLine); }
public static Int32 SaveDropLine(ShipmentDropLine line) { TDCShipmentLine tdcShipmentLine; //if (line.ShipmentLineId == Null.NullInteger) //{ // //get shipment id tdcShipmentLine = TDCShipmentLineController.GetLine(line.LineCode, line.OpcoCode, line.ShipmentNumber, line.DespatchNumber); if (tdcShipmentLine == null) { throw new Exception( string.Format("When importing Drop Line data the related Shipment Line could not be found. The line code was '{3}', Opco Code was '{0}', the Shipment Number was '{1}', and the Despatch Number was '{2}'.", line.OpcoCode, line.ShipmentNumber, line.DespatchNumber, line.LineCode)); } //if (line.ShipmentLineId == Null.NullInteger) //{ // throw new Exception( // string.Format("When importing Drop Line data the related Shipment Line could not be found. The Opco Code was '{0}', the Shipment Number was '{1}', and the Despatch Number was '{2}' and the Line Code was '{3}'.", // line.OpcoCode, line.ShipmentNumber, line.DespatchNumber, line.LineCode)); //} line.ShipmentLineId = tdcShipmentLine.Id; if (!line.Split) { } else { //optrak split this line // tdcShipment.SplitShipment() } //} if (line.DropId == Null.NullInteger) { //get warehouse id which will be used to find the trip id int warehouseId; Warehouse relatedWarehouse = WarehouseController.GetWarehouse(line.Depot); if (relatedWarehouse == null) { throw new Exception( string.Format("When importing Drop Line data the related warehouse could not be found. The Warehouse number was '{0}'.", line.Depot)); } warehouseId = relatedWarehouse.Id; //get the related trip id Trip relatedTrip = TripController.GetTripByWarehouseDateAndNumber(line.TripNumber, line.DeliveryDate, warehouseId); if (relatedTrip == null) { //the trip file hasn't bee recieved yet so add a record to relate to for now relatedTrip = new Trip(); relatedTrip.TripNumber = line.TripNumber; relatedTrip.StartDate = line.DeliveryDate; relatedTrip.WarehouseId = warehouseId; relatedTrip.Id = TripController.SaveTrip(relatedTrip); } if (relatedTrip.Id == -1) { throw new Exception( string.Format("When importing ShipmentDrop data a related trip could not be created with details, Trip Number: '{0}', Search Date: '{1}', and WarehouseId: '{2}'.", line.TripNumber, line.DeliveryDate.ToShortDateString(), warehouseId)); } //get drop id this line relates to ShipmentDrop relatedShipmentDrop = GetDrop(tdcShipmentLine.ShipmentId, relatedTrip.Id, line.OrderSequence, line.DropSequence); if (relatedShipmentDrop == null) { //a related shipment drop could not be found //this could be because that file has not been proced yet so create //a blank one to relate to relatedShipmentDrop = new ShipmentDrop(); relatedShipmentDrop.ShipmentId = tdcShipmentLine.ShipmentId; relatedShipmentDrop.TripId = relatedTrip.Id; // relatedShipmentDrop.OrderSequence = line.OrderSequence; relatedShipmentDrop.DropSequence = line.DropSequence; relatedShipmentDrop.Id = SaveDrop(relatedShipmentDrop, line.Depot); } if (relatedShipmentDrop.Id == -1) { throw new Exception( string.Format("When importing Drop Line data a related Drop could not be created with details, Shipment Id: '{0}', Trip Id: '{1}', and Order OrderSequence: '{2}' and Drop OrderSequence '{3}'.", tdcShipmentLine.ShipmentId, relatedTrip.Id, line.OrderSequence, line.DropSequence)); } line.DropId = relatedShipmentDrop.Id; } try { if (line.IsValid) { // Save entity //check to see if we've had this data before or we have recieved a TRIPPART file that needed us to //add a record to maintain referential integrity ShipmentDropLine existingShipmentDropLine = null;// DropController.GetDropLine(line.ShipmentLineId); if (existingShipmentDropLine != null) { //just overwite with this new data //log? line.Id = existingShipmentDropLine.Id; line.CheckSum = existingShipmentDropLine.CheckSum; } line.OriginalShipmentLineId = line.ShipmentLineId; line.Id = DataAccessProvider.Instance().SaveDropLine(line); } else { // Entity is not valid throw new InValidBusinessObjectException(line); } } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } // Done return(line.Id); }