示例#1
0
        public static Options Parse(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .AddCommandLine(args, _commandMapping);

            var configure = new ConfigureFromConfigurationOptions <Options>(builder.Build());
            var options   = new Options();

            configure.Action(options);
            return(options);
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region Obtendo as configurações do projeto
            AppSettings appSettings = new AppSettings();
            //responsavel pela deserializanção do appsettings.json
            var config = new ConfigureFromConfigurationOptions <object>
                             (Configuration.GetSection("AppSettings"));
            config.Action(appSettings);

            services.AddSingleton <AppSettings>(appSettings);

            //variavel global para string de conexao
            System.Environment.SetEnvironmentVariable("MYSQLSTRCON", appSettings.StringConexaoMysql);

            #endregion

            #region Serviço para Cookie Authorization

            services.AddAuthentication(option =>
            {
                option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                option.DefaultChallengeScheme    = CookieAuthenticationDefaults.AuthenticationScheme;
                option.DefaultSignInScheme       = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie(option =>
            {
                option.Cookie.Name      = "CookieAutenticacao";
                option.AccessDeniedPath = new Microsoft.AspNetCore.Http.PathString("/Default/Index");
                option.LoginPath        = new Microsoft.AspNetCore.Http.PathString("/Default/Index");
                option.ExpireTimeSpan   = TimeSpan.FromDays(appSettings.CookieTempoVida);
            });

            services.AddAuthorization(option =>
            {
                option.AddPolicy("CookieAutenticacao", new AuthorizationPolicyBuilder()
                                 .AddAuthenticationSchemes(CookieAuthenticationDefaults.AuthenticationScheme)
                                 .RequireAuthenticatedUser().Build());
            });

            #endregion

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddControllersWithViews();

            services.AddHttpContextAccessor();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
示例#3
0
        internal static TOptions Parse <TOptions>(IEnumerable <string> args, IDictionary <string, string> switchMapping)
            where TOptions : class, new()
        {
            var booleanSwitches = GetConfigMapCounts(typeof(TOptions), t => t == typeof(bool), switchMapping);
            var arrays          = GetConfigMapCounts(typeof(TOptions), t => (t.GetTypeInfo().IsGenericType&& t.GetGenericTypeDefinition() == typeof(List <>)) || t.IsArray, switchMapping);
            var updatedArgs     = TransformArguments(args, arrays, booleanSwitches).ToArray();

            var cmd = new ConfigurationBuilder(Directory.GetCurrentDirectory())
                      .AddCommandLine(updatedArgs, switchMapping)
                      .Build();

            var manager = new ConfigureFromConfigurationOptions <TOptions>(cmd);

            var options = new TOptions();

            manager.Action(options);

            return(options);
        }