void WorkerAgentObject_NewLogItem(WorkerAgent.Log log) { // This event handler is invoked in the context of UI thread. // Worker Start/Stop status check if ((log is WorkerAgent.WorkerStartedLog)) { // Change UI ChangeUIByWorkerAgentStatus(true); } else if (log is WorkerAgent.WorkerStoppedLog) { // Change UI ChangeUIByWorkerAgentStatus(false); } else if (log is WorkerAgent.JobResultSentLog) { statistics.DoneJobs += 1; lblDoneJobs.Text = statistics.DoneJobs.ToString(); } else if (log is WorkerAgent.JobsRecivedLog) { statistics.RecivedJobs += ((WorkerAgent.JobsRecivedLog)log).Jobs.Length; lblRecivedJobs.Text = statistics.RecivedJobs.ToString(); } else if (log is WorkerAgent.ErrorInWritingJobToDiskLog || (log is WorkerAgent.ErrorInReadingJobOutputFile) || (log is WorkerAgent.ErrorInJobExecutionLog)) { statistics.FailedJobs++; lblFailedJobs.Text = statistics.FailedJobs.ToString(); } // Add log to the textbox if (EnabledToolStripMenuItem.Checked) { AddLogToTextBox(log); } }
void _controlUnit_OnNewLogItem(WorkerAgent.Log log) { // Raise "this.NewLogItem" event EventExtensions.Raise(NewLogItem, new[] { log }); }
private void AddLogToTextBox(WorkerAgent.Log log) { Color timeColor = Color.Gray; Color messageColor = Color.White; Color errorMessageColor = Color.Red; const int INDENT_L1 = 30; // Level 1 indent size = 30; AppendText(DateTime.Now.ToLongTimeString() + " ", timeColor); if (log is WorkerAgent.JobsRecivedLog) { #region JobsRecivedLog WorkerAgent.JobsRecivedLog l = (WorkerAgent.JobsRecivedLog)log; AppendText(l.Jobs.Length.ToString() + " job(s) recived:", messageColor); rtbLogs.AppendText(Environment.NewLine); for (int i = 0; i < l.Jobs.Length; i++) { AppendText("[" + (i + 1).ToString() + "] Job ID: ", Color.Aqua, INDENT_L1); AppendText(l.Jobs[i].ID.ToString(), Color.Aqua, 30); AppendText(" Executable length: " + l.Jobs[i].ExecutableFileLength.ToString() + " Bytes", Color.Aqua, INDENT_L1); rtbLogs.AppendText(Environment.NewLine); } #endregion } else if (log is WorkerAgent.JobExecutionStartedLog) { #region JobExecutionStartedLog WorkerAgent.JobExecutionStartedLog l = (WorkerAgent.JobExecutionStartedLog)log; AppendText(l.Message + " (Job ID: " + l.Job.ID.ToString() + ")", messageColor); #endregion } else if (log is WorkerAgent.JobResultSentLog) { #region JobResultSentLog WorkerAgent.JobResultSentLog l = (WorkerAgent.JobResultSentLog)log; AppendText(l.Message + " (Job ID: " + l.Job.ID.ToString() + ")", messageColor); #endregion } else if (log is WorkerAgent.JobExecutedSuccessfullyLog) { #region JobExecutedSuccessfullyLog WorkerAgent.JobExecutedSuccessfullyLog l = (WorkerAgent.JobExecutedSuccessfullyLog)log; AppendText(l.Message + " (Job ID: " + l.Job.ID.ToString() + ")", messageColor); #endregion } else if (log is WorkerAgent.WorkerStartedLog) { #region WorkerStartedLog WorkerAgent.WorkerStartedLog l = (WorkerAgent.WorkerStartedLog)log; AppendText(l.Message, Color.GreenYellow); #endregion } else if (log is WorkerAgent.WorkerStoppedLog) { #region WorkerStoppedLog WorkerAgent.WorkerStoppedLog l = (WorkerAgent.WorkerStoppedLog)log; AppendText(l.Message, messageColor); #endregion } else if (log is WorkerAgent.WorkerCouldNotStartLog) { #region WorkerCouldNotStartLog WorkerAgent.WorkerCouldNotStartLog l = (WorkerAgent.WorkerCouldNotStartLog)log; AppendText(l.Message, errorMessageColor); rtbLogs.AppendText(Environment.NewLine); AppendText("Error Message: " + l.ErrorMessage, errorMessageColor); #endregion } else if (log is WorkerAgent.WorkerCouldNotStopLog) { #region WorkerCouldNotStopLog WorkerAgent.WorkerCouldNotStopLog l = (WorkerAgent.WorkerCouldNotStopLog)log; AppendText(l.Message, errorMessageColor); rtbLogs.AppendText(Environment.NewLine); AppendText("Error Message: " + l.ErrorMessage, errorMessageColor); #endregion } else if (log is WorkerAgent.ErrorInJobExecutionLog) { #region ErrorInJobExecutionLog WorkerAgent.ErrorInJobExecutionLog l = (WorkerAgent.ErrorInJobExecutionLog)log; AppendText(l.Message, errorMessageColor); rtbLogs.AppendText(Environment.NewLine); AppendText("Job ID: " + l.Job.ID.ToString() + Environment.NewLine, errorMessageColor, INDENT_L1); AppendText("Job Executable: " + l.Job.ExecuteableFileName + Environment.NewLine, errorMessageColor, INDENT_L1); AppendText("Error: " + l.ErrorMessage, errorMessageColor, 30); rtbLogs.AppendText(Environment.NewLine); AppendText("Is Win32 Error: " + (l.IsWin32Error ? "Yes" : "No"), errorMessageColor, INDENT_L1); if (l.IsWin32Error) { rtbLogs.AppendText(Environment.NewLine); AppendText("Win32 Error Code: " + l.Win32ErrorCode.ToString(), errorMessageColor, INDENT_L1); } #endregion } else if (log is WorkerAgent.ErrorInWritingJobToDiskLog) { #region ErrorInWritingJobToDiskLog WorkerAgent.ErrorInWritingJobToDiskLog l = (WorkerAgent.ErrorInWritingJobToDiskLog)log; AppendText(l.Message + " (Job ID: " + l.Job.ID.ToString() + ")", errorMessageColor); rtbLogs.AppendText(Environment.NewLine); AppendText("Error Message: " + l.ErrorMessage, errorMessageColor); #endregion } else if (log is WorkerAgent.ErrorInReadingJobOutputFile) { #region ErrorInReadingJobOutputFile WorkerAgent.ErrorInReadingJobOutputFile l = (WorkerAgent.ErrorInReadingJobOutputFile)log; AppendText(l.Message + " (Job ID: " + l.Job.ID.ToString() + ")", errorMessageColor); rtbLogs.AppendText(Environment.NewLine); AppendText("Error Message: " + l.ErrorMessage, errorMessageColor, INDENT_L1); #endregion } else if (log is WorkerAgent.ErrorInConnectingToJobServerLog) { #region ErrorInConnectingToJobServerLog WorkerAgent.ErrorInConnectingToJobServerLog l = (WorkerAgent.ErrorInConnectingToJobServerLog)log; AppendText(l.Message, errorMessageColor); rtbLogs.AppendText(Environment.NewLine); AppendText("Error Message: " + l.ErrorMessage, errorMessageColor, INDENT_L1); #endregion } else if (log is WorkerAgent.WorkerRegisterationFailedLog) { #region WorkerRegisterationFailedLog WorkerAgent.WorkerRegisterationFailedLog l = (WorkerAgent.WorkerRegisterationFailedLog)log; AppendText(l.Message, errorMessageColor); rtbLogs.AppendText(Environment.NewLine); #endregion } else if (log is WorkerAgent.WorkerRegisterationStartLog) { #region WorkerRegisterationStartLog WorkerAgent.WorkerRegisterationStartLog l = (WorkerAgent.WorkerRegisterationStartLog)log; AppendText(l.Message, Color.GreenYellow); #endregion } else if (log is WorkerAgent.WorkerRegisterdLog) { #region WorkerRegisterdLog WorkerAgent.WorkerRegisterdLog l = (WorkerAgent.WorkerRegisterdLog)log; AppendText(l.Message, Color.GreenYellow); rtbLogs.AppendText(Environment.NewLine); #endregion } else // log is Log { AppendText(log.Message, messageColor); } // Move cursor to next line rtbLogs.AppendText(Environment.NewLine); rtbLogs.ScrollToCaret(); }