public static bool Enabled()
        {
            var environmentProvider = new EnvironmentProvider();
            var configFileProvider  = new ConfigFileProvider(environmentProvider);

            return(configFileProvider.EnableProfiler);
        }
示例#2
0
        public async Task Execute_With_NonExisting_Config_Asks_To_Create_It(
            bool solutionLoaded,
            string configPath,
            [Frozen] IFileAccessor fileAccessor,
            [Frozen][Substitute] IPopupManager popupManager,
            [Frozen][Substitute] ConfigFileProvider configFileProvider,
            Fixture fixture
            )
        {
            // Arrange
            IoC.Container.Inject(popupManager);
            var sut    = getSut(fixture, configFileProvider, fileAccessor, configPath, solutionLoaded);
            var called = false;

            // Act
            await sut.ExecuteAsync(s =>
            {
                called = true;
                return(Task.CompletedTask);
            });

            // Assert
            called.ShouldBeFalse();
            popupManager.Received().Confirm(Arg.Any <string>(), Arg.Any <string>());
        }
示例#3
0
        public async Task Response_To_Popup_Should_Open_File(
            bool solutionLoaded,
            string configPath,
            bool userWantsToCreateFile,
            [Frozen] IFileAccessor fileAccessor,
            [Frozen][Substitute] IPopupManager popupManager,
            [Frozen][Substitute] ConfigFileProvider configFileProvider,
            Fixture fixture
            )
        {
            // Arrange
            popupManager.Configure().Confirm(Arg.Any <string>(), Arg.Any <string>()).Returns(userWantsToCreateFile);
            IoC.Container.Inject(popupManager);
            var sut    = getSut(fixture, configFileProvider, fileAccessor, configPath, solutionLoaded);
            var called = false;

            // Act
            await sut.ExecuteAsync(s =>
            {
                called = true;
                return(Task.CompletedTask);
            });

            // Assert
            var expectedResult = userWantsToCreateFile;

            called.ShouldBe(expectedResult);
            popupManager.Received().Confirm(Arg.Any <string>(), Arg.Any <string>());
        }
示例#4
0
 public SysTrayApp(ConfigFileProvider configFileProvider, ProcessProvider processProvider,
                   IISProvider iisProvider, EnvironmentProvider environmentProvider)
 {
     _configFileProvider  = configFileProvider;
     _processProvider     = processProvider;
     _iisProvider         = iisProvider;
     _environmentProvider = environmentProvider;
 }
示例#5
0
 public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider,
                           HttpProvider httpProvider, ConfigFileProvider configFileProvider)
 {
     _processProvider    = processProvider;
     _iisProvider        = iisProvider;
     _httpProvider       = httpProvider;
     _configFileProvider = configFileProvider;
 }
示例#6
0
 public SysTrayApp(ConfigFileProvider configFileProvider, ProcessProvider processProvider,
                   IISProvider iisProvider, EnvironmentProvider environmentProvider)
 {
     _configFileProvider = configFileProvider;
     _processProvider = processProvider;
     _iisProvider = iisProvider;
     _environmentProvider = environmentProvider;
 }
示例#7
0
        public void TestConfigFileReaderAndFileWatcher()
        {
            var file = Path.Combine(Fixture.ContentRoot, "config", $"{Guid.NewGuid()}.json");

            //Create JSON
            var data = new TestServiceConfig
            {
                TestServiceAConfig = new TestServiceAConfig()
                {
                    A = "AAA"
                },
                TestServiceBConfig = new TestServiceBConfig()
                {
                    B = "BBB"
                },
                TestServiceCConfig = new TestServiceCConfig()
                {
                    C = "CCC"
                }
            };

            WriteConfigFile(file, data);

            var provider = new ConfigFileProvider <TestServiceConfig>(Fixture.LoggerFactory, file);

            Assert.NotNull(provider.Get());
            Assert.Equal(data.TestServiceAConfig.A, provider.Get().TestServiceAConfig.A);
            Assert.Equal(data.TestServiceBConfig.B, provider.Get().TestServiceBConfig.B);
            Assert.Equal(data.TestServiceCConfig.C, provider.Get().TestServiceCConfig.C);

            var configChangeEventTriggered = 0;

            //Now: Register Change listener and edit the file.
            provider.ConfigChangedEvent += (sender, args) =>
            {
                configChangeEventTriggered++;
                Assert.NotNull(args.NewValue);
                Assert.NotEqual("AAA", provider.Get().TestServiceAConfig.A);
                Assert.Equal("BBB", provider.Get().TestServiceBConfig.B);
                Assert.Equal("CCC", provider.Get().TestServiceCConfig.C);
            };

            data.TestServiceAConfig.A = "foo";
            WriteConfigFile(file, data);

            var maxIter = 0;

            while (configChangeEventTriggered == 0 && maxIter < 20)
            {
                maxIter++;
                Thread.Sleep(500);
            }

            Assert.Equal(1, configChangeEventTriggered);
        }
示例#8
0
 public AppUpdateJob(UpdateProvider updateProvider, EnvironmentProvider environmentProvider, DiskProvider diskProvider,
                     HttpProvider httpProvider, ProcessProvider processProvider, ArchiveProvider archiveProvider, ConfigFileProvider configFileProvider)
 {
     _updateProvider      = updateProvider;
     _environmentProvider = environmentProvider;
     _diskProvider        = diskProvider;
     _httpProvider        = httpProvider;
     _processProvider     = processProvider;
     _archiveProvider     = archiveProvider;
     _configFileProvider  = configFileProvider;
 }
示例#9
0
        OpenGenerateLocalConfigViewModel getSut(Fixture fixture, ConfigFileProvider configFileProvider, IFileAccessor fileAccessor, string configPath, bool fileExists)
        {
            configFileProvider.Configure().TryGetLocalConfigAsync().Returns(configPath);
            fileAccessor.Exists(Arg.Any <string>()).ReturnsForAnyArgs(fileExists);

            IoC.Container.EjectAllInstancesOf <IConfigFileProvider>();
            IoC.Container.Inject <IConfigFileProvider>(configFileProvider);

            IoC.Container.EjectAllInstancesOf <IFileAccessor>();
            IoC.Container.Inject <IFileAccessor>(fileAccessor);

            return(fixture.Create <OpenGenerateLocalConfigViewModel>());
        }
示例#10
0
        public async Task Command_Is_Enabled_Based_On_Solution_Loaded(
            bool solutionLoaded,
            string configPath,
            [Frozen] IFileAccessor fileAccessor,
            [Frozen][Substitute] ConfigFileProvider configFileProvider,
            Fixture fixture
            )
        {
            var sut = getSut(fixture, configFileProvider, fileAccessor, configPath, solutionLoaded);

            var expectedEnabledState = solutionLoaded;

            (await sut.IsCommandEnabledAsync()).ShouldBe(expectedEnabledState);
        }
示例#11
0
 public ApplicationServer(ConfigFileProvider configFileProvider, IISProvider iisProvider,
                          DebuggerProvider debuggerProvider, EnvironmentProvider environmentProvider,
                          ProcessProvider processProvider, MonitoringProvider monitoringProvider,
                          SecurityProvider securityProvider, DiskProvider diskProvider)
 {
     _configFileProvider  = configFileProvider;
     _iisProvider         = iisProvider;
     _debuggerProvider    = debuggerProvider;
     _environmentProvider = environmentProvider;
     _processProvider     = processProvider;
     _monitoringProvider  = monitoringProvider;
     _securityProvider    = securityProvider;
     _diskProvider        = diskProvider;
 }
示例#12
0
        public HostConfigModule(ConfigFileProvider configFileProvider)
            : base("/config/host")
        {
            _configFileProvider = configFileProvider;

            GetResourceSingle = GetHostConfig;
            GetResourceById   = GetHostConfig;
            UpdateResource    = SaveHostConfig;

            SharedValidator.RuleFor(c => c.Branch).NotEmpty().WithMessage("Branch name is required, 'master' is the default");
            SharedValidator.RuleFor(c => c.Port).InclusiveBetween(1, 65535);

            SharedValidator.RuleFor(c => c.Username).NotEmpty().When(c => c.AuthenticationEnabled);
            SharedValidator.RuleFor(c => c.Password).NotEmpty().When(c => c.AuthenticationEnabled);

            SharedValidator.RuleFor(c => c.SslPort).InclusiveBetween(1, 65535).When(c => c.EnableSsl);
            SharedValidator.RuleFor(c => c.SslCertHash).NotEmpty().When(c => c.EnableSsl);
        }
示例#13
0
 public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider,
                           QualityProvider qualityProvider, AutoConfigureProvider autoConfigureProvider,
                           SeriesProvider seriesProvider, ExternalNotificationProvider externalNotificationProvider,
                           QualityTypeProvider qualityTypeProvider, ConfigFileProvider configFileProvider,
                           NewznabProvider newznabProvider, MetadataProvider metadataProvider,
                           JobProvider jobProvider)
 {
     _externalNotificationProvider = externalNotificationProvider;
     _qualityTypeProvider          = qualityTypeProvider;
     _configFileProvider           = configFileProvider;
     _newznabProvider       = newznabProvider;
     _metadataProvider      = metadataProvider;
     _jobProvider           = jobProvider;
     _configProvider        = configProvider;
     _indexerProvider       = indexerProvider;
     _qualityProvider       = qualityProvider;
     _autoConfigureProvider = autoConfigureProvider;
     _seriesProvider        = seriesProvider;
 }
示例#14
0
        private static void Main()
        {
            if (AppController.IsOnlyAppInstance() == false)
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += ApplicationThreadException;
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            AppController.CreateAppDirectory();

#if DEBUG
#else
            Console.Write("Redirecting console output");
            LogProvider.RedirectConsoleOutput();
#endif

            ConfigFileProvider.ValidateUserConfigFile();

            Properties.Settings userSettings = new Properties.Settings();
            if (userSettings.UpgradeRequired)
            {
                Console.WriteLine("Upgrading settings to new version");
                userSettings.Upgrade();
                userSettings.UpgradeRequired = false;
                userSettings.Save();
            }

            AppController.Start();

            Application.Run(new KeyboardForm());

            AppController.Close();
            // Release static events or else leak.
            Application.ThreadException -= ApplicationThreadException;
            AppDomain.CurrentDomain.UnhandledException -= UnhandledExceptionHandler;
        }
示例#15
0
        public void TestConfigFileProviderSerialization()
        {
            //Create JSON
            var data = new TestServiceConfig
            {
                TestServiceAConfig = new TestServiceAConfig()
                {
                    A = "AAA"
                },
                TestServiceBConfig = new TestServiceBConfig()
                {
                    B = "BBB"
                },
                TestServiceCConfig = new TestServiceCConfig()
                {
                    C = "CCC"
                }
            };

            var r = new ConfigFileProvider <TestServiceConfig>(Fixture.LoggerFactory);

            using (var mStream = new MemoryStream())
            {
                var writer     = new StreamWriter(mStream, Encoding.UTF8);
                var serializer = new Newtonsoft.Json.JsonSerializer();
                //serializer.Converters.Add(new ConfigInterfaceJsonConverter());
                //serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

                serializer.Serialize(writer, data);

                writer.Flush();
                mStream.Position = 0;
                var reader = new StreamReader(mStream, Encoding.UTF8);
                r.ReadConfig(reader);
                Assert.NotNull(r.Get());

                Assert.Equal(data.TestServiceAConfig.A, r.Get().TestServiceAConfig.A);
                Assert.Equal(data.TestServiceBConfig.B, r.Get().TestServiceBConfig.B);
                Assert.Equal(data.TestServiceCConfig.C, r.Get().TestServiceCConfig.C);
            }
        }
示例#16
0
        public async Task Execute_With_Existing_Config_Opens_The_File(
            bool solutionLoaded,
            string configPath,
            [Frozen] IFileAccessor fileAccessor,
            [Frozen][Substitute] IPopupManager popupManager,
            [Frozen][Substitute] ConfigFileProvider configFileProvider,
            Fixture fixture
            )
        {
            // Arrange
            var sut    = getSut(fixture, configFileProvider, fileAccessor, configPath, solutionLoaded);
            var called = false;

            // Act
            await sut.ExecuteAsync(s =>
            {
                called = true;
                return(Task.CompletedTask);
            });

            // Assert
            called.ShouldBeTrue();
            popupManager.DidNotReceiveWithAnyArgs().Confirm(Arg.Any <string>(), Arg.Any <string>());
        }