private async void Application_Startup(object sender, StartupEventArgs e) { try { _splash = new Controls.SplashScreen(); _splash.Show(); if (Program.StartupArgs["noupdate"] != "1" && !Program.StartupArgs.AllKeys.Contains("disable-updates")) { await StartUpdater(); return; } SetProgress("Getting configuration..."); var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var pluginsPath = Path.Combine(basePath, "ibt-plugins"); if (!Directory.Exists(pluginsPath)) { pluginsPath = Path.Combine(new DirectoryInfo(basePath).Parent.Parent.Parent.Parent.Parent.Parent.FullName, "Modules"); } var kernel = new StandardKernel(); var serializer = new PanaceaSerializer(); kernel.Bind <ISerializer>().ToConstant(serializer); _logger = new EventViewerLogger("Panacea"); kernel.Bind <ILogger>().ToConstant(_logger); _logger.Info(this, "Hi!"); var identification = new TerminalIdentifier(serializer); var putik = await identification.GetIdentifierAsync(); _settings = new PanaceaRegistrySettingsManager(serializer); var cache = new SqLiteNetworkCache(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "cache"), "cache.db"); var httpClient = new HttpClient( new Uri((await _settings.GetRegistrationInfo()).HospitalServer), 0, cache, serializer, _logger); var userService = new UserService(httpClient, _logger); httpClient.AddMiddleware(new UserAuthenticationMiddleware(userService)); httpClient.AddMiddleware(new TerminalIdentificationMiddleware(putik)); var loader = new PluginLoader(kernel, _logger); var webSocket = new WebSocketCommunicator(putik); webSocket.Connect(); await userService.LoginFromFileAsync(); _core = new PanaceaServices(httpClient, userService, loader, _logger, webSocket, serializer); kernel.Bind <PanaceaServices>().ToConstant(_core); var dir = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); var pluginsToLoad = (await GetPluginsAsync()).ToList(); var exclude = new List <string>(); if (Program.StartupArgs["exclude"] != null) { exclude = Program.StartupArgs["exclude"].ToLower().Split(',').ToList(); } if (Program.StartupArgs["include"] != null) { var letters = Program.StartupArgs["include"].ToLower().Split(','); pluginsToLoad = pluginsToLoad.Concat(letters).ToList(); } //if (Debugger.IsAttached) //{ // new DevConsole(logger).Show(); //} //Console.WriteLine("-------------"); var watch = new Stopwatch(); watch.Start(); SetProgress("Loading plugins..."); var args = await MergeParametersAsync(e.Args.ToList()); await loader.LoadPlugins(pluginsPath, pluginsToLoad, exclude, args.ToArray()); watch.Stop(); _logger.Info(this, $"Time to load plugins: {watch.ElapsedMilliseconds.ToString()}ms"); _splash.Close(); _splash = null; } catch (Exception ex) { SetProgress(ex.Message); await Task.Delay(5000); ShutDownSafe(); } }