/// <summary> /// Constructor /// </summary> /// <param name="args">Args</param> /// <param name="rootDirectory">Root directory</param> /// <param name="config">Configuration</param> /// <param name="mailService">Mail service</param> public MailDemonWebApp(string[] args, string rootDirectory, IConfigurationRoot config, MailDemonService mailService) { Args = args; RootDirectory = rootDirectory; Configuration = config; this.mailService = mailService; Instance = this; }
private Task Run(string[] args) { Console.CancelKeyPress += Console_CancelKeyPress; // read config string rootDir = Directory.GetCurrentDirectory(); IConfigurationBuilder configBuilder = new ConfigurationBuilder().SetBasePath(rootDir); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development" && File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.Development.json"))) { configBuilder.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.Development.json")); } else { configBuilder.AddJsonFile("appsettings.json"); } IConfigurationRoot config = configBuilder.Build(); CertificateCache cache = new CertificateCache(config); // singleton // start mail server mailService = new MailDemonService(args, config); Task mailTask = mailService.StartAsync(cancel.Token); MailDemonLog.Info("Mail demon running"); // test sending with the server: // test localhost [email protected],[email protected] [full path to file to attach] if (args.Length > 0 && args[0].StartsWith("test", StringComparison.OrdinalIgnoreCase)) { mailService.DisableSending = true; string file = args.Length > 2 ? args[3] : null; if (file != null) { TestClientConnectionAsync(mailService, args[1], args[2], file).ConfigureAwait(false).GetAwaiter().GetResult(); TestClientConnectionAsync(mailService, args[1], args[2], file).ConfigureAwait(false).GetAwaiter().GetResult(); } args = new string[0]; } // start web server webApp = new MailDemonWebApp(args, rootDir, config, mailService); Task webTask = webApp.StartAsync(cancel.Token); return(Task.WhenAll(mailTask, webTask)); }