Exemplo n.º 1
0
        public void TestDeSerializeClassHierarchyAndBind()
        {
            Type streamTask1Type = typeof(StreamTask1);
            Type helloTaskType   = typeof(HelloTask);

            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(HelloTask).Assembly.GetName().Name });
            IClassNode      StreamTask1ClassNode = (IClassNode)ns.GetNode(streamTask1Type.AssemblyQualifiedName);
            IClassNode      HelloTaskClassNode   = (IClassNode)ns.GetNode(helloTaskType.AssemblyQualifiedName);

            ProtocolBufferClassHierarchy.Serialize("task.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("task.bin");
            IClassNode      StreamTask1ClassNode2 = (IClassNode)ch.GetNode(streamTask1Type.AssemblyQualifiedName);
            IClassNode      HelloTaskClassNode2   = (IClassNode)ch.GetNode(helloTaskType.AssemblyQualifiedName);

            Assert.Equal(StreamTask1ClassNode.GetName(), StreamTask1ClassNode2.GetName());
            Assert.Equal(HelloTaskClassNode.GetName(), HelloTaskClassNode2.GetName());

            // have to use original class hierarchy for the merge. ClassHierarchy from ProtoBuffer doesn't support merge.
            IConfigurationBuilder cb = TangFactory.GetTang()
                                       .NewConfigurationBuilder(ns);

            cb.AddConfiguration(TaskConfiguration.ConfigurationModule
                                .Set(TaskConfiguration.Identifier, "Hello_From_Streaming1")
                                .Set(TaskConfiguration.Task, GenericType <StreamTask1> .Class)
                                .Build());

            IConfiguration taskConfiguration = cb.Build();
            StreamTask1    st = TangFactory.GetTang().NewInjector(taskConfiguration).GetInstance <StreamTask1>();

            Assert.NotNull(st);
        }
Exemplo n.º 2
0
        private static InjectorImpl Copy(InjectorImpl old, IConfiguration[] configurations)
        {
            InjectorImpl i;

            try
            {
                IConfigurationBuilder cb = old.configuration.newBuilder();
                foreach (IConfiguration c in configurations)
                {
                    cb.AddConfiguration(c);
                }
                i = new InjectorImpl(cb.Build());
            }
            catch (BindException e)
            {
                throw new IllegalStateException("Unexpected error copying configuration!", e);
            }

            foreach (IClassNode cn in old.instances.Keys)
            {
                if (cn.GetFullName().Equals(ReflectionUtilities.GetFullName(typeof(IInjector))) ||
                    cn.GetFullName().Equals(ReflectionUtilities.GetFullName(typeof(InjectorImpl))))
                {
                    // This would imply that we're treating injector as a singleton somewhere.  It should be copied fresh each time.
                    throw new IllegalStateException("");
                }
                try
                {
                    IClassNode new_cn = (IClassNode)i.classHierarchy.GetNode(cn.GetFullName());

                    object o = null;
                    old.instances.TryGetValue(cn, out o);
                    if (o != null)
                    {
                        i.instances.Add(new_cn, o);
                    }
                }
                catch (BindException e)
                {
                    throw new IllegalStateException("Could not resolve name "
                                                    + cn.GetFullName() + " when copying injector", e);
                }
            }

            foreach (INamedParameterNode np in old.namedParameterInstances.Keys)
            {
                // if (!builder.namedParameters.containsKey(np)) {
                Object o = null;
                old.namedParameterInstances.TryGetValue(np, out o);
                INamedParameterNode new_np = (INamedParameterNode)i.classHierarchy.GetNode(np.GetFullName());
                i.namedParameterInstances.Add(new_np, o);
            }

            // Fork the aspect (if any)
            if (old.aspect != null)
            {
                i.BindAspect(old.aspect.CreateChildAspect());
            }
            return(i);
        }
Exemplo n.º 3
0
        private void ConfigureAppConfigurationSettings(IConfigurationBuilder config)
        {
            string         path    = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ?? Directory.GetCurrentDirectory();
            IConfiguration secrets = GetConfiguration();

            config.AddConfiguration(secrets);
            config.SetBasePath(path);
        }
        public static IConfigurationBuilder AddConfiguration(
            this IConfigurationBuilder configurationBuilder,
            Dictionary <string, string> overrideConfig = null)
        {
            var defaultConfiguration = GetDefaultConfiguration(overrideConfig);

            return(configurationBuilder
                   .AddConfiguration(defaultConfiguration));
        }
 public static IConfigurationBuilder AddConfigurationIfTrue(this IConfigurationBuilder configurationBuilder,
                                                            IConfiguration configuration,
                                                            Func <bool> func)
 {
     if (func.Invoke())
     {
         configurationBuilder.AddConfiguration(configuration);
     }
     return(configurationBuilder);
 }
        private static void AddCustomConfiguration(HostBuilderContext context, IConfigurationBuilder builder)
        {
            builder.AddEnvironmentVariables("GPCONNECTAPPOINTMENTCHECKER_");
            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            var configuration = builder.Build();

            builder.AddConfiguration(options =>
            {
                options.ConnectionString = configuration.GetConnectionString("DefaultConnection");
            });
        }
 /// <summary>
 /// Adds configuration to the <see cref="IConfigurationBuilder"/> from files and table storage
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="config"></param>
 /// <returns></returns>
 public static IConfiguration AddConfig(this IConfigurationBuilder builder, IConfiguration config)
 {
     return(builder
            .AddConfiguration(config)
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appSettings.json")
            .AddJsonFile("appSettings.Development.json", true)
            .AddEnvironmentVariables()
            .AddAzureTableStorageConfiguration(
                config["ConfigurationStorageConnectionString"],
                config["AppName"],
                config["EnvironmentName"],
                "1.0", "SFA.DAS.HmrcApprenticeshipLevyApiStub")
            .Build()
            );
 }
Exemplo n.º 8
0
        private static void GenerateConfig(IConfigurationBuilder config)
        {
            try
            {
                var configuration = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile(ConfigPath, false, true)
                                    .Build();

                config.AddConfiguration(configuration);
            }
            catch (FileNotFoundException)
            {
                Console.BackgroundColor = ConsoleColor.DarkYellow;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.WriteLine("Warning: Config file missing or invalid! Creating Default.");
                Console.Write("Please input your discord bot token: ");
                string token = Console.ReadLine();
                Console.Write("Please input the sql server address: ");
                string sqlServer = Console.ReadLine();
                Console.Write("Database name: ");
                string databaseName = Console.ReadLine();
                Console.Write("Username: "******"Password: "******"{" +
                                       "\n  \"prefix\": \"!\"," +
                                       "\n  \"token\": \"" + token + "\"," +
                                       "\n  \"mysql\":" +
                                       "\n  {" +
                                       "\n    \"username\": \"" + username + "\"," +
                                       "\n    \"password\": \"" + password + "\"," +
                                       "\n    \"server\": \"" + sqlServer + "\"," +
                                       "\n    \"database\": \"" + databaseName + "\"" +
                                       "\n  }" +
                                       "\n}";
                File.WriteAllText(ConfigPath, defaultConfig);
                Path.GetFullPath(ConfigPath);
                Console.WriteLine("New config file at:\n " + Path.GetFullPath(ConfigPath));
                Console.ResetColor();
                GenerateConfig(config);
            }
        }
Exemplo n.º 9
0
        public void BuildCrossCheckConfigure(WebHostBuilderContext context, IConfigurationBuilder config)
        {
            config.AddEnvironmentVariables("BCC_");

            var builtConfig = config.Build();

            var azureKeyVault = builtConfig["Azure:KeyVault"];

            if (!string.IsNullOrEmpty(azureKeyVault))
            {
                var keyVaultConfigBuilder = GetConfigurationBuilder();

                var keyVaultClient = GetKeyVaultClient();

                keyVaultConfigBuilder.AddAzureKeyVault($"https://{azureKeyVault}.vault.azure.net/", keyVaultClient, new StringUnescapingSecretsManager());

                var keyVaultConfig = keyVaultConfigBuilder.Build();

                config.AddConfiguration(keyVaultConfig);
            }
        }
Exemplo n.º 10
0
        public static IConfiguration MergeDeserializedConfs(params IConfiguration[] configurations)
        {
            IClassHierarchy ch;

            if (configurations != null && configurations.Length > 0)
            {
                ch = configurations[0].GetClassHierarchy();
            }
            else
            {
                ch = new ProtocolBufferClassHierarchy();
            }

            IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(ch);

            foreach (IConfiguration tc in configurations)
            {
                cb.AddConfiguration(((ConfigurationImpl)tc));
            }

            return(cb.Build());
        }
Exemplo n.º 11
0
 public static IConfigurationBuilder BuildConfig(IConfigurationBuilder builder)
 => builder.AddConfiguration(ConfigurationSingleton.Instance);
Exemplo n.º 12
0
 private static void ConfigureApp(HostBuilderContext HostBuilderContext, IConfigurationBuilder Configuration)
 {
     Configuration.AddConfiguration(Configurations);
 }
Exemplo n.º 13
0
 private void ConfigureHostConfiguration(IConfigurationBuilder configurationBuilder)
 {
     configurationBuilder.AddConfiguration(this.configuration);
 }
Exemplo n.º 14
0
        private static void ConfigureAppConfiguration(IApplicationBuilder app, IConfigurationBuilder s)
        {
            var hostConfig = app.ApplicationServices.GetRequiredService <IConfiguration>();

            s.AddConfiguration(hostConfig);
        }