Ejemplo n.º 1
0
        public void CanLoadConfigurationFromGlobalAndUserRepositoryUsingShortAndLongName()
        {
            var userConfigurationDirectory   = "user-configuration".AsNewDirectoryInfo();
            var systemConfigurationDirectory = "temp-configuration".AsNewDirectoryInfo();

            var systemConfiguration = new SampleConfigurationWithDefaultValues()
            {
                Value = 10, SecondValue = 200
            };
            var userConfiguration = new { Value = 20 };

            WriteConfiguration <SampleConfigurationWithDefaultValues>(userConfigurationDirectory, userConfiguration, true);
            WriteConfiguration <SampleConfigurationWithDefaultValues>(systemConfigurationDirectory, systemConfiguration);

            var container            = new CompositionContainer();
            var configurationCatalog = new LoadConfiguration(systemConfigurationDirectory, container);

            configurationCatalog.AddConfigurationLocation(userConfigurationDirectory);

            configurationCatalog.Load();
            var conf = container.GetExportedValue <SampleConfigurationWithDefaultValues>();

            Assert.Equal(20, conf.Value);
            Assert.Equal(200, conf.SecondValue);
        }
Ejemplo n.º 2
0
 private void editConfigItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
 {
     try
     {
         if (gv.GetFocusedRow() == null)
         {
             return;
         }
         var loadConfigCommand = new LoadConfiguration();
         var userConfig        = (GrabConfiguration)gv.GetFocusedRow();
         var configFromDisk    = loadConfigCommand.Execute(userConfig.Path);
         var frm        = new UserConfigForm();
         var editResult = frm.Edit(configFromDisk);
         if (editResult != null)
         {
             var handle         = gv.FocusedRowHandle;
             var configurations = (BindingList <GrabConfiguration>)grid.DataSource;
             var currentIndex   = configurations.IndexOf(userConfig);
             configurations.Insert(currentIndex, editResult);
             configurations.Remove(userConfig);
             gv.FocusedRowHandle = handle;
             grid.RefreshDataSource();
         }
     }
     catch (Exception ex)
     {
         Log.Error(string.Format("Failed to edit user configuration.{0}{1}", Environment.NewLine, ex.Message), ex);
         XtraMessageBox.Show(string.Format("Failed to edit user configuration.{0}{1}", Environment.NewLine, ex.Message), "Error");
     }
     finally
     {
         navBarControl.Enabled = true;
         SplashManager.CloseSplashScreen();
     }
 }
Ejemplo n.º 3
0
 public static void Main(string[] args)
 {
     LoadConfiguration.Load();
     SystemClock.GetInstance();
     //new SystemClock(); --Singleton, autorun
     BuildWebHost(args).Run();
 }
        protected DBConfig()
        {
            var config = LoadConfiguration.Load().GetConfiguration;

            _relational  = config["ConnectionStrings:RelationalSchema"];
            _dimensional = config["ConnectionStrings:DimensionalSchema"];
            _eventStore  = config["ConnectionStrings:EventstoreSchema"];
        }
        public RabbitMqConfigParams()
        {
            var config = LoadConfiguration.Load().GetConfiguration;

            Username = config["RabbitMQ:Username"];
            Password = config["RabbitMQ:Password"];
            Hostname = config["RabbitMQ:Hostname"];
            Port     = int.Parse(config["RabbitMQ:Port"]);
        }
Ejemplo n.º 6
0
        public void CanLoadShortcutConfiguration()
        {
            var container            = new CompositionContainer();
            var configurationCatalog = new LoadConfiguration(new DirectoryInfo(_PathToDebugConfiguration), container);

            configurationCatalog.Load();

            var conf = container.GetExportedValue <Configuration>();

            Assert.Contains(@"%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu", conf.Directories);
        }
Ejemplo n.º 7
0
        public WebFrequenciesDbContext CreateDbContext(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder <WebFrequenciesDbContext>();

            var config            = LoadConfiguration.Configure().Build();
            var connectionStrings = config[$"{nameof(ConnectionStrings)}:{nameof(ConnectionStrings.HtmlAnalysisDb)}"];

            optionsBuilder.UseSqlServer(connectionStrings);

            return(new WebFrequenciesDbContext(optionsBuilder.Options));
        }
Ejemplo n.º 8
0
        public void RequestingNotFoundConfigurationShouldLoadANewlyCreatedConfiguration()
        {
            var container = new CompositionContainer(new AssemblyCatalog(this.GetType().Assembly));

            var configurationDirectory = "temp-configuration".AsNewDirectoryInfo();

            var configurationCatalog = new LoadConfiguration(configurationDirectory, container);

            configurationCatalog.Load();

            var conf = container.GetExportedValue <SampleConfigurationWithDefaultValues>();

            Assert.Equal(5, conf.Value);
        }
Ejemplo n.º 9
0
        public void ReloadingConfigurationShouldNotDuplicateEntries()
        {
            var container            = new CompositionContainer();
            var configurationCatalog = new LoadConfiguration(new DirectoryInfo(_PathToDebugConfiguration), container);

            configurationCatalog.Load();

            var conf  = container.GetExportedValue <Configuration>();
            var count = conf.Directories.Count;

            configurationCatalog.Load();
            Assert.Equal(count, conf.Directories.Count);
            Assert.Contains(@"%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu", conf.Directories);
        }
Ejemplo n.º 10
0
        public void ShouldIgnoreReadmeFile()
        {
            var configurationDirectory = "temp-configuration".AsNewDirectoryInfo();
            var container = new CompositionContainer(new AssemblyCatalog(this.GetType().Assembly));

            File.WriteAllText(Path.Combine(configurationDirectory.FullName, "readme.txt"), "Text");
            var configurationCatalog = new LoadConfiguration(configurationDirectory, container);

            configurationCatalog.Load();

            var conf = container.GetExportedValue <SampleConfigurationWithDefaultValues>();

            Assert.Equal(5, conf.Value);
        }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            var config = LoadConfiguration.Configure().Build();

            var host = BuildWebHostBuilder(args, config);

            using (var scope = host.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetService <WebFrequenciesDbContext>();

                context.Database.Migrate();
            }

            host.Run();
        }
Ejemplo n.º 12
0
 public static IHost BuildWebHostBuilder(string[] args, IConfiguration config)
 {
     return(Host.CreateDefaultBuilder(args)
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .ConfigureAppConfiguration(configBuilder =>
     {
         configBuilder = LoadConfiguration.Configure();
     })
            .ConfigureWebHostDefaults(webHostBuilder =>
     {
         webHostBuilder
         .UseConfiguration(config)
         .UseStartup <Startup>();
     })
            .Build());
 }
Ejemplo n.º 13
0
        public void RequestingStoredConfigurationWithADefaultTypeAlreadyRegisteredShouldReturnStoredConfiguration()
        {
            var configurationDirectory = "temp-configuration".AsNewDirectoryInfo();
            var conf = new SampleConfigurationWithDefaultValues()
            {
                Value = 10
            };

            WriteConfiguration <SampleConfigurationWithDefaultValues>(configurationDirectory, conf);

            var container            = new CompositionContainer(new AssemblyCatalog(this.GetType().Assembly));
            var configurationCatalog = new LoadConfiguration(configurationDirectory, container);

            configurationCatalog.Load();

            conf = container.GetExportedValue <SampleConfigurationWithDefaultValues>();
            Assert.Equal(10, conf.Value);
        }
Ejemplo n.º 14
0
        private static X509Certificate2 LoadCertificate(IHostingEnvironment environment)
        {
            if (MainConfig.Connection.SSL.SerialNumb != null)
            {
                using (var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine))
                {
                    var SSLMatch = new Regex("[^a-fA-F0-9]");
                    store.Open(OpenFlags.ReadOnly);
                    var certificate = store.Certificates.Find(
                        X509FindType.FindBySerialNumber,
                        SSLMatch.Replace(MainConfig.Connection.SSL.SerialNumb, string.Empty).ToUpper(),
                        validOnly: true);


                    if (certificate.Count == 0)
                    {
                        LoadConfiguration.CloseApp($"Certificate not found for serial number {MainConfig.Connection.SSL.SerialNumb}.");
                    }

                    return(certificate[0]);
                }
            }

            if (MainConfig.Connection.SSL?.PathFile != null && MainConfig.Connection.SSL?.Password != null)
            {
                try
                {
                    return(new X509Certificate2(MainConfig.Connection.SSL.PathFile, MainConfig.Connection.SSL.Password));
                }
                catch (Exception ex)
                {
                    LoadConfiguration.CloseApp($"Error read certificate: {ex.Message}");
                }
            }

            LoadConfiguration.CloseApp("No valid certificate configuration found for the current endpoint.");
            throw new InvalidOperationException("No valid certificate configuration found for the current endpoint.");
        }
Ejemplo n.º 15
0
        public static void ConfigureEndpoints(this KestrelServerOptions options)
        {
            if (MainConfig.Connection.SSL != null)
            {
                try
                {
                    DeserializeObject.IsValid(MainConfig.Connection.SSL);
                }
                catch (Exception ex)
                {
                    LoadConfiguration.CloseApp(ex.Message);
                }

                var environment = options.ApplicationServices.GetRequiredService <IHostingEnvironment>();

                options.Listen(IPAddress.Parse(MainConfig.Connection.SSL.IP), MainConfig.Connection.Port,
                               listenOptions =>
                {
                    var certificate = LoadCertificate(environment);
                    listenOptions.UseHttps(certificate);
                });
            }
        }
Ejemplo n.º 16
0
        private void editSelectedWebGrabConfigItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            var userConfig = (GrabConfiguration)gv.GetFocusedRow();

            if (userConfig != null)
            {
                if (!AskQuestion(string.Format("Edit grabbing settings for {0}?", userConfig.Name)))
                {
                    return;
                }
                try
                {
                    var loadConfigCommand = new LoadConfiguration();
                    var configFromDisk    = loadConfigCommand.Execute(userConfig.Path);
                    var frm = new WebGrabConfigForm(configFromDisk.Config, null);
                    if (frm.Edit())
                    {
                        var handle         = gv.FocusedRowHandle;
                        var configurations = (BindingList <GrabConfiguration>)grid.DataSource;
                        var currentIndex   = configurations.IndexOf(userConfig);
                        configurations.Insert(currentIndex, configFromDisk);
                        configurations.Remove(userConfig);
                        gv.FocusedRowHandle = handle;
                        grid.RefreshDataSource();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("Edit failed.{0}{1}", Environment.NewLine, ex.Message), ex);
                    XtraMessageBox.Show(string.Format("Edit failed.{0}{1}", Environment.NewLine, ex.Message), "Error");
                }
                finally
                {
                    SplashManager.CloseSplashScreen();
                }
            }
        }
Ejemplo n.º 17
0
        protected override void ConfigureContainer(ContainerBuilder builder)
        {
            base.ConfigureContainer(builder);

            var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var catalogs = new List <ComposablePartCatalog>
            {
                new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x))),
                new DirectoryCatalog(assemblyDirectory, "Plugins.*.dll"),
                new DirectoryCatalog(assemblyDirectory, "Plugins.dll"),
                new AssemblyCatalog(typeof(IItem).Assembly)
            };

            var pluginsPath = Path.Combine(assemblyDirectory, "Plugins");

            if (Directory.Exists(pluginsPath))
            {
                catalogs.Add(new DirectoryCatalog(pluginsPath, "Plugins.*.dll"));
                catalogs.Add(new DirectoryCatalog(pluginsPath, "Plugins.dll"));
            }
            else
            {
                pluginsPath = assemblyDirectory;
            }

            MefContainer =
                CompositionHost.Initialize(catalogs.ToArray());

            var loadConfiguration =
                new LoadConfiguration(new DirectoryInfo(Path.Combine(assemblyDirectory, "Configuration")), MefContainer);
            var localConfigurationDirectory = new DirectoryInfo(Path.Combine(assemblyDirectory, "Local.Configuration"));

            if (localConfigurationDirectory.Exists)
            {
                loadConfiguration.AddConfigurationLocation(localConfigurationDirectory);
            }
            loadConfiguration.Load();

            var dataDirectory     = Path.Combine(assemblyDirectory, "Data");
            var coreConfiguration = new CoreConfiguration(dataDirectory, pluginsPath);

            var learningStorageLocation = new DirectoryInfo(Path.Combine(coreConfiguration.DataDirectory, "Learnings"));
            var indexStorageLocation    = new DirectoryInfo(Path.Combine(coreConfiguration.DataDirectory, "Index"));

            var updateManagerAdapter = new UpdateManagerAdapter();

            var scheduler = new StdSchedulerFactory().GetScheduler();

            scheduler.JobFactory = new MefJobFactory(new SimpleJobFactory(), MefContainer);

            var batch = new CompositionBatch();

            batch.AddExportedValue(MefContainer);
            batch.AddExportedValue <ILoadConfiguration>(loadConfiguration);
            batch.AddExportedValue <ILog>(new NLogAdapterToCoreILog(NLog.LogManager.GetLogger("mef")));
            batch.AddExportedValue(coreConfiguration);
            batch.AddExportedValue(updateManagerAdapter);
            batch.AddExportedValue <IScheduler>(scheduler);
            MefContainer.Compose(batch);

            MefContainer.SatisfyImportsOnce(updateManagerAdapter);

            builder.RegisterInstance(MefContainer).AsSelf();
            builder.RegisterInstance(coreConfiguration).AsSelf();
            builder.RegisterInstance(updateManagerAdapter).AsSelf();

            builder.RegisterInstance(scheduler).As <IScheduler>();
            builder.RegisterInstance <IWindowManager>(new WindowManager());
            builder.RegisterInstance <IEventAggregator>(new EventAggregator());

            builder.RegisterModule(new LoggingModule(t => new NLogAdapterToCoreILog(NLog.LogManager.GetLogger(t.FullName)),
                                                     t => NLog.LogManager.GetLogger(t.FullName)));
            builder.RegisterModule(new SatisfyMefImports(MefContainer));

            builder.RegisterType <MainWindowViewModel>().AsSelf();
            builder.RegisterType <AutoCompleteBasedOnLucene>().AsSelf();
            builder.RegisterType <GetActionsForItem>().As <IGetActionsForItem>();

            builder.RegisterType <ConverterRepository>().As <IConverterRepository>();

            builder.RegisterType <SourceStorageFactory>().AsSelf().SingleInstance();

            builder.RegisterType <FileSystemLearningRepository>().As <ILearningRepository>().WithParameter("input", learningStorageLocation);
            builder.RegisterType <ScheduleIndexJobs>().As <IStartupTask>();
            builder.RegisterType <ScheduleUpdateCheckJob>().As <IStartupTask>();
            builder.RegisterType <IronPythonCommandsMefExport>().As <IStartupTask>();
            builder.RegisterType <LogScheduledJobs>().As <IStartupTask>();
            builder.RegisterType <ProcessMonitor>().As <IStartupTask>();

            builder.RegisterType <Shutdown>().AsSelf();

            builder.RegisterType <SeparateIndexesDirectoryFactory>()
            .As <IDirectoryFactory>().WithParameter("root", indexStorageLocation)
            .SingleInstance();
        }
Ejemplo n.º 18
0
 private void OnLoadConfiguration()
 {
     LoadConfiguration?.Invoke(this, EventArgs.Empty);
 }