Exemplo n.º 1
0
        private async Task Aggregate(TPHEntity reading)
        {
            var aggregateTable  = new GenericTableStorage(connString, "Aggregates");
            var dayEntityTask   = aggregateTable.GetSingle <AggregateEntity>(reading.PartitionKey + "D", reading.ReadAt.ToString("yyMMdd"));
            var hourEntityTask  = aggregateTable.GetSingle <AggregateEntity>(reading.PartitionKey + "H", reading.ReadAt.ToString("yyMMddHH"));
            var monthEntityTask = aggregateTable.GetSingle <AggregateEntity>(reading.PartitionKey + "M", reading.ReadAt.ToString("yyMM"));

            var dayEntity = await dayEntityTask;

            if (dayEntity == null)
            {
                dayEntity = new AggregateEntity()
                {
                    PartitionKey = reading.PartitionKey + "D", RowKey = reading.ReadAt.ToString("yyMMdd")
                };
            }
            var dayRecord = Mapper.Map <AggregateEntity, IAggregateRecord>(dayEntity);

            UpdateAggregateValues(reading.Temperature, dayRecord.Temperature);
            UpdateAggregateValues(reading.Pressure, dayRecord.Pressure);
            UpdateAggregateValues(reading.Humidity, dayRecord.Humidity);
            await aggregateTable.InsertOrReplaceAsync(Mapper.Map <IAggregateRecord, AggregateEntity>(dayRecord));

            var hourEntity = await hourEntityTask;

            if (hourEntity == null)
            {
                hourEntity = new AggregateEntity()
                {
                    PartitionKey = reading.PartitionKey + "H", RowKey = reading.ReadAt.ToString("yyMMddHH")
                };
            }
            var hourRecord = Mapper.Map <AggregateEntity, IAggregateRecord>(hourEntity);

            UpdateAggregateValues(reading.Temperature, hourRecord.Temperature);
            UpdateAggregateValues(reading.Pressure, hourRecord.Pressure);
            UpdateAggregateValues(reading.Humidity, hourRecord.Humidity);
            await aggregateTable.InsertOrReplaceAsync(Mapper.Map <IAggregateRecord, AggregateEntity>(hourRecord));

            var monthEntity = await monthEntityTask;

            if (monthEntity == null)
            {
                monthEntity = new AggregateEntity()
                {
                    PartitionKey = reading.PartitionKey + "M", RowKey = reading.ReadAt.ToString("yyMM")
                };
            }
            var monthRecord = Mapper.Map <AggregateEntity, IAggregateRecord>(monthEntity);

            UpdateAggregateValues(reading.Temperature, monthRecord.Temperature);
            UpdateAggregateValues(reading.Pressure, monthRecord.Pressure);
            UpdateAggregateValues(reading.Humidity, monthRecord.Humidity);
            await aggregateTable.InsertOrReplaceAsync(Mapper.Map <IAggregateRecord, AggregateEntity>(monthRecord));
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            //app.UseMvc();
            //app.UseFileServer();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });            //app.UseStaticFiles();
            app.UseSpaStaticFiles();
            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
            Mapper.Initialize(c =>
            {
                TPHEntity.MapToEntity(c);
                TPHEntity.MapFromEntity(c);
                DeviceEntity.MapToEntity(c);
                DeviceEntity.MapFromEntity(c);
                AggregateEntity.MapToEntity(c);
                AggregateEntity.MapFromEntity(c);
            });
        }