SafeDispatch/Safedispatch_4_0/Program.cs

184 lines
6.7 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.IO;
using SafeMobileLib;
using SafeMobileLib.Helpers;
using System.Diagnostics;
using CefSharp;
using CefSharp.WinForms;
namespace Safedispatch_4_0
{
static class Program
{
static String filename = "";
// private static LicenseInitializer m_AOLicenseInitializer = new Safedispatch_4_0.LicenseInitializer();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread()]
static void Main(string[] args)
{
// register for console events in order to intercept the close event
handler = new ConsoleEventDelegate(ConsoleEventCallback);
//ESRI License Initializer generated code.
/*m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeArcView },
new esriLicenseExtensionCode[] { });
*/
Console.Title = "DispatchConsole";
MainForm2.radioType = RADIOTYPE.UNKNOWN;
#if MOTOROLA
MainForm2.radioType = RADIOTYPE.MOTO;
#elif HYTERA
MainForm2.radioType = RADIOTYPE.HYT;
#elif HARRIS
MainForm2.radioType = RADIOTYPE.HARRIS;
#elif ATLAS
MainForm2.radioType = RADIOTYPE.ATLAS;
#elif TETRA
MainForm2.radioType = RADIOTYPE.TETRA;
#elif CONPLUS
MainForm2.radioType = RADIOTYPE.CONECTPLUS;
#elif REPEATER
MainForm2.radioType = RADIOTYPE.REPEATER_TRBO;
#elif SIMOCO
MainForm2.radioType = RADIOTYPE.SIMOCO;
#elif EXCERA
MainForm2.radioType = RADIOTYPE.EXCERA;
#elif LINX
MainForm2.radioType = RADIOTYPE.LINX;
#elif LINXB
MainForm2.radioType = RADIOTYPE.LINXB;
#elif LISF
MainForm2.radioType = RADIOTYPE.LISF;
#endif
//if (!HandleCommandLineArgs(args))
// return;
// parse the command line args
CommandLineHelper clh = new CommandLineHelper(args, Console.Title);
MainForm2.radioType = clh.ConfigurationType;
if (MainForm2.radioType == RADIOTYPE.UNKNOWN)
{
Application.Exit();
}
else
{
// Test if app if allready working
if (Utils.testIfAlreadyRunning(true))
{
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (!AppDomain.CurrentDomain.FriendlyName.EndsWith("vshost.exe"))
{
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
// Set the unhandled exception mode to force all Windows Forms errors
// to go through our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
InitializeCefSharp();
Application.Run(new Login());
}
//ESRI License Initializer generated code.
//Do not make any call to ArcObjects after ShutDownApplication()
//m_AOLicenseInitializer.ShutdownApplication();
}
static void InitializeCefSharp()
{
var settings = new CefSettings();
CefSharpSettings.FocusedNodeChangedEnabled = true;
CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
CefSharpSettings.WcfEnabled = true;
// Enable Precise Memory Info
settings.CefCommandLineArgs.Add("enable-precise-memory-info", "1");
settings.CefCommandLineArgs.Add("ignore-certificate-errors");
settings.IgnoreCertificateErrors = true;
if (MainForm2.MapDebugConsole)
settings.CefCommandLineArgs.Add("remote-debugging-port", "9222");
// initialize the browser so the settings arguments are passed to the instances
if (!Cef.IsInitialized)
Cef.Initialize(settings);
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
//MessageBox.Show(e.Exception.Message, "ThreadException Dispatch.Please restart the application.");
Utils.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", ConsoleColor.Red);
Utils.WriteLine("Application_ThreadException: " + e.Exception.ToString(), ConsoleColor.Red);
Utils.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", ConsoleColor.Red);
// here you can log the exception ...
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
//MessageBox.Show((e.ExceptionObject as Exception).Message, "Unhandled UI Exception Dispatch.Please restart the application.");
Utils.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", ConsoleColor.Red);
Utils.WriteLine("CurrentDomain_UnhandledException: " + e.ToString(), ConsoleColor.Red);
Utils.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", ConsoleColor.Red);
// here you can log the exception ...
}
static bool ConsoleEventCallback(int eventType)
{
int CTRL_C_EVENT = 0;
int CTRL_BREAK_EVENT = 1;
int CTRL_CLOSE_EVENT = 2;
int CTRL_LOGOFF_EVENT = 5;
int CTRL_SHUTDOWN_EVENT = 6;
if (eventType == CTRL_C_EVENT || eventType == CTRL_BREAK_EVENT || eventType == CTRL_CLOSE_EVENT
|| eventType == CTRL_LOGOFF_EVENT || eventType == CTRL_SHUTDOWN_EVENT)
{
SafeMobileLib.Utils.WriteLine("Console window closing, death imminent");
SafeMobileLib.Utils.WriteEventLog("SafeMobile", "SafeDispatch is closing, death imminent", EventLogEntryType.Warning, 21522);
// check if the main form was initiated and an invoke is required
MainForm2.CloseNotifyIcon();
}
return false;
}
static ConsoleEventDelegate handler; // Keeps it from getting garbage collected
// Pinvoke
private delegate bool ConsoleEventDelegate(int eventType);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
}
}