public void AddUILogMessage( IUILogMessage uILogMessage, bool showMessageBox = false) { EventsViewModel.AddUILogMessage(uILogMessage, showMessageBox); }
public void TryExecute( string actionName, Func <Tuple <bool, string> > action, bool showMessageBoxOnError = false, bool showMessageBoxOnSuccess = false) { EventsViewModel.UpdateStatusStripText($"Executing action {actionName}"); Exception exception = null; string resultMessage; bool resultIsSuccess; try { var result = action(); if (result != null) { resultIsSuccess = result.Item1; if (resultIsSuccess) { resultMessage = result.Item2 ?? $"Action {actionName} executed successfully"; } else { resultMessage = result.Item2 ?? $"An error ocurred while executing action {actionName}"; } } else { resultIsSuccess = false; resultMessage = $"Something went wrong while executing action {actionName}"; } } catch (Exception exc) { resultIsSuccess = false; resultMessage = $"An Unhandled error ocurred while executing action {actionName}"; exception = exc; } var uILogMessageLevel = resultIsSuccess ? UILogMessageLevel.Information : UILogMessageLevel.Error; bool showMessageBox; if (resultIsSuccess) { showMessageBox = showMessageBoxOnSuccess; EventsViewModel.UpdateStatusStripText($"Action {actionName} executed successfully"); } else { showMessageBox = showMessageBoxOnError; EventsViewModel.UpdateStatusStripText($"Action {actionName} executed with errors"); } EventsViewModel.AddUILogMessage( uILogMessageLevel, resultMessage, exception, showMessageBox); }