/// <summary> /// Main method which starts instance's loop. /// </summary> public void Run() { while (loopBreaker) { DisplayMenu(); operationExecutionReport = RunChosenOption(GetOptionFromUser()); ProcessOperationReport(operationExecutionReport); //post action log processing if (isLoggingAllowed) { ProcessOperationLog(operationExecutionReport); } } }
// -> Operation post-processing private void ProcessOperationReport(ConsoleMenuReport report) { if (report.UpdateStaticMessageRequest) { showStaticMessage = true; staticMessage = report.StaticMessage; } if (report.InterruptionRequest == Request.Suspend || report.InterruptionRequest == Request.SuspendThenBreak) { Console.WriteLine(report.DynamicMessage); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } if (report.InterruptionRequest == Request.Break || report.InterruptionRequest == Request.SuspendThenBreak) { loopBreaker = false; } else { Console.WriteLine(report.DynamicMessage); } }
// post action log private string GetLogLine(ConsoleMenuReport report) { string resultantMessage; string actionName = report.CreatorName; string resultTime = report.ReportCreationTime.ToString(); string totalTime = (report.ReportCreationTime - timeStamp).ToString(); if (report.InterruptionRequest == Request.WithoutInterruption) { resultantMessage = "Operation completed successfully."; } if (report.InterruptionRequest == Request.Break) { resultantMessage = $"Operation terminated by user in: {menuHeader}."; } else { resultantMessage = report.DynamicMessage; } return($"Operation end time: <{resultTime}> | Additional information: <{resultantMessage}> | Total time of operation: <{totalTime}>"); }
// Little Wrappers private void ProcessOperationLog(ConsoleMenuReport report) { LogToFile(GetLogLine(report)); }