protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (CheckForDuplicateProcess()) { MessageBox.Show("Server Density is already running. Click its icon in the system tray to view your configuration.", "Server Density", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); return; } AgentConfiguration config = AgentConfiguration.Load(); _url.Text = config.Url; _agentKey.Text = config.AgentKey; _iis.Checked = config.IISChecks; _pluginDirectory.Text = config.PluginDirectory; _plugins.Checked = !string.IsNullOrEmpty(config.PluginDirectory); _mongoDBConnectionString.Text = config.MongoDBConnectionString; _mongoDB.Checked = !string.IsNullOrEmpty(config.MongoDBConnectionString); _dbStats.Checked = config.MongoDBDBStats; _replSet.Checked = config.MongoDBReplSet; _sqlServer.Checked = config.SQLServerChecks; _customPrefix.Checked = !string.IsNullOrEmpty(config.CustomPrefix); _customPrefixValue.Text = config.CustomPrefix; _eventViewer.Checked = config.EventViewer; // Initialise and start the background update checker. _updater = new Updater(); _updater.UpdatesDetected += Updater_UpdatesDetected; _updater.Start(); }
public void Start() { if (isStarted) { throw new Exception("Agent has already been started!"); } isStarted = true; Log.Debug("Starting Agent..."); // Load existing or default agent configuration AgentConfiguration.Load(); UserMgr.Directory = Configuration.Directory; SecurityTest.Initialize(UserMgr); ApplicationMgr.Initialize(); if (!IPAddress.TryParse(AgentConfiguration.Value.Tcp.Host, out var _address)) { throw new Exception($"Invalid TCP Host '{AgentConfiguration.Value.Tcp.Host}'!"); } Http.Initialize(); MessageRegistry.Scan(Assembly.GetExecutingAssembly()); MessageRegistry.Scan(typeof(ILibraryAssembly).Assembly); MessageRegistry.Scan(typeof(IFrameworkAssembly).Assembly); messageListener.Listen(_address, AgentConfiguration.Value.Tcp.Port); Sessions.Start(); var taskVariables = Task.Run(() => Variables.Load(Configuration.VariablesDirectory)); var taskRepositories = Task.Run(() => RepositorySources.Initialize()); var taskHttp = Task.Run(() => Http.Start()); Task.WaitAll( taskVariables, taskRepositories, taskHttp); Log.Info("Agent started."); }