From c1aed4775678af146b52fb96fd454479d3cae99a Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 10 Oct 2017 16:40:59 -0700 Subject: [PATCH] Hook up error message --- ApplicationView/ApplicationController.cs | 34 +++++++++++------------ PrinterCommunication/PrinterConnection.cs | 6 ++-- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 7e39bcb69..b4d2cf126 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -162,7 +162,6 @@ namespace MatterHackers.MatterControl internal void ClearActivePrinter() { this.ActivePrinter = emptyPrinter; - } public void RefreshActiveInstance(PrinterSettings updatedPrinterSettings) @@ -442,6 +441,22 @@ namespace MatterHackers.MatterControl thumbGenResetEvent?.Set(); }; + PrinterConnection.ErrorReported.RegisterEvent((s, e) => + { + var foundStringEventArgs = e as FoundStringEventArgs; + if (foundStringEventArgs != null) + { + string message = "Your printer is reporting a hardware Error. This may prevent your printer from functioning properly.".Localize() + + "\n" + + "\n" + + "Error Reported".Localize() + ":" + + $" \"{foundStringEventArgs.LineToCheck}\"."; + UiThread.RunOnIdle(() => + StyledMessageBox.ShowMessageBox(null, message, "Printer Hardware Error".Localize()) + ); + } + }, ref unregisterEvent); + PrinterConnection.AnyCommunicationStateChanged.RegisterEvent((s, e) => { var printerConnection = s as PrinterConnection; @@ -1201,23 +1216,6 @@ namespace MatterHackers.MatterControl } } - // TODO: this must be wired up to PrinterConnection.ErrorReported - public void PrinterReportsError(object sender, EventArgs e) - { - var foundStringEventArgs = e as FoundStringEventArgs; - if (foundStringEventArgs != null) - { - string message = "Your printer is reporting a hardware Error. This may prevent your printer from functioning properly.".Localize() - + "\n" - + "\n" - + "Error Reported".Localize() + ":" - + $" \"{foundStringEventArgs.LineToCheck}\"."; - UiThread.RunOnIdle(() => - StyledMessageBox.ShowMessageBox(null, message, "Printer Hardware Error".Localize()) - ); - } - } - public class CloudSyncEventArgs : EventArgs { public bool IsAuthenticated { get; set; } diff --git a/PrinterCommunication/PrinterConnection.cs b/PrinterCommunication/PrinterConnection.cs index 942674069..04751125e 100644 --- a/PrinterCommunication/PrinterConnection.cs +++ b/PrinterCommunication/PrinterConnection.cs @@ -77,6 +77,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication /// public class PrinterConnection { + public static RootedObjectEventHandler ErrorReported = new RootedObjectEventHandler(); + public static RootedObjectEventHandler AnyCommunicationStateChanged = new RootedObjectEventHandler(); public static RootedObjectEventHandler AnyConnectionSucceeded = new RootedObjectEventHandler(); @@ -1297,8 +1299,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication private bool haveReportedError = false; - public event EventHandler ErrorReported; - public void PrinterReportsError(object sender, EventArgs e) { if (!haveReportedError) @@ -1308,7 +1308,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication FoundStringEventArgs foundStringEventArgs = e as FoundStringEventArgs; if (foundStringEventArgs != null) { - ErrorReported?.Invoke(null, foundStringEventArgs); + ErrorReported?.Invoke(null, foundStringEventArgs); } } }