Example #1
0
        public AdvancedBootloader(bool isHosting, WebServerOptions webServerOptions, IConfiguration configuration)
        {
            OneDasOptions   options;
            ExtensionLoader extensionLoader;

            _isHosting        = isHosting;
            _webServerOptions = webServerOptions;
            _configuration    = configuration;

            if (isHosting)
            {
                _webhost         = this.CreateWebHost();
                _serviceProvider = _webhost.Services;

                // create directories
                options = _serviceProvider.GetRequiredService <IOptions <OneDasOptions> >().Value;

                Directory.CreateDirectory(options.BackupDirectoryPath);
                Directory.CreateDirectory(options.ConfigurationDirectoryPath);
                Directory.CreateDirectory(options.DataDirectoryPath);
                Directory.CreateDirectory(options.NugetDirectoryPath);
                Directory.CreateDirectory(options.ProjectDirectoryPath);

                // client push service
                AdvancedBootloader.ClientPushService = _serviceProvider.GetRequiredService <ClientPushService>();

                // extension loader
                extensionLoader = _serviceProvider.GetRequiredService <ExtensionLoader>();
                extensionLoader.ReloadPackages();

                // create engine
                _engine = _serviceProvider.GetRequiredService <OneDasEngine>();
            }
            else
            {
                _serviceCollection = new ServiceCollection();
                this.ConfigureServices(_serviceCollection);
                _serviceProvider = _serviceCollection.BuildServiceProvider();
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            bool                  isHosting;
            string                configurationFileName;
            IConfigurationRoot    configurationRoot;
            IConfigurationBuilder configurationBuilder;

            Thread.CurrentThread.Name         = "Main thread";
            BasicBootloader.IsUserInteractive = !args.Contains("--non-interactive");

            // configuration
            BasicBootloader.ConfigurationDirectoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "OneDAS", "Core");
            configurationFileName = "settings.json";

            Directory.CreateDirectory(BasicBootloader.ConfigurationDirectoryPath);

            configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddJsonFile(new PhysicalFileProvider(BasicBootloader.ConfigurationDirectoryPath), path: configurationFileName, optional: true, reloadOnChange: true);
            configurationRoot = configurationBuilder.Build();

            _options = configurationRoot.Get <WebServerOptions>();

            if (_options == null)
            {
                _options = new WebServerOptions();
                configurationRoot.Bind(_options);
            }

            if (!Directory.Exists(_options.BaseDirectoryPath))
            {
                _options.BaseDirectoryPath = BasicBootloader.ConfigurationDirectoryPath;
            }

            if (string.IsNullOrWhiteSpace(_options.NewBaseDirectoryPath))
            {
                _options.NewBaseDirectoryPath = _options.BaseDirectoryPath;
            }
            else if (!string.Equals(_options.BaseDirectoryPath, _options.NewBaseDirectoryPath, StringComparison.OrdinalIgnoreCase))
            {
                _options.BaseDirectoryPath = _options.NewBaseDirectoryPath;
            }

            _options.Save(BasicBootloader.ConfigurationDirectoryPath);

            // determine startup mode
            if (BasicBootloader.IsUserInteractive && BasicBootloader.GetOneDasServiceStatus() > 0)
            {
                isHosting = false;
            }
            else
            {
                if (!WebServerUtilities.EnsureSingeltonInstance(new Guid(_options.MutexName)))
                {
                    Environment.Exit(0);
                }

                isHosting = true;
            }

            // create advanced bootloader
            _advancedBootloader = new AdvancedBootloader(isHosting, _options, configurationRoot);

            // logging
            BasicBootloader.SystemLogger = _advancedBootloader.CreateSystemLogger();

            // exception handling
            AppDomain.CurrentDomain.UnhandledException += BasicBootloader.CurrentDomain_UnhandledException;

            // run
            _advancedBootloader.Run();

            // shutdown
            BasicBootloader.Shutdown(0);
        }