Esempio n. 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, HistoryDbContext historyDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/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();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
            historyDbContext.Database.EnsureCreated();
        }
 public EventLinksController(HistoryDbContext context, IDataShaper <Event> eventDataShaper, IDataShaper <Birth> birthDataShaper, IDataShaper <Death> deathDataShaper)
 {
     _eventDataShaper = eventDataShaper;
     _birthDataShaper = birthDataShaper;
     _deathDataShaper = deathDataShaper;
     _context         = context;
     unitOfWork       = new UnitOfWork(_context, _eventDataShaper, _birthDataShaper, _deathDataShaper);
 }
Esempio n. 3
0
 public UnitOfWork(HistoryDbContext context, IDataShaper <Event> eventDataShaper, IDataShaper <Birth> birthDataShaper
                   , IDataShaper <Death> deathDataShaper)
 {
     _context         = context;
     _eventDataShaper = eventDataShaper;
     _birthDataShaper = birthDataShaper;
     _deathDataShaper = deathDataShaper;
 }
Esempio n. 4
0
        public static void Scrape(IApplicationBuilder applicationBuilder)
        {
            var scope = applicationBuilder.ApplicationServices.CreateScope();
            HistoryDbContext _historyDbContext = scope.ServiceProvider.GetRequiredService <HistoryDbContext>();
            PageScraper      pageScraper       = new PageScraper();
            var          months = CultureInfo.GetCultureInfo("en-us").DateTimeFormat.MonthNames;
            List <Event> events = new List <Event>();
            List <Birth> births = new List <Birth>();
            List <Death> deaths = new List <Death>();
            var          watch  = System.Diagnostics.Stopwatch.StartNew();

            if (!_historyDbContext.Event.Any())
            {
                for (int i = 0; i < 12; i++)
                {
                    for (int j = 1; j < DateTime.DaysInMonth(DateTime.Now.Year, i + 1); j++)
                    {
                        events = pageScraper.GetData <Event>(months[i] + "_" + j.ToString(), "1");
                        _historyDbContext.AddRange(events);
                    }
                }

                _historyDbContext.SaveChanges();
            }
            if (!_historyDbContext.Birth.Any())
            {
                for (int i = 0; i < 12; i++)
                {
                    for (int j = 1; j < DateTime.DaysInMonth(DateTime.Now.Year, i + 1); j++)
                    {
                        births = pageScraper.GetData <Birth>(months[i] + "_" + j.ToString(), "2");
                        _historyDbContext.AddRange(births);
                    }
                }

                _historyDbContext.SaveChanges();
            }

            if (!_historyDbContext.Death.Any())
            {
                for (int i = 0; i < 12; i++)
                {
                    for (int j = 1; j < DateTime.DaysInMonth(DateTime.Now.Year, i + 1); j++)
                    {
                        deaths = pageScraper.GetData <Death>(months[i] + "_" + j.ToString(), "3");
                        _historyDbContext.AddRange(deaths);
                    }
                }

                _historyDbContext.SaveChanges();
            }

            // measuring the time it takes to scrape for fun
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            System.Diagnostics.Trace.WriteLine("ScrapeData took" + elapsedMs.ToString() + " ms");
        }
Esempio n. 5
0
        public void TestGetHistoryValue()
        {
            HistoryDbContext    context = new HistoryDbContext();
            List <HistoryValue> list    = context.GetHistoryValues(new string[] { "000001G0010001", "000001G0010002" }, new string[] { "31000000000711" }, new DateTime(2018, 4, 27, 10, 30, 0));

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("MeterID:{0};MeterParamID:{1};Value:{2}", list[i].MeterID, list[i].MeterParamID, list[i].Value);
            }
        }
Esempio n. 6
0
        public void EventGetById_ReturnsHttpNotFound_ForInvalidId()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HistoryDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var _dbContext = new HistoryDbContext(optionsBuilder.Options);

            var controller = new EventsController(_dbContext);

            // Act
            var result = controller.GetEventById(1, "");

            Assert.IsType <NotFoundObjectResult>(result);
        }
Esempio n. 7
0
 public BirthsController(HistoryDbContext context)
 {
     _context   = context;
     unitOfWork = new UnitOfWork(_context, _eventDataShaper, _birthDataShaper, _deathDataShaper);
 }
 public ChangeRepository(HistoryDbContext context) : base(context)
 {
 }
Esempio n. 9
0
 public RepositoryImplementor(HistoryDbContext h)
 {
     this.historyDbContext = h;
 }
Esempio n. 10
0
 public BaseRepository(HistoryDbContext context)
 {
     this.context = context;
     table        = context.Set <T>();
 }
Esempio n. 11
0
 public GenericRepository(HistoryDbContext @object)
 {
     this.@object = @object;
 }
Esempio n. 12
0
 public CircuitCollectService()
 {
     context = new HistoryDbContext();
 }
Esempio n. 13
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, HistoryDbContext context)
 {
     loggerFactory.AddConsole(Configuration.GetSection("Logging"));
     loggerFactory.AddDebug();
     StartupConfigureAuth.ConfigureAuth(app);
     app.UseMvc();
     HistoryDbInitializer.Initialize(context);
 }
Esempio n. 14
0
 public GenericRepository(HistoryDbContext context, IDataShaper <T> dataShaper)
 {
     _context    = context;
     dbSet       = _context.Set <T>();
     _dataShaper = dataShaper;
 }
Esempio n. 15
0
 public EventLinksController(HistoryDbContext context)
 {
     _context   = context;
     unitOfWork = new UnitOfWork(_context);
 }
 public GenericRepository(HistoryDbContext context)
 {
     _context = context;
     dbSet    = _context.Set <T>();
 }
Esempio n. 17
0
 public DeathsController(HistoryDbContext context)
 {
     _context   = context;
     unitOfWork = new UnitOfWork(_context);
 }
Esempio n. 18
0
 public HistoryDataService()
 {
     context = new HistoryDbContext();
 }
Esempio n. 19
0
 public EventsController(HistoryDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public HistoryRepository(HistoryDbContext context)
 {
     _context = context;
 }
Esempio n. 21
0
 public UnitOfWork(HistoryDbContext context)
 {
     _context = context;
 }
Esempio n. 22
0
 public CustomerController(HistoryDbContext context)
 {
     _context = context;
 }
Esempio n. 23
0
 public static void Initialize(HistoryDbContext context)
 {
     context.Database.EnsureCreated();
 }