Hook up error message

This commit is contained in:
Lars Brubaker 2017-10-10 16:40:59 -07:00
parent da5a9279df
commit c1aed47756
2 changed files with 19 additions and 21 deletions

View file

@ -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; }

View file

@ -77,6 +77,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication
/// </summary>
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);
}
}
}