83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
|
using SafeMobileLib;
|
|||
|
using System;
|
|||
|
using System.Diagnostics;
|
|||
|
using System.Threading;
|
|||
|
using System.Windows.Forms;
|
|||
|
using Telerik.WinControls;
|
|||
|
|
|||
|
namespace AppServer
|
|||
|
{
|
|||
|
public class FeedbackRadMessageBox
|
|||
|
{
|
|||
|
|
|||
|
// Restart if no user interaction after message box is displayed
|
|||
|
private static Thread restartThread;
|
|||
|
private static Boolean isMessageBoxShown = false;
|
|||
|
|
|||
|
public static Int16 InteractionWaitSeconds = 7;
|
|||
|
|
|||
|
|
|||
|
public static void SetTheme(String themeName)
|
|||
|
{
|
|||
|
RadMessageBox.SetThemeName(themeName);
|
|||
|
}
|
|||
|
|
|||
|
public static DialogResult ShowError(String message, String title)
|
|||
|
{
|
|||
|
return Show(title, message, MessageBoxButtons.OK, RadMessageIcon.Error);
|
|||
|
}
|
|||
|
|
|||
|
public static DialogResult ShowInfo(String message, String title)
|
|||
|
{
|
|||
|
return Show(title, message, MessageBoxButtons.OK, RadMessageIcon.Info);
|
|||
|
}
|
|||
|
|
|||
|
public static DialogResult ShowExclamation(String message, String title)
|
|||
|
{
|
|||
|
return Show(title, message, MessageBoxButtons.OK, RadMessageIcon.Exclamation);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private static DialogResult Show(String title, String message, MessageBoxButtons buttons, RadMessageIcon icon)
|
|||
|
{
|
|||
|
isMessageBoxShown = true;
|
|||
|
restartThread = new Thread(new ThreadStart(WaitForMessageBoxInteraction));
|
|||
|
restartThread.Start();
|
|||
|
|
|||
|
|
|||
|
Utils.WriteEventLog("Safemobile", title + ":" + message, icon == RadMessageIcon.Error ? EventLogEntryType.Error :
|
|||
|
(icon == RadMessageIcon.Info ? EventLogEntryType.Information : EventLogEntryType.Warning), 3345);
|
|||
|
|
|||
|
DialogResult result = RadMessageBox.Show(message, title, buttons, icon);
|
|||
|
|
|||
|
isMessageBoxShown = false;
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
private static void WaitForMessageBoxInteraction()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
int count = 0;
|
|||
|
while (isMessageBoxShown)
|
|||
|
{
|
|||
|
Thread.Sleep(100);
|
|||
|
|
|||
|
if (count++ > InteractionWaitSeconds * 10 && isMessageBoxShown == true)
|
|||
|
{
|
|||
|
isMessageBoxShown = false;
|
|||
|
|
|||
|
Utils.WriteEventLog("Safemobile", "Restarting AppServer", EventLogEntryType.Information, 3345);
|
|||
|
// restart the app if no interaction from user
|
|||
|
OnRestartRequest?.Invoke();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex) { Utils.WriteLine("WaitForMessageBoxInteraction error: " + ex.ToString(), ConsoleColor.DarkMagenta); }
|
|||
|
}
|
|||
|
public delegate void RestartRequestDel();
|
|||
|
public static event RestartRequestDel OnRestartRequest;
|
|||
|
}
|
|||
|
}
|