Exemplo n.º 1
0
        /// <summary>
        /// Get the credentials from the command line
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static Options GetOptionsFromConfiguration(string[] args)
        {
            Dictionary <string, string> mapping = new Dictionary <string, string>
            {
                { "--tenant-id", "SharedTokenCacheTenantId" },
                { "--app-owner", "SharedTokenCacheUsername" },
                { "--client-id", "ClientId" },
                { "--spa-redirect-uri", "SpaRedirectUri" },
                { "--web-redirect-uri", "WebRedirectUri" },
                { "--app-name", "AppName" },
            };
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddCommandLine(args, mapping);
            IConfiguration configuration = configurationBuilder.Build();
            DefaultAzureCredentialOptions defaultAzureCredentialOptions = ConfigurationBinder.Get <DefaultAzureCredentialOptions>(configuration);

            defaultAzureCredentialOptions.ExcludeManagedIdentityCredential    = true;
            defaultAzureCredentialOptions.ExcludeInteractiveBrowserCredential = false;
            defaultAzureCredentialOptions.InteractiveBrowserTenantId          = defaultAzureCredentialOptions.SharedTokenCacheTenantId;

            Options options = new Options();

            options.Action         = args.FirstOrDefault(a => !a.StartsWith("--"));
            options.SpaRedirectUri = ConfigurationBinder.GetValue <string>(configuration, "SpaRedirectUri", null);
            options.WebRedirectUri = ConfigurationBinder.GetValue <string>(configuration, "WebRedirectUri", null);
            options.AppName        = ConfigurationBinder.GetValue <string>(configuration, "AppName", null);
            options.ClientId       = ConfigurationBinder.GetValue <string>(configuration, "ClientId", null);
            options.DefaultAzureCredentialOptions = defaultAzureCredentialOptions;
            return(options);
        }
Exemplo n.º 2
0
 public void GetToList()
 {
     for (int i = 0; i < Count; i++)
     {
         ConfigurationBinder.GetValue <string[]>(config, "Name");
     }
 }
Exemplo n.º 3
0
        public WordsCountModel get()
        {
            //api/feed
            var model = _feed.GetTopWords(ConfigurationBinder.GetValue <string>(_config, "UriFeed"));

            return(model);
        }
Exemplo n.º 4
0
        protected override void Prepare()
        {
            string host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
            int    port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);

            _sensorService.SetUrl($"http://{host}:{port}/monitoring/api/sensor");
        }
Exemplo n.º 5
0
 protected override void Prepare()
 {
     this.host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
     this.port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);
     this._politicaPublicaService.SetUrl($"http://{host}:{port}/cidadao/PoliticaPublica");
     this._VagaService.SetUrl($"http://{host}:{port}/gestao/vaga");
 }
Exemplo n.º 6
0
        /// <summary>
        /// 获取Json配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">配置文件的Key(格式:xxx:yyy,注意中间使用':'分割)</param>
        /// <returns></returns>
        public static T GetValue <T>(string key)
        {
            string         fileName      = "appsettings.json";
            IConfiguration configuration = GetJsonConfiguration(fileName);

            return(ConfigurationBinder.GetValue <T>(configuration, key));
        }
Exemplo n.º 7
0
        protected override void Prepare()
        {
            string host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
            int    port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);

            this._campanhaService.SetUrl($"http://{host}:{port}/cidadao/campanha");
        }
        protected override void Prepare()
        {
            string host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
            int    port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);

            this._colaboradorService.SetUrl($"http://{host}:{port}/gestao/Colaborador");
        }
Exemplo n.º 9
0
        protected override void Prepare()
        {
            string host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
            int    port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);

            this._manutencaoService.SetUrl($"http://{host}:{port}/maintenance/api");
            this._insumoService.SetUrl($"http://{host}:{port}/input/api/insumos");
        }
Exemplo n.º 10
0
        protected void Prepare()
        {
            string host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
            int    port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);

            _regiaoService.SetUrl($"http://{host}:{port}/monitoring/api/publico/regiao");
            _cadastroService.SetUrl($"http://{host}:{port}/monitoring/api/publico/cadastro");
        }
Exemplo n.º 11
0
        protected override void Prepare()
        {
            string host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
            int    port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);

            this._votarService.SetUrl($"http://{host}:{port}/cidadao/Votar");
            this._votacaoService.SetUrl($"http://{host}:{port}/cidadao/votacao");
            this._politicaPublicaService.SetUrl($"http://{host}:{port}/cidadao/politicapublica");
        }
Exemplo n.º 12
0
        public CadastroService(ILogger <CadastroService> logger, IConfiguration config, MonitoramentoContext context)
        {
            this._logger  = logger;
            this._context = context;

            this._clientHttp = new HttpClient();

            this.host = config.GetSection("ConfigApp").GetSection("host").Value;
            this.port = ConfigurationBinder.GetValue <int>(config.GetSection("ConfigApp"), "port", 80);
        }
Exemplo n.º 13
0
        public static void Init(IConfiguration configuration)
        {
            if (!_isUnited)
            {
                Configuration = configuration;

                //var appId = ConfigurationBinder.GetValue<string>(Configuration, "MicrosoftAppId");
                //var password = ConfigurationBinder.GetValue<string>(Configuration, "MicrosoftAppPassword");

                SqlConnectionString = ConfigurationBinder.GetValue <string>(Configuration, "ConnectionStrings:SqlConnection");

                _isUnited = true;
            }
        }
Exemplo n.º 14
0
        private static string GetSettingValue(string settingName)
        {
            if (Config == null)
            {
                var builder = new ConfigurationBuilder().AddEnvironmentVariables();
                if (File.Exists("local.settings.json"))
                {
                    builder.AddJsonFile("local.settings.json");
                }
                Config = builder.Build();
            }


            return(ConfigurationBinder.GetValue(Config, settingName, "default"));
        }
        /// <summary>
        /// Load a settings style path settings.x.y.z -> x:y:z.
        /// </summary>
        /// <param name="configuration">Configuration.</param>
        /// <param name="value">Value to load.</param>
        /// <returns>The value formatted to the configuration.</returns>
        public static string LoadSetting(this IConfiguration configuration, string value)
        {
            if (value.StartsWith("{") && value.EndsWith("}"))
            {
                var path = value.Trim('{', '}').Replace(".", ":");
                if (path.StartsWith("settings:"))
                {
                    path = path.Substring(9);
                }

                // just use configurations ability to query for x:y:z
                value = ConfigurationBinder.GetValue <string>(configuration, path);
            }

            return(value);
        }
Exemplo n.º 16
0
        protected override async Task ExecuteAsync(CancellationToken cancel)
        {
            logger.LogDebug("");
            logger.LogDebug("Application Directories");
            logger.LogDebug("=======================");
            logger.LogDebug("ApplicationPath: " + Environment.GetCommandLineArgs()[0]);
            logger.LogDebug("BaseDirectory: " + AppContext.BaseDirectory);
            logger.LogDebug("CurrentDirectory: " + Directory.GetCurrentDirectory());
            logger.LogDebug("");
            logger.LogDebug("Configuration");
            logger.LogDebug("=============");
            logger.LogDebug("ASPNETCORE_ENVIRONMENT: " + ConfigurationBinder.GetValue(configuration, "ASPNETCORE_ENVIRONMENT", "Production"));
            logger.LogDebug("");
            amsTcpIpRouter = new AmsTcpIpRouter(logger, configuration);
            amsTcpIpRouter.RouterStatusChanged += Router_RouterStatusChanged;

            await amsTcpIpRouter.StartAsync(cancel);
        }
Exemplo n.º 17
0
        private static void LogOrmConfig(
            ILogger <Program> logger,
            IConfiguration configuration)
        {
            switch (ConfigurationBinder.GetValue <int>(configuration, "PATIENTSERVICE_ORM"))
            {
            case 1:
                logger.LogInformation("Entity Framework Core ORM chosen.");
                break;

            case 2:
                logger.LogInformation("Dapper ORM chosen.");
                break;

            default:
                logger.LogWarning("Defaulting to Entity Framework Core ORM.");
                break;
            }
        }
Exemplo n.º 18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().AddRazorPagesOptions(options =>
            {
                // Set all permissions for the pages
                options.Conventions.AllowAnonymousToPage("/Index");
                options.Conventions.AllowAnonymousToPage("/Error");

                options.Conventions.AuthorizePage("/OwnTimes", "PermissionNormal");

                options.Conventions.AuthorizePage("/Controlling", "PermissionAdvanced");

                options.Conventions.AuthorizePage("/Users", "PermissionHigh");
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // Cross-site request blocking
            services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");

            // Cookie Authentication
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
            {
                options.LoginPath        = "/Index";
                options.AccessDeniedPath = "/Shared/Error";
                //options.ExpireTimeSpan = TimeSpan.FromMinutes(15);
            });

            // Roles Authorization
            services.AddAuthorization(options =>
            {
                options.DefaultPolicy = new AuthorizationPolicyBuilder("Cookies").RequireAuthenticatedUser().Build();
                options.AddPolicy("PermissionNormal", policy => policy.RequireRole("Normal", "Advanced", "High"));
                options.AddPolicy("PermissionAdvanced", policy => policy.RequireRole("Advanced", "High"));
                options.AddPolicy("PermissionHigh", policy => policy.RequireRole("High"));
            });

            // Database service
            services.AddDbContext <DatabaseContext>(options =>
            {
                options.UseSqlServer(ConfigurationBinder.GetValue <string>(Configuration, "ConnectionString"));
                options.EnableSensitiveDataLogging(true);
            });
        }
        public void Bind(string prefix, Type t, object dataObject)
        {
            if (dataObject == null)
            {
                return;
            }

            var properties = t.GetProperties();

            foreach (var property in properties.Where(p => p.SetMethod.IsPublic))
            {
                string key = prefix + "." + property.Name;
                if (PropertyTypeIsBasic(property.PropertyType.GetTypeInfo()))
                {
                    object value = ConfigurationBinder.GetValue(this, property.PropertyType, key, property.GetValue(dataObject));
                    property.SetValue(dataObject, value);
                }
                else
                {
                    Bind(key, property.PropertyType, property.GetValue(dataObject));
                }
            }
        }
Exemplo n.º 20
0
        public void OneTimeSetUp()
        {
            var environment = Environment.GetEnvironmentVariable("TYPEDSQL_ENVIRONMENT");
            var config      = new ConfigurationBuilder()
                              .SetBasePath(TestContext.CurrentContext.TestDirectory)
                              .AddJsonFile("appSettings.json")
                              .AddJsonFile("appSettings." + environment + ".json", true)
                              .Build();

            var mycsb = new MySqlConnectionStringBuilder()
            {
                Server             = ConfigurationBinder.GetValue <string>(config, "MySql:Server"),
                Port               = ConfigurationBinder.GetValue <uint>(config, "MySql:Port"),
                UserID             = ConfigurationBinder.GetValue <string>(config, "MySql:UserID"),
                Password           = ConfigurationBinder.GetValue <string>(config, "MySql:Password"),
                Database           = ConfigurationBinder.GetValue <string>(config, "MySql:Database"),
                AllowUserVariables = ConfigurationBinder.GetValue <bool>(config, "MySql:AllowUserVariables"),
            };

            var mscsb = new SqlConnectionStringBuilder()
            {
                DataSource         = ConfigurationBinder.GetValue <string>(config, "SqlServer:DataSource"),
                InitialCatalog     = ConfigurationBinder.GetValue <string>(config, "SqlServer:InitialCatalog"),
                IntegratedSecurity = ConfigurationBinder.GetValue <bool>(config, "SqlServer:IntegratedSecurity"),
            };

            if (!mscsb.IntegratedSecurity)
            {
                mscsb.UserID   = ConfigurationBinder.GetValue <string>(config, "SqlServer:UserID");
                mscsb.Password = ConfigurationBinder.GetValue <string>(config, "SqlServer:Password");
            }

            var pgcsb = new NpgsqlConnectionStringBuilder()
            {
                Host     = ConfigurationBinder.GetValue <string>(config, "PostgreSql:Host"),
                Port     = ConfigurationBinder.GetValue <int>(config, "PostgreSql:Port"),
                Username = ConfigurationBinder.GetValue <string>(config, "PostgreSql:Username"),
                Password = ConfigurationBinder.GetValue <string>(config, "PostgreSql:Password"),
                Database = ConfigurationBinder.GetValue <string>(config, "PostgreSql:Database"),
            };

            var services = new ServiceCollection();

            services.AddScoped(provider =>
            {
                var connection = new MySqlConnection(mycsb.ConnectionString);
                connection.Open();
                return(connection);
            });

            services.AddScoped(provider =>
            {
                return(new MySqlQueryRunner(provider.GetRequiredService <MySqlConnection>()));
            });

            services.AddScoped(provider =>
            {
                return(new InMemoryQueryRunner());
            });

            services.AddScoped(provider =>
            {
                var connection = new SqlConnection(mscsb.ConnectionString);
                connection.Open();
                return(connection);
            });

            services.AddScoped(provider =>
            {
                return(new SqlServerQueryRunner(provider.GetRequiredService <SqlConnection>()));
            });

            services.AddScoped(provider =>
            {
                var connection = new NpgsqlConnection(pgcsb.ConnectionString);
                connection.Open();
                return(connection);
            });

            services.AddScoped(provider =>
            {
                return(new PostgreSqlQueryRunner(provider.GetRequiredService <NpgsqlConnection>()));
            });

            RootProvider = services.BuildServiceProvider();
        }
Exemplo n.º 21
0
 protected override void Prepare()
 {
     this._host = this._configuration.GetSection("ConfigApp").GetSection("host").Value;
     this._port = ConfigurationBinder.GetValue <int>(this._configuration.GetSection("ConfigApp"), "port", 80);
 }
Exemplo n.º 22
0
        /// <summary>
        /// 获取Json配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileDir">文件目录(格式:D:\JsonConfigs)</param>
        /// <param name="fileName">文件名称(格式:xxx.json)</param>
        /// <param name="key">配置文件的Key(格式:xxx:yyy,注意中间使用':'分割)</param>
        /// <returns></returns>
        public static T GetValue <T>(string fileDir, string fileName, string key)
        {
            IConfiguration configuration = GetJsonConfiguration(fileDir, fileName);

            return(ConfigurationBinder.GetValue <T>(configuration, key));
        }
Exemplo n.º 23
0
 /// <summary>
 /// Get a setting from defaults or local override
 /// Expectation: key names for settings are lower case
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="name"></param>
 /// <param name="defaultValue"></param>
 /// <returns></returns>
 protected T GetConfiguration <T>(string name, T defaultValue)
 => ConfigurationBinder.GetValue(this.Config, $"{RuleConfigSection}:{Code}:{name}", defaultValue);
Exemplo n.º 24
0
        private static string GetSettingValue(string settingName)
        {
            EnsureConfigInitialized();

            return(ConfigurationBinder.GetValue(Config, settingName, "default"));
        }