Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            // Should not user Database.Migrate() in production,
            // instead migrations should be done as part of deployment
            using (var srvc = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var context = srvc.ServiceProvider.GetService <ApplicationDbContext>();
                context.Database.Migrate();
            }

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });

            ApplicationInitialiser.Initialise(userManager, roleManager).Wait();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            #region Display Header Info

            System.Console.ForegroundColor = ConsoleColor.DarkGreen;
            System.Console.WriteLine("---------------------------------------------------------------");
            System.Console.WriteLine("Welcome to NearMap Test ---------------------------------------");
            System.Console.WriteLine("------------------------ https://github.com/izevaka/nearmap-test");
            System.Console.WriteLine("Amir--Pour-----------------------------------------------------");
            System.Console.WriteLine("Mobile: 0414 888 931-------------------------------------------");
            System.Console.WriteLine("---------------------------------------------------------------");
            System.Console.ResetColor();

            #endregion

            #region Setting up log

            ILog log = LogManager.GetLogger(typeof(Program));

            FileInfo configFile = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.xml"));

            XmlConfigurator.ConfigureAndWatch(configFile);

            #endregion

            #region Composition root- Any kind of Dependency injector can be used to set it up

            DatabaseStore databaseStore = new DatabaseStore(log);

            ApplicationInitialiser applicationInitialiser = new ApplicationInitialiser(databaseStore, log);

            applicationInitialiser.Initialise();

            //getting all configs required for application
            CacheConfiguration cacheConfiguration = new CacheConfiguration();

            ICacheStoreAccelerator cacheStoreAccelerator = new CacheStoreAccelerator(cacheConfiguration, log);

            //this class helps local cache work faster, it adds more functionality
            LocalCacheStoreAccelerator localCacheAccelerator = new LocalCacheStoreAccelerator(cacheStoreAccelerator, cacheConfiguration, log);

            //this is the distributed cache
            DistributedCacheStore distributedCacheStore = new DistributedCacheStore(cacheConfiguration, log);

            //this class combines the localcache and distributed cache together  to provide a faster caching mechanism after a while
            //for more demanded objects, this class is the cache layer of the application
            SmartCacheStore fastCacheInterceptor = new SmartCacheStore(distributedCacheStore, localCacheAccelerator, log);

            //this class is responsible to retrieve the data either from cache layer or from database
            Repository repository = new Repository(fastCacheInterceptor, databaseStore, log);

            //this is the service that is going to expose to all consumers
            MyService myService = new MyService(repository);

            #endregion

            System.Console.WriteLine("Start up finished");
            System.Console.WriteLine("---------------------------------------------------------------");

            for (int i = 0; i < 10; i++)
            {
                new Thread(() =>
                {
                    //Sets the resolution of the timer. This has to be done per thread to ensure that 5ms sleep is actually 5 ms.
                    //http://stackoverflow.com/a/522681
                    timeBeginPeriod(5);

                    for (int j = 0; j < 50; j++)
                    {
                        string key = string.Format("key_{0}", random.Next(0, 9));

                        Stopwatch myStopwatch = new Stopwatch();

                        myStopwatch.Reset();
                        myStopwatch.Start();

                        var value = myService.GetItem(key);

                        myStopwatch.Stop();

                        var duration = myStopwatch.ElapsedMilliseconds;

                        System.Console.WriteLine("[{0}] Request '{1}', response '{2}', time: {3}",
                                                 Thread.CurrentThread.ManagedThreadId,
                                                 key,
                                                 value,
                                                 duration.ToString("F2"));

                        System.Console.ResetColor();
                    }

                    timeEndPeriod(5);
                }).Start();
            }

            System.Console.WriteLine("----E--N--D---");

            System.Console.Read();
        }