/// <summary> /// The service control manager has requested us to start /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { Log.Debug("OnStart subroutine Starting..."); AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptions); var dbConnectionStatus = Common.TestConnection(); if (dbConnectionStatus.Success) { Log.Info("Verified successful connection to database."); } else { Log.Fatal("Unable to connect to database: " + dbConnectionStatus.CaughtException.Message); return; } try { Common.InitialiseLogFolder(); DeleteStoreFiles(); } catch (Exception ex) { Log.Fatal("Error getting registry settings and/or deleting logs: " + ex.Message, ex); } Log.Info("Removing Orphaned Methods"); OSAEMethodManager.ClearMethodQueue(); try { OSAE.OSAESql.RunSQL("SET GLOBAL event_scheduler = ON;"); } catch (Exception ex) { Log.Fatal("Error setting the event scheduler: " + ex.Message, ex); } checkLog = new System.Timers.Timer(60000); checkLog.Elapsed += checkLogEvent; checkLog.Enabled = true; // Start the network service so messages can be // received by the service StartNetworkListener(); // Start the threads that monitor the plugin // updates check the method queue and so on StartThreads(serviceObject); }
/// <summary> /// Public Constructor for WindowsService. /// - Put all of your Initialization code here. /// </summary> public OSAEService() { serviceObject = CheckServiceObject(); if (serviceObject == null) { Log = new General.OSAELog("Faulted Service"); Log.Fatal("Failed to retrieve Service's Object!"); } //else // OSAE.OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject); Log = new General.OSAELog(serviceObject); Log.Info("Service Starting"); Common.CheckComputerObject(serviceObject); OSAEObject obj = OSAEObjectManager.GetObjectByName(serviceObject); OSAEObjectManager.ObjectUpdate(serviceObject, serviceObject, obj.Address, obj.Description, obj.Type, obj.Address, Common.ComputerName, obj.MinTrustLevel, obj.Enabled); InitialiseOSAInEventLog(); // These Flags set whether or not to handle that specific type of event. Set to true if you need it, false otherwise. CanStop = true; CanShutdown = true; }
private void Domain_UnhandledException(object source, System.UnhandledExceptionEventArgs e) { Log.Fatal(PluginName + " plugin has fatally crashed. ERROR: \n" + e.ExceptionObject.ToString()); AppDomain.Unload(_domain); }