示例#1
0
        private void Save_Aggregate_To_WareHouse(List <Aggregate_Raw_Data> _list_aggregation, AggerationType _aggerationType, long Element_ID)
        {
            if (_list_aggregation != null)
            {
                if (_list_aggregation.Any())
                {
                    try
                    {
                        _db_datawarehouse_context = new InnonAnalyticsWarehouseEntities();

                        switch (_aggerationType)
                        {
                        case AggerationType.Hour:
                            _db_datawarehouse_context.Point_Agg_Hour.AddRange(Point_Agg_Hour_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Hour_List(_list_aggregation));
                            break;

                        case AggerationType.Day:
                            _db_datawarehouse_context.Point_Agg_Day.AddRange(Point_Agg_Day_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Day_List(_list_aggregation));
                            break;

                        case AggerationType.Week:
                            //_db_datawarehouse_context.Point_Agg_Week.AddRange(Point_Agg_Week_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Week_List(_list_aggregation));
                            break;

                        case AggerationType.Month:
                            _db_datawarehouse_context.Point_Agg_Month.AddRange(Point_Agg_Month_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Month_List(_list_aggregation));
                            break;

                        case AggerationType.Year:
                            _db_datawarehouse_context.Point_Agg_Year.AddRange(Point_Agg_Year_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Year_List(_list_aggregation));
                            break;

                        default:
                            File_Log.SaveLog_ToFile(new Exception("Invalid AggregationType"), LoggingActions.Error, "Point_ID " + Element_ID);
                            break;
                        }
                        _db_datawarehouse_context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        File_Log.SaveLog_ToFile(ex, LoggingActions.Error, "Aggragation Type " + _aggerationType + " Point_ID " + Element_ID);
                    }
                }
            }
        }
示例#2
0
        protected void Update_Hour_Aggregation(long Element_ID)
        {
            try
            {
                InnonAnalyticsWarehouseEntities db_datawarehouse_context = new InnonAnalyticsWarehouseEntities();
                //Get last inserted record in the table Point_Agg_Hour
                double   hours    = double.Parse(ConfigurationManagerHelper.AppSettings["aggregate_hours"].ToString());
                DateTime datetime = DateTime.Now.AddHours(-hours);
                IList <Point_Agg_Hour> tbl_point_Agg_Hours = db_datawarehouse_context.Point_Agg_Hour.Where(point_hour => point_hour.Point_ID == Element_ID && point_hour.Hour_ID >= datetime).ToList();
                if (tbl_point_Agg_Hours.Count() > 0)
                {
                    List <Aggregate_Raw_Data> _list_aggregation = new List <Aggregate_Raw_Data>();
                    _list_aggregation = Get_Aggregate_Raw_Data(Element_ID, Helper.Get_Last_Hour(datetime), AggerationType.Hour);

                    _list_aggregation = _list_aggregation.Where(aggregate => tbl_point_Agg_Hours.Any(aggr_hour =>
                                                                                                     aggregate.Hour_ID == aggr_hour.Hour_ID &&
                                                                                                     (aggregate.TotalCount != aggr_hour.Hour_Count || aggregate.SumValue != aggr_hour.Sum_Value))).ToList();

                    if (_list_aggregation.Count() > 0)
                    {
                        tbl_point_Agg_Hours      = Point_Agg_Hour_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Hour_List(_list_aggregation);
                        db_datawarehouse_context = new InnonAnalyticsWarehouseEntities();
                        foreach (Point_Agg_Hour tbl_point_Agg_Hour in tbl_point_Agg_Hours)
                        {
                            db_datawarehouse_context.Point_Agg_Hour.Attach(tbl_point_Agg_Hour);
                            db_datawarehouse_context.Entry(tbl_point_Agg_Hour).State = System.Data.Entity.EntityState.Modified;
                        }
                        db_datawarehouse_context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                File_Log.SaveLog_ToFile(ex, Common.Enums.LoggingActions.Error, "Update_Hour_Aggregation passing parameter element_id:- " + Element_ID);
            }
        }