示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IDatabaseInitializerService initializerService)
        {
            initializerService.InitializeDatabase();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        public void Run()
        {
            IDatabaseInitializerService initializeService =
                this.serviceProvider.GetService <IDatabaseInitializerService>();

            initializeService.InitializeDatabase();

            ICommandInterpreter commandInterpreter = this.serviceProvider.GetService <ICommandInterpreter>();

            while (true)
            {
                try
                {
                    Console.WriteLine("Enter command:");

                    string[] input = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

                    string result = commandInterpreter.Read(input);

                    Console.WriteLine(result);
                    Console.WriteLine();
                }
                catch (Exception exception) when(exception is SqlException || exception is ArgumentException ||
                                                 exception is InvalidOperationException)
                {
                    Console.WriteLine(exception.Message);
                    Console.WriteLine();
                }
            }
        }