Esempio n. 1
0
 public DicUnitResponse(NoDataOptions options, Globle globle, WDbContext wDbContext) : base(options)
 {
     DicUnits        = DefaultDatabase.GetCollection <DicUnit>(DicUnit.DicUnitTableName);
     this.globle     = globle;
     dicBckFolder    = globle.GetGlobleFolder <DicBckFolder>();
     this.wDbContext = wDbContext;
 }
Esempio n. 2
0
File: Startup.cs Progetto: ewsq/Unit
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCompression(options =>
            {
                options.Providers.Add <GzipCompressionProvider>();
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "image/png", "image/jpg", "text/json" });
            });
            services.Configure <GzipCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Fastest;
            });
            services.AddDbContext <WDbContext>();
            services.AddDefaultIdentity <SUser>(options =>
            {
                options.Password.RequireDigit   = options.Password.RequireLowercase = options.Password.RequireNonAlphanumeric = options.Password.RequireUppercase = false;
                options.Password.RequiredLength = 6;
            }).AddRoles <SRole>()
            .AddEntityFrameworkStores <WDbContext>();
            var globle = new Globle();

            globle.RegisterFolder <HeadPortraitFolder>();
            globle.RegisterFolder <DicBckFolder>();
            services.AddSingleton(globle);
            var noSqlOpt = new NoDataOptions(MongoClientSettings.FromUrl(new MongoUrl(Configuration["dbConnection:nosql:connection"])));

            services.AddSingleton(noSqlOpt);
            services.AddSingleton(new WordsBrench(noSqlOpt));

            services.AddResponses();
            var issuer = Configuration["issuer"];

            services.AddJwt(options =>
            {
                options.UseHttps      = false;
                options.SecretKey     = Key;
                options.Issuer        = issuer;
                options.Audience      = issuer;
                options.ValidIssuer   = issuer;
                options.ValidAudience = issuer;
            });
            var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Key));
            var op         = new TokenProviderOptions()
            {
                Issuer             = issuer,
                Audience           = issuer,
                ValidFor           = TimeSpan.FromHours(6),
                SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256)
            };

            services.AddSingleton(op);
            services.AddSingleton(new STokenProvider(op));
            services.AddAuthorization(options =>
            {
                options.AddPolicy("Admin", builder => builder.RequireClaim("Role"));
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddCors(options =>
            {
                options.AddDefaultPolicy(builder =>
                {
                    builder.WithOrigins("http://localhost:4200", "http://localhost:4200/api/v1").AllowAnyHeader().AllowAnyMethod().AllowCredentials();
                });
            });
            //Task.Run(() =>
            //{
            //    var b = new WordsBrench(noSqlOpt);
            //    var du = new DicUnit()
            //    {
            //        Title = "sd",
            //        Words = b.ws.Select(wx => new WordUnit(wx.Item1, wx.Item2)).ToArray()
            //    };
            //    var Client = new MongoClient(noSqlOpt.LinkSettings);
            //    var DefaultDatabase = Client.GetDatabase(NoDataResponseBase.DefaultDbName);
            //    var d = DefaultDatabase.GetCollection<DicUnit>(DicUnit.DicUnitTableName);

            //    d.InsertOne(du);
            //}).Wait();
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }
Esempio n. 3
0
 protected NoDataResponseBase(NoDataOptions options)
 {
     Options         = options;
     Client          = new MongoClient(options.LinkSettings);
     DefaultDatabase = Client.GetDatabase(DefaultDbName);
 }