// <summary>
 /// Sobreescribimos el metodo OnConfiguring del DbContext para configurar como base de datos SqlServer
 /// </summary>
 /// <param name="optionsBuilder"></param>
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseSqlServer(MySettingModel.GetNetTestConecction(), options =>
     {
         options.CommandTimeout(120);
     });
 }
Esempio n. 2
0
        /// <summary>
        /// 获取用户设置
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public MySettingInfo GetUserSettingByToken(string token)
        {
            MySettingInfo result = null;

            try
            {
                result = new MySettingInfo {
                    IsCheckPicInDucument = true, IsUseCustumCi = true
                };
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "通用类目", Code = "111" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "母婴", Code = "222" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "房地产", Code = "333" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "美妆", Code = "444" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "食品", Code = "555" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "医疗", Code = "666" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "教育", Code = "777" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "保健品", Code = "888" });
                //result.CategoryInfos.Add(new CategorySelectInfo { CheckedState = true, Name = "其它", Code = "999" });
                string         apiName    = "setting";
                string         resultStr  = HttpHelper.HttpUrlGet(apiName, "Get", token);
                CommonResponse resultInfo = JsonConvert.DeserializeObject <CommonResponse>(resultStr);
                if (resultInfo != null && resultInfo.state)
                {
                    MySettingModel mySettingModel = JsonConvert.DeserializeObject <MySettingModel>(resultInfo.result);
                    if (mySettingModel != null)
                    {
                        result.IsCheckPicInDucument = mySettingModel.imageActive;
                        result.IsUseCustumCi        = mySettingModel.customActive;
                        if (mySettingModel.types != null)
                        {
                            foreach (var item in mySettingModel.types)
                            {
                                result.CategoryInfos.Add(new CategorySelectInfo {
                                    CheckedState = item.selected, Name = item.typeName, Code = item.typeId
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message);
                result = null;
            }
            return(result);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Inject AppSettings
            services.Configure <ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // Mappers
            MapperConfiguration.Configuration();

            services.AddDbContext <ApplicactionDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("NetTestSqlServer:ConnectionString")));

            services.AddDefaultIdentity <ApplicationUser>().AddRoles <IdentityRole>().AddEntityFrameworkStores <ApplicactionDbContext>();
            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequiredLength         = 4;

                options.SignIn.RequireConfirmedEmail = false;
            });

            services.Configure <DataProtectionTokenProviderOptions>(options =>
            {
                options.TokenLifespan = TimeSpan.FromMinutes(5);
            });

            services.AddCors();

            //Jwt Authentication
            var key = Encoding.UTF8.GetBytes(Configuration["ApplicationSettings:JWT_Secret"].ToString());

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = false;
                x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    ClockSkew = TimeSpan.Zero
                };
            });

            MySettingModel.SetNetTestConecction(Configuration.GetConnectionString("NetTestSqlServer:ConnectionString"));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Net Test", Version = "v1"
                });
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    In          = ParameterLocation.Header,
                    Description = "Please insert JWT with Bearer into field, example:'bearer tokenJWT' ",
                    Name        = "Authorization",
                    Type        = SecuritySchemeType.ApiKey
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        new string[] { }
                    }
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });
        }