public void Initialize() { var services = new ServiceCollection(); services.AddSingleton(ins => ConfigurationHandler.GetAppConfiguration()); var databaseManager = new MSSQLManager(ConfigurationHandler.GetConfiguration()); services.AddSingleton(provider => databaseManager); ServiceLocator.SetLocatorProvider(services.BuildServiceProvider()); }
public static async Task Main(string[] args) { NLog.LogManager.LoadConfiguration("nlog.config"); starter = new AutoStarter(ApplicationLogging.LoggerFactory, "Sentiment analysis", args); starter.LoggerFactory.AddNLog(); starter.RegisterCommand <TestingCommand, TestingConfig>("test"); starter.RegisterCommand <TrainCommand, TrainingConfig>("train"); starter.RegisterCommand <BoostrapCommand, BootsrapConfig>("boot"); var configuration = new ConfigurationHandler(); var resourcesPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), configuration.GetConfiguration("Resources")); if (Directory.Exists(resourcesPath)) { log.LogInformation("Resources folder {0} found.", resourcesPath); } else { var dataDownloader = new DataDownloader(ApplicationLogging.LoggerFactory); Task download = dataDownloader.DownloadFile(new Uri(configuration.GetConfiguration("dataset")), resourcesPath); await download.ConfigureAwait(false); } #if NET472 var fPreviousExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED); if (fPreviousExecutionState == 0) { log.LogError("SetThreadExecutionState failed."); return; } #endif try { source = new CancellationTokenSource(); task = starter.StartAsync(source.Token); System.Console.WriteLine("Please press CTRL+C to break..."); System.Console.CancelKeyPress += ConsoleOnCancelKeyPress; await starter.Status.LastOrDefaultAsync(); System.Console.WriteLine("Exiting..."); } catch (Exception e) { System.Console.WriteLine(e); } }