Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, DriveLogicManager logicManager)
        {
            var createScript = logicManager.Database.Database.GenerateCreateScript();

            try {
                await logicManager.Database.Database.ExecuteSqlCommandAsync(createScript);
            } catch { }

            //logicManager.Database.Database.ExecuteSqlCommand(createScript);
            #region Init Default User
            if (logicManager.UserLogic.List().Count() == 0)
            {
                var user = logicManager.UserLogic.Create(new User()
                {
                    Id       = "admin",
                    Password = "******",
                    IsAdmin  = true
                });
            }
            #endregion

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // 使用認證
            app.UseAuthentication();

            // 使用MVC
            app.UseMvc();

            // 使用Swagger
            app.UseSwagger();

            // 使用Swagger UI
            app.UseSwaggerUI(c => {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Drive API");
            });

            // 使用靜態檔案
            app.UseStaticFiles();

            // 使用SPA
            app.UseSpaStaticFiles();

            // SPA例外處理
            app.Use(async(context, next) => {
                try {
                    await next();
                } catch (Exception e) {
                    if (e is InvalidOperationException && e.Message.Contains("/index.html"))
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                }
            });

            // SPA設定
            app.UseSpa(c => { });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 初始化基礎控制器
 /// </summary>
 /// <param name="database">資料庫實例</param>
 public BaseController(DriveLogicManager manager)
 {
     this.Manager = manager;
 }
Ejemplo n.º 3
0
 public FileController(DriveLogicManager manager) : base(manager)
 {
 }
Ejemplo n.º 4
0
 public UserController(DriveLogicManager manager) : base(manager)
 {
 }