private static ConfigurationServices GetConfigurationService()
        {
            try
            {
                Log.Info($"Initialising config for environment {EnvironmentName}");

                var repo = new AzureTableStorageConfigurationRepository(
                    ConfigurationManager.AppSettings["ConfigurationStorageConnectionString"]);
                var options = new ConfigurationOptions(ServiceName, EnvironmentName, Version);
                var service = new ConfigurationService(repo, options);

                var config = new ConfigurationServices
                {
                    Repository = repo,
                    Service    = service,
                    Options    = options
                };

                Log.Info($"Initialised config for environment {EnvironmentName}");

                return(config);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Could not initialise configuration");
                throw;
            }
        }
Пример #2
0
        private T GetConfiguration <T>(string serviceName)
        {
            var configurationRepository = new AzureTableStorageConfigurationRepository(CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString"));
            var configurationService    = new ConfigurationService(configurationRepository, new ConfigurationOptions(serviceName, _environment, _serviceVersion));

            return(configurationService.Get <T>());
        }
Пример #3
0
        private WebConfiguration GetConfiguration()
        {
            var environment = CloudConfigurationManager.GetSetting("EnvironmentName");

            var storageConnectionString = CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString");

            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            if (storageConnectionString == null)
            {
                throw new ArgumentNullException(nameof(storageConnectionString));
            }

            var configurationRepository = new AzureTableStorageConfigurationRepository(storageConnectionString);;

            var configurationOptions = new ConfigurationOptions(ServiceName, environment, Version);

            var configurationService = new ConfigurationService(configurationRepository, configurationOptions);

            var webConfiguration = configurationService.Get <WebConfiguration>();

            if (webConfiguration == null)
            {
                throw new ArgumentOutOfRangeException($"The requried configuration settings were not retrieved, please check the environmentName case, and the configuration connection string is correct.");
            }

            return(webConfiguration);
        }
Пример #4
0
        private static DataConfiguration GetAzureStorageConfig()
        {
            var configurationRepository = new AzureTableStorageConfigurationRepository(CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString", false));
            var environment             = CloudConfigurationManager.GetSetting("EnvironmentName", false);
            var configurationService    = new ConfigurationService(configurationRepository, new ConfigurationOptions(CloudConfigurationManager.GetSetting("ServiceName", false), environment, "1.0"));

            return(configurationService.Get <DataConfiguration>());
        }
        private static ConfigurationService CreateConfigurationService(string serviceName)
        {
            var storageConnectionString = CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString");
            var configurationRepository = new AzureTableStorageConfigurationRepository(storageConnectionString);
            var configurationService    = new ConfigurationService(configurationRepository, new ConfigurationOptions(serviceName, CurrentEnvironmentName, "1.0"));

            return(configurationService);
        }
Пример #6
0
        public static T GetConfiguration <T>(string serviceName, string version)
        {
            var environmentName         = EnvironmentHelper.GetEnvironmentName();
            var configurationRepository = new AzureTableStorageConfigurationRepository(CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString"));
            var configurationService    = new ConfigurationService(configurationRepository, new ConfigurationOptions(serviceName, environmentName, version));
            var config = configurationService.Get <T>();

            return(config);
        }
        private CommitmentSupportSiteConfiguartion GetConfiguration()
        {
            var environment             = ConfigurationManager.AppSettings["EnvironmentName"] ?? "LOCAL";
            var storageConnectionString = ConfigurationManager.AppSettings["ConfigurationStorageConnectionString"] ?? "UseDevelopmentStorage=true;";
            var configurationRepository = new AzureTableStorageConfigurationRepository(storageConnectionString);
            var configurationOptions    = new ConfigurationOptions(ApplicationConstants.ServiceName, environment, Version);
            var configurationService    = new ConfigurationService(configurationRepository, configurationOptions);
            var webConfiguration        = configurationService.Get <CommitmentSupportSiteConfiguartion>();

            return(webConfiguration);
        }
        private static TestConfiguration loadConfig()
        {
            var configurationRepository = new AzureTableStorageConfigurationRepository(ConfigurationManager.AppSettings["ConfigurationStorageConnectionString"]);

            var configurationService =
                new ConfigurationService(
                    configurationRepository,
                    new ConfigurationOptions(ConfigurationManager.AppSettings["ServiceName"],
                                             ConfigurationManager.AppSettings["EnvironmentName"],
                                             ConfigurationManager.AppSettings["Version"]));

            return(configurationService.Get <TestConfiguration>());
        }
        protected IConfigurationRepository GetDataFromAzure()
        {
            IConfigurationRepository configurationRepository;

            if (bool.Parse(ConfigurationManager.AppSettings["LocalConfig"]))
            {
                configurationRepository = new FileStorageConfigurationRepository();
            }
            else
            {
                configurationRepository = new AzureTableStorageConfigurationRepository(CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString"));
            }
            return(configurationRepository);
        }
Пример #10
0
        private static IConfigurationRepository GetConfigurationRepository()
        {
            IConfigurationRepository configurationRepository;

            if (bool.Parse(ConfigurationManager.AppSettings["LocalConfig"]))
            {
                configurationRepository = new FileStorageConfigurationRepository();
            }
            else
            {
                configurationRepository = new AzureTableStorageConfigurationRepository(ConfigurationManager.AppSettings["ConfigurationStorageConnectionString"]);
            }
            return(configurationRepository);
        }
        private static T GetConfiguration <T>(string serviceName)
        {
            var environment = Environment.GetEnvironmentVariable("DASENV");

            if (string.IsNullOrEmpty(environment))
            {
                environment = GetAppSetting("EnvironmentName", false);
            }

            var configurationRepository = new AzureTableStorageConfigurationRepository(GetAppSetting("ConfigurationStorageConnectionString", true));
            var configurationService    = new ConfigurationService(configurationRepository,
                                                                   new ConfigurationOptions(serviceName, environment, "1.0"));

            return(configurationService.Get <T>());
        }
        private WebConfiguration GetConfiguration()
        {
            var environment = CloudConfigurationManager.GetSetting("EnvironmentName") ?? "LOCAL";

            var storageConnectionString =
                CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString") ??
                "UseDevelopmentStorage=true;";

            var configurationRepository = new AzureTableStorageConfigurationRepository(storageConnectionString);

            var configurationOptions = new ConfigurationOptions(ServiceName, environment, Version);

            var configurationService = new ConfigurationService(configurationRepository, configurationOptions);

            return(configurationService.Get <WebConfiguration>());
        }
        private WebConfiguration GetConfiguration()
        {
            var environment = ConfigurationManager.AppSettings["EnvironmentName"] ??
                              "local";
            var storageConnectionString = ConfigurationManager.AppSettings["ConfigurationStorageConnectionString"] ??
                                          "UseDevelopmentStorage=true";

            var configurationRepository = new AzureTableStorageConfigurationRepository(storageConnectionString);

            var configurationOptions = new ConfigurationOptions(ServiceName, environment, Version);

            var configurationService = new ConfigurationService(configurationRepository, configurationOptions);

            var webConfiguration = configurationService.Get <WebConfiguration>();

            return(webConfiguration);
        }
        private ConfigurationService GetconfigService(string environment)
        {
            IConfigurationRepository configurationRepository;

            if (ConfigurationManager.AppSettings["LocalConfig"].AsBool())
            {
                configurationRepository = new FileStorageConfigurationRepository();
            }
            else
            {
                configurationRepository = new AzureTableStorageConfigurationRepository(ConfigurationManager.AppSettings["ConfigurationStorageConnectionString"]);
            }

            var configurationService = new ConfigurationService(configurationRepository,
                                                                new ConfigurationOptions("SFA.DAS.EmployerUsers.Web", environment, "1.0"));

            return(configurationService);
        }
        private ProviderApprenticeshipsServiceConfiguration GetConfiguration()
        {
            var environment = Environment.GetEnvironmentVariable("DASENV");

            if (string.IsNullOrEmpty(environment))
            {
                environment = ConfigurationManager.AppSettings["EnvironmentName"];
            }
            if (environment.Equals("LOCAL") || environment.Equals("AT") || environment.Equals("TEST"))
            {
                // Not sure how/when/why this is used?
                //SystemDetails.EnvironmentName = envName;
                //SystemDetails.VersionNumber = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }

            var configurationRepository = new AzureTableStorageConfigurationRepository(ConfigurationManager.AppSettings["ConfigurationStorageConnectionString"]);
            var configurationService    = new ConfigurationService(configurationRepository,
                                                                   new ConfigurationOptions(ServiceName, environment, "1.0"));

            var result = configurationService.Get <ProviderApprenticeshipsServiceConfiguration>();

            return(result);
        }
        static void Main(string[] args)
        {
            IConfigurationRepository repo = null;
            var exit         = false;
            var defaultColor = Console.ForegroundColor;

            // Fluff - Get what persistence implementation to use
            while (repo == null && !exit)
            {
                Console.WriteLine("Where is your configuration stored:");
                Console.WriteLine("    1. Azure Table Storage");
                Console.WriteLine("    2. File Storage");
                Console.WriteLine("    3. None of the above. Exit");
                Console.Write("Please select (1 - 3): ");
                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    repo = new AzureTableStorageConfigurationRepository();
                    break;

                case "2":
                    repo = new FileStorageConfigurationRepository();
                    break;

                case "3":
                    exit = true;
                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Invalid input. Please enter an number between 1 and 2");
                    Console.ForegroundColor = defaultColor;
                    Console.WriteLine();
                    break;
                }
            }
            Console.WriteLine();

            // Create a new configuration service
            var configurationService = new ConfigurationService(repo,
                                                                new ConfigurationOptions("GettingConfiguration", "DEV", "1.0"));

            // Get the configuration
            var configTask = configurationService.GetAsync <SampleConfiguration>();

            configTask.Wait();
            var config = configTask.Result;

            // Ouput result
            if (config != null)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"Read {config.ServiceName} as configured service name");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Did not find configuration");
            }
            Console.ForegroundColor = defaultColor;

            Console.WriteLine();
            Console.Write("Press any key to exit...");
            Console.ReadKey();
        }
        public DefaultRegistry()
        {
            var environment = Environment.GetEnvironmentVariable("DASENV");

            if (string.IsNullOrEmpty(environment))
            {
                environment = CloudConfigurationManager.GetSetting("EnvironmentName");
            }

            Scan(
                scan => {
                scan.WithDefaultConventions();
                scan.AssemblyContainingType <IMessageNotificationRepository>();
                scan.ConnectImplementationsToTypesClosing(typeof(IRequestHandler <,>));
                scan.ConnectImplementationsToTypesClosing(typeof(IAsyncRequestHandler <,>));
                scan.ConnectImplementationsToTypesClosing(typeof(INotificationHandler <>));
                scan.ConnectImplementationsToTypesClosing(typeof(IAsyncNotificationHandler <>));
                scan.ConnectImplementationsToTypesClosing(typeof(AbstractValidator <>));
            });
            For <SingleInstanceFactory>().Use <SingleInstanceFactory>(ctx => t => ctx.GetInstance(t));
            For <MultiInstanceFactory>().Use <MultiInstanceFactory>(ctx => t => ctx.GetAllInstances(t));
            For <INotifyHttpClientWrapper>().Use <NotifyHttpClientWrapper>();

            IConfigurationRepository configurationRepository;

            if (bool.Parse(ConfigurationManager.AppSettings["LocalConfig"]))
            {
                configurationRepository = new FileStorageConfigurationRepository();
            }
            else
            {
                configurationRepository = new AzureTableStorageConfigurationRepository(CloudConfigurationManager.GetSetting("ConfigurationStorageConnectionString"));
            }

            var configurationService = new ConfigurationService(
                configurationRepository,
                new ConfigurationOptions(ServiceName, environment, "1.0"));

            For <IConfigurationService>().Use(configurationService);

            var storageConnectionString = CloudConfigurationManager.GetSetting("StorageConnectionString") ??
                                          "UseDevelopmentStorage=true";

            For <IMessageNotificationRepository>().Use <AzureEmailNotificationRepository>().Ctor <string>().Is(storageConnectionString);

            if (environment == DevEnv)
            {
                For <IMessageSubSystem>().Use(() => new FileSystemMessageSubSystem());
                For <IEmailService>().Use <LocalEmailService>();
                //For<IEmailService>().Use<SendGridSmtpEmailService>();
            }
            else
            {
                var config      = configurationService.Get <NotificationServiceConfiguration>();
                var queueConfig = config.ServiceBusConfiguration;
                For <IMessageSubSystem>().Use(() => new AzureServiceBusMessageSubSystem(queueConfig.ConnectionString, queueConfig.QueueName));
                For <IEmailService>().Use <SendGridSmtpEmailService>();
            }

            For <MessagingService>().Use <MessagingService>();
            For <QueuedMessageHandler>().Use <QueuedMessageHandler>();
            For <IAccountRepository>().Use <AccountRepository>();
            For <IMediator>().Use <Mediator>();
        }