Esempio n. 1
0
        // Public Methods
        public bool Load(OrderAddress objOrderAddress)
        {
            try
            {
                if (objOrderAddress == null)
                {
                    throw new Exception("The workflow address object supplied was null.  The Workflow address State evaluator requires a loaded, non-null address to function. ");
                }

                // Set the local property
                _objOrderAddress_Existing = objOrderAddress;

                // Set the base logging string
                _strBaseLoggingMessage = OrderAddressUtil.CalcUniqueRecordIdentifierLoggingString(_objOrderAddress_Existing);
            }
            catch (Exception ex)
            {
                _lstErrorMessages.Add(String.Concat("There was an error while trying to LOAD the address Evaluator.  ", _strBaseLoggingMessage, ",  Error Message: [", ex.Message, "]"));
            }

            _blnIsLoaded = _lstErrorMessages.Count() == 0;

            // return
            return(_blnIsLoaded);
        }
        public bool Process()
        {
            try
            {
                // Instantiate a stopwatch to write runtimes to a log file
                Stopwatch objStopWatch = new Stopwatch();
                objStopWatch.Start();

                // Iterate over the order addresses that require processing
                Parallel.For(0, _lstOrderAddressRecords_ToProcess.Count, new ParallelOptions {
                    MaxDegreeOfParallelism = _intNumberOfThreads
                }, i =>
                {
                    // Declare a base logging string
                    string strBaseLoggingString = OrderAddressUtil.CalcUniqueRecordIdentifierLoggingString(_lstOrderAddressRecords_ToProcess[i]);

                    try
                    {
                        // Instantiate an OrderAddressProcessor for the order
                        OrderAddressProcessor objOrderAddressProcessor = new OrderAddressProcessor();
                        if (objOrderAddressProcessor.Load(_lstOrderAddressRecords_ToProcess[i].OrderAddressID.Value) == false)
                        {
                            throw new Exception(String.Format("The OrderAddressProcessor could not be loaded from the address record, and so processing of this single transaction will be aborted and skipped. Error Messages = [{0}]", String.Join(" | ", objOrderAddressProcessor.ErrorMessages.ToArray())));
                        }

                        if (objOrderAddressProcessor.Process() == false)
                        {
                            throw new Exception(String.Format("The OrderAddressProcessor experienced an issue. Error Messages = [{0}]", String.Join(" | ", objOrderAddressProcessor.ErrorMessages.ToArray())));
                        }
                    }
                    catch (Exception ex)
                    {
                        string strErrorMessage = String.Format("There was an error while processing one of the order address records that needs processing into GLM and SAP.  This error is contained to a single Order Address record, which will now be skipped.  Other records contained in the result set will continue to process.  Error Message = [{0}].  {1}", ex.Message, strBaseLoggingString);

                        // Log a warning to the log file
                        _objLogger.Warn(strErrorMessage);

                        // Continue to the next record, so that one bad record cannot hault the processing of subsequent records that are next in the list
                        return;
                    }
                });

                // This is the code, without MULTI-THREADING, if ever needed.
                //// Iterate over the order addresses that require processing
                //for (int i = 0; i < _lstOrderAddressRecords_ToProcess.Count; i++)
                //{
                //    // Declare a base logging string
                //    string strBaseLoggingString = OrderAddressUtil.CalcUniqueRecordIdentifierLoggingString(_lstOrderAddressRecords_ToProcess[i]);

                //    try
                //    {
                //        // Instantiate an OrderAddressProcessor for the order
                //        OrderAddressProcessor objOrderAddressProcessor = new OrderAddressProcessor();
                //        if (objOrderAddressProcessor.Load(_lstOrderAddressRecords_ToProcess[i].OrderAddressID.Value) == false)
                //        {
                //            throw new Exception(String.Format("The OrderAddressProcessor could not be loaded from the address record, and so processing of this single transaction will be aborted and skipped. Error Messages = [{0}]", String.Join(" | ", objOrderAddressProcessor.ErrorMessages.ToArray())));
                //        }

                //        if (objOrderAddressProcessor.Process() == false)
                //        {
                //            throw new Exception(String.Format("The OrderAddressProcessor experienced an issue. Error Messages = [{0}]", String.Join(" | ", objOrderAddressProcessor.ErrorMessages.ToArray())));
                //        }
                //    }
                //    catch (Exception ex)
                //    {
                //        string strErrorMessage = String.Format("There was an error while processing one of the order address records that needs processing into GLM and SAP.  This error is contained to a single Order Address record, which will now be skipped.  Other records contained in the result set will continue to process.  Error Message = [{0}].  {1}", ex.Message, strBaseLoggingString);

                //        // Log a warning to the log file
                //        _objLogger.Warn(strErrorMessage);

                //        // Continue to the next record, so that one bad record cannot hault the processing of subsequent records that are next in the list
                //        continue;
                //    }
                //}


                // Log the time to retrieve the date
                string strTimeElapsed = StopwatchUtil.GetHumanReadableTimeElapsedString(objStopWatch);
                _objLogger.Info(String.Concat("Time elapsed while processing the Order Address records included in this batch.  Batch Type [", _enmBatchType, "] was [", strTimeElapsed, "] to retrieve [", _lstOrderAddressRecords_ToProcess.Count, "] records."));
            }
            catch (Exception ex)
            {
                // Create the error message
                string strErrorMessage = String.Format("A global error was caught while trying to process the order addresses loaded into memory and that were to be included as part of this batch.  This failure occured outside the try/catch/continue meaning that subsequent records will NOT be processed.  Please investigate the issue and run the process again to process any records that had not yet been processed when things errored.  Error Message = [{0}]", ex.Message);

                // Log a warning to the log file
                _objLogger.Warn(strErrorMessage);

                // Add the error message to the error list so that the caller can access it
                _lstErrorMessages.Add(strErrorMessage);
            }

            _blnIsLoaded = (_lstErrorMessages.Count == 0);

            return(_blnIsLoaded);
        }