private void AddSystemLog(string strLoggingString)
        {
            try
            {
                string      strUsername    = String.Empty;
                HttpContext objHttpContext = HttpContext.Current;
                if (objHttpContext != null && objHttpContext.User != null && objHttpContext.User.Identity.IsAuthenticated)
                {
                    strUsername = objHttpContext.User.Identity.Name;
                }

                strLoggingString = String.Concat(strLoggingString, " Windows Http Username/Context that Executed the Update = [", strUsername, "]");

                // Log the update to to the user-accessible system log table
                if (SystemLogItemUtil.InsertLogItem(strLoggingString, "A user just updated a DB-driven config setting"))
                {
                    // Log to the log file
                    _objLogger.Info(strLoggingString);
                }
                else
                {
                    _objLogger.Warn(String.Format("There was an error while trying to insert the system log item."));
                }
            }
            catch (Exception ex)
            {
                string strLoggingErrorMessage = String.Concat("There was an error while trying to log the config setting change.  ", strLoggingString, ", Error Message = ", ex.Message, "]");
                _objLogger.Error(strLoggingErrorMessage);

                // Eat the error by continuing since this only affects a log of the action that already completed
                return;
            }
        }
コード例 #2
0
        public void Test_Insert_Failing()
        {
            string strNote = String.Concat("The back-end console application just sent the SYSTEM STATs email to all recipients.");

            SystemLogItemUtil.InsertLogItem(strNote, "The back-end console application just sent the SYSTEM STATs email to all recipients.");
        }
コード例 #3
0
 public void Test_Insert()
 {
     SystemLogItemUtil.InsertLogItem("This is the note", "This is the action");
 }
コード例 #4
0
        private static void LaunchProcesses(List <string> lstSwitches)
        {
            // For some of the operations, we may want to abort if there were previous issues
            bool blnProcessResult = true;

            #region EMAIL SENDS - THESE RUN EVEN IF ANOTHER PROCESS IS RUNNING IN PARALLEL
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to send the stats email
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/statsEmail"))
            {
                _objLogger.Info("   STARTED sending STATs email...");

                try
                {
                    NotificationManager objNotificationManager = new NotificationManager();
                    if (objNotificationManager.SendEmail_Stats())
                    {
                        string strLoggingMessage = String.Empty;
                        strLoggingMessage = "The STATS email was sent without issue.";
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to send the STATs email. Errors = [", String.Join(" <|> ", objNotificationManager.ErrorMessages.ToArray()), "]"));
                    }


                    string strNote = String.Concat("The back-end console application just sent the SYSTEM STATs email to all recipients.");
                    SystemLogItemUtil.InsertLogItem(strNote, "The back-end console application just sent the SYSTEM STATs email to all recipients.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the sening of the SYSTEM STATs. The console app will continue to process additional switches, but the function to send the STATs email will not continue. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);

                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "The back-end console application COULD NOT COMPLETE the sending of the STATs email.");
                }

                _objLogger.Info("   finished sending STATs email.");
            }


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to send the user reminder
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/reminderEmail"))
            {
                _objLogger.Info("   STARTED sending USER REMINDER email...");

                try
                {
                    NotificationManager objNotificationManager = new NotificationManager();
                    if (objNotificationManager.SendEmail_UserActionNeededReminder())
                    {
                        string strLoggingMessage = String.Empty;
                        strLoggingMessage = "The User Reminder email was sent without issue.";
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to send the User Reminder email. Errors = [", String.Join(" <|> ", objNotificationManager.ErrorMessages.ToArray()), "]"));
                    }


                    string strNote = String.Concat("The back-end console application just sent the USER ACTION REQUIRED REMINDER email to all recipients.");
                    SystemLogItemUtil.InsertLogItem(strNote, "The back-end console application just sent the USER REMINDER email to all recipients.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the sening of the USER REMINDER. The console app will continue to process additional switches, but the function to send the USER REMINDER email will not continue. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);

                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "The back-end console application COULD NOT COMPLETE the sending of the USER REMINDER email.");
                }

                _objLogger.Info("   finished sending USER REMINDER email.");
            }

            if (!blnProcessResult)
            {
                System.Console.WriteLine("An error occurred while processing.  Please check the log file for additional information.");
            }
            #endregion


            // THIS ENSURES THAT ONLY ONE CONSOLE APP PROCESS RUNS AT A TIME...
            // If the console app is not being run in the VS Debugger....Check to see if another instance of this same console app is running, and if so, exit this one without further processing... since we don't want to run more than one instance at a time
#if !(DEBUG)
            int intNumberOfRunningProcessesWithSameName = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count();
            if ((intNumberOfRunningProcessesWithSameName == 1)) // Since this current process fired, then we know ther is at least one.. so check for others||())
            {
            }
            else
            {
                string strNote = String.Concat("The back-end console application started, BUT since another instance of it is still running from the last scheduled start time, this new instance will now exit.");
                SystemLogItemUtil.InsertLogItem(strNote, "The back-end console application just QUIT.");
                _objLogger.Error("Another instance of this CONSOLE APP is already running, and so this new process will now exit to allow the existing process to run to completion without interference.");
                return;
            }
#endif

            _objLogger.Info("   Launching Processes");



            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the pull of address data from CDW
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Any(l => l.Contains("/pullFromCDW")))
            {
                try
                {
                    _objLogger.Info("About to Query CDW for NEW missing addresses");
                    BLL.CDWRecordPuller objCDWRecordPuller = new BLL.CDWRecordPuller();
                    if (objCDWRecordPuller.Load())
                    {
                        if (objCDWRecordPuller.Process())
                        {
                        }
                        else
                        {
                            // Log the errors that were experienced to file
                            string strErrorMessage = String.Format("There were one or more issues while trying to process the records pulled from the CDW into the customer SQL server tables. Some of the records may have been succesffuly processed, while others failed. Only addresses with issues will be listed within the error messages logged here.  Error Messages = [{0}]", String.Join(" | ", objCDWRecordPuller.ErrorMessages.ToArray()));
                            _objLogger.Error(strErrorMessage);
                        }
                    }
                    else
                    {
                        // There were one or more issues with trying to pull in the records from CDW
                        throw new Exception(String.Format("There was an error while trying to LOAD / PULL missing address records from the CDW.  The program will NOT attempt to process any records, as the issue was  been processed. Only addresses with issues will be listed within the error messages logged here.  Error Messages = [{0}]", String.Join(" | ", objCDWRecordPuller.ErrorMessages.ToArray())));
                    }

                    _objLogger.Info("Done staging NEW missing addresses from CDW");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Format("There was a global exception while trying to execute the Console application responsible for migrating addresses into GLM and SAP.  All processing has haulted.  Error Message = [{0}]", ex.Message);

                    // Log the error to the log file
                    _objLogger.Error(strErrorMessage);

                    // Write the error to the console incase someone is watching this process from the console
                    System.Console.WriteLine(strErrorMessage);

                    // Add a system log record
                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "The back-end console application COULD NOT complete the pull of records in from CDW.");
                }

                string strNote = String.Concat("The back-end console application just finished pulling in the newest changeset of new or changed address records from the CDW.  It may or may not have completed without errors.  Please review earlier log messages for details.");
                SystemLogItemUtil.InsertLogItem(strNote, "CDW Sync");
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to analyze any order addresses that are currently active within the workflow and that require further processing against SAP
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/sapChecks"))
            {
                string strNote = String.Empty;

                try
                {
                    _objLogger.Info("   STARTED procesing all order addresses that require handling...");

                    BLL.OrderAddressBatchOrchestrator objOrderAddressBatchOrchestrator = new BLL.OrderAddressBatchOrchestrator();
                    if (objOrderAddressBatchOrchestrator.Load(Model.BatchType.SAPChecks))
                    {
                        string strLoggingMessage = String.Empty;
                        if (objOrderAddressBatchOrchestrator.Process())
                        {
                            strLoggingMessage = "The order address batch orchestrator completed processing without issue";
                        }
                        else
                        {
                            strLoggingMessage = "The order address batch orchestrator experienced one or more errors while trying to process the group of records.";
                            _objLogger.Error(String.Concat("There was one or more errors while trying to process the addresses in the system requiring processing. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                        }
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to load the order address batch orchestrator. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                    }

                    _objLogger.Info("   FINISHED procesing all order addresses that required handling.");

                    strNote = String.Concat("The back-end console application just completed procesing all order addresses that required existence checks in SAP.");
                    SystemLogItemUtil.InsertLogItem(strNote, "The back-end console application just completed procesing all order addresses that required handling.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the Order Address Batch Orchestrator and the processing of Order Address transactions.  The console app will continue to process additional switches, but the function to process order addresses has failed. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);
                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "The back-end console application COULD NOT complete the processing of all order addresses requiring existence check in SAP.");
                }

                strNote = String.Concat("The back-end console application just finished running existence checks against SAP for any records queued for such an action.");
                SystemLogItemUtil.InsertLogItem(strNote, "SAP Existence Check");
            }


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to analyze any order addresses that are currently active within the workflow and that require further processing
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/processInWorkflow"))
            {
                try
                {
                    _objLogger.Info("   STARTED procesing all order addresses that require handling...");

                    BLL.OrderAddressBatchOrchestrator objOrderAddressBatchOrchestrator = new BLL.OrderAddressBatchOrchestrator();
                    if (objOrderAddressBatchOrchestrator.Load(Model.BatchType.AlreadyInWorkflow))
                    {
                        string strLoggingMessage = String.Empty;
                        if (objOrderAddressBatchOrchestrator.Process())
                        {
                            strLoggingMessage = "The order address batch orchestrator completed processing without issue";
                        }
                        else
                        {
                            strLoggingMessage = "The order address batch orchestrator experienced one or more errors while trying to process the group of records.";
                            _objLogger.Error(String.Concat("There was one or more errors while trying to process the addresses in the system requiring processing. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                        }
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to load the order address batch orchestrator. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                    }

                    _objLogger.Info("   FINISHED procesing all order addresses that required handling.");

                    string strNote = String.Concat("The back-end console application just completed procesing all order addresses that are or were IN WORKFLOW at the time the process kicked off.");
                    SystemLogItemUtil.InsertLogItem(strNote, "Back-end console application; IN WORKFLOW.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the Order Address Batch Orchestrator and the processing of Order Address transactions.  The console app will continue to process additional switches, but the function to process order addresses has failed. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);
                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "The back-end console application COULD NOT complete the processing of all order addresses that are currently IN WORKFLOW.");
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to analyze any order addresses that are currently active within the workflow and that require further processing
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/processNonErrorsInWorkflow"))
            {
                try
                {
                    _objLogger.Info("   STARTED procesing all order addresses that require handling...");

                    BLL.OrderAddressBatchOrchestrator objOrderAddressBatchOrchestrator = new BLL.OrderAddressBatchOrchestrator();
                    if (objOrderAddressBatchOrchestrator.Load(Model.BatchType.AlreadyInWorkflowWithNoErrors))
                    {
                        string strLoggingMessage = String.Empty;
                        if (objOrderAddressBatchOrchestrator.Process())
                        {
                            strLoggingMessage = "The order address batch orchestrator completed processing without issue";
                        }
                        else
                        {
                            strLoggingMessage = "The order address batch orchestrator experienced one or more errors while trying to process the group of records.";
                            _objLogger.Error(String.Concat("There was one or more errors while trying to process the addresses in the system requiring processing. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                        }
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to load the order address batch orchestrator. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                    }

                    _objLogger.Info("   FINISHED procesing all order addresses that required handling.");

                    string strNote = String.Concat("The back-end console application just completed procesing all order addresses that are or were IN WORKFLOW and that WERE NOT ERRORING or ABANDONED at the time the process kicked off.");
                    SystemLogItemUtil.InsertLogItem(strNote, "Back-end console application; IN WORKFLOW NOT ERRORING OR ABANDONED.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the Order Address Batch Orchestrator and the processing of Order Address transactions.  The console app will continue to process additional switches, but the function to process order addresses has failed. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);
                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "The back-end console application COULD NOT complete the processing of all order addresses that are currently IN WORKFLOW and that WERE NOT ERRORING or ABANDONED.");
                }
            }

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to analyze any order addresses that are currently active within the workflow, have failed on the last call, and that wil be reattempted
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/retryErrors"))
            {
                try
                {
                    _objLogger.Info("   STARTED procesing all order addresses that require handling...");

                    BLL.OrderAddressBatchOrchestrator objOrderAddressBatchOrchestrator = new BLL.OrderAddressBatchOrchestrator();
                    if (objOrderAddressBatchOrchestrator.Load(Model.BatchType.Errors))
                    {
                        string strLoggingMessage = String.Empty;
                        if (objOrderAddressBatchOrchestrator.Process())
                        {
                            strLoggingMessage = "The order address batch orchestrator completed processing without issue";
                        }
                        else
                        {
                            strLoggingMessage = "The order address batch orchestrator experienced one or more errors while trying to process the group of records.";
                            _objLogger.Error(String.Concat("There was one or more errors while trying to process the addresses in the system requiring processing. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                        }
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to load the order address batch orchestrator. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                    }

                    _objLogger.Info("   FINISHED procesing all order addresses that required handling.");

                    string strNote = String.Concat("The back-end console application just completed procesing all order addresses that required RE-TRY due to previously FAILED API Calls.");
                    SystemLogItemUtil.InsertLogItem(strNote, "Back-end console application; RETRY ERRORS.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the Order Address Batch Orchestrator and the processing of Order Address transactions that needed RETRY due to previous API Call Errors.  The console app will continue to process additional switches, but the function to process order addresses has failed. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);
                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "FAILED: Back-end console application; RETRY ERRORS.");
                }
            }

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to analyze any order addresses that were just added to the system from the CDW
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/startNew"))
            {
                try
                {
                    _objLogger.Info("   STARTED procesing all order addresses that require handling...");

                    BLL.OrderAddressBatchOrchestrator objOrderAddressBatchOrchestrator = new BLL.OrderAddressBatchOrchestrator();
                    if (objOrderAddressBatchOrchestrator.Load(Model.BatchType.OnlyNewFromCDW))
                    {
                        string strLoggingMessage = String.Empty;
                        if (objOrderAddressBatchOrchestrator.Process())
                        {
                            strLoggingMessage = "The order address batch orchestrator completed processing without issue";
                        }
                        else
                        {
                            strLoggingMessage = "The order address batch orchestrator experienced one or more errors while trying to process the group of records.";
                            _objLogger.Error(String.Concat("There was one or more errors while trying to process the addresses in the system requiring processing. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                        }
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to load the order address batch orchestrator. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                    }

                    _objLogger.Info("   FINISHED procesing all order addresses that required handling.");

                    string strNote = String.Concat("The back-end console application just completed procesing all order addresses that were NEWLY SYNC'D in from CDW.");
                    SystemLogItemUtil.InsertLogItem(strNote, "Back-end console application; NEWLY SYNC'D.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the Order Address Batch Orchestrator and the processing of Order Address transactions that were NEWLY Sync'd in from CDW.  The console app will continue to process additional switches, but the function to process order addresses has failed. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);
                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "FAILED: Back-end console application; START NEW.");
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Trigger the workflow engine to analyze any order addresses that are currently active within the workflow and that require further processing
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (blnProcessResult && lstSwitches.Contains("/processAll"))
            {
                try
                {
                    _objLogger.Info("   STARTED procesing all order addresses that require handling...");

                    BLL.OrderAddressBatchOrchestrator objOrderAddressBatchOrchestrator = new BLL.OrderAddressBatchOrchestrator();
                    if (objOrderAddressBatchOrchestrator.Load(Model.BatchType.AllAddressesNeedingProcessing))
                    {
                        string strLoggingMessage = String.Empty;
                        if (objOrderAddressBatchOrchestrator.Process())
                        {
                            strLoggingMessage = "The order address batch orchestrator completed processing without issue";
                        }
                        else
                        {
                            strLoggingMessage = "The order address batch orchestrator experienced one or more errors while trying to process the group of records.";
                            _objLogger.Error(String.Concat("There was one or more errors while trying to process the addresses in the system requiring processing. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                        }
                        _objLogger.Info(strLoggingMessage);
                    }
                    else
                    {
                        _objLogger.Error(String.Concat("There was one or more errors while trying to load the order address batch orchestrator. Errors = [", String.Join(" <|> ", objOrderAddressBatchOrchestrator.ErrorMessages.ToArray()), "]"));
                    }

                    _objLogger.Info("   FINISHED procesing all order addresses that required handling.");

                    string strNote = String.Concat("The back-end console application just completed PROCESSING ALL order addresses that required handling in the system.");
                    SystemLogItemUtil.InsertLogItem(strNote, "Back-end console application; PROCESS ALL.");
                }
                catch (Exception ex)
                {
                    string strErrorMessage = String.Concat("There was a SERIOUS GLOBAL exception that affects the Order Address Batch Orchestrator and the PROCESSING of ALL Order Address transactions.  The console app will continue to process additional switches, but the function to process order addresses has failed. Error Message = [", ex.Message, "]");
                    _objLogger.Error(strErrorMessage);
                    SystemLogItemUtil.InsertLogItem(strErrorMessage, "FAILED: Back-end console application; PROCESS ALL.");
                }
            }
        }