コード例 #1
0
ファイル: Service1.cs プロジェクト: weedkiller/Analytics
        private async void GetRowsForEachTable(ElementDTO element)
        {
            try
            {
                InnonAnalyticsEngineEntities _dbContext2 = new InnonAnalyticsEngineEntities();
                this.EventLog.WriteEntry("Start For Table " + element.Source_Element_Name_History, EventLogEntryType.Information);
                IRawDataRepository _rawDataRepository = new RawDataRepository();
                //IList<RawDataDTO> rawdata =
                Point_Measure_Fact_Service point_measure_fact_service;
                await Task.Run(() => _rawDataRepository.GetRowData(element.Source_Element_Name_History, Convert.ToDateTime("2013-05-16 05:45:00"), Convert.ToDateTime("2013-05-16 05:45:00"), _dto_connector, _dbContext2))
                .ContinueWith((x) =>
                {
                    this.EventLog.WriteEntry("Get Rows for Table " + element.Source_Element_Name_History + " - " + x.Result.Count(), EventLogEntryType.Information);

                    point_measure_fact_service = new Point_Measure_Fact_Service();

                    try
                    {
                        point_measure_fact_service.Save_Point_Measure_Fact_Service(x.Result, element);
                    }
                    catch (Exception ex)
                    {
                        this.EventLog.WriteEntry("Error " + ex + " -----  " + element.ElementSourceName);
                    }
                });

                //this.EventLog.WriteEntry("Get Rows for Table " + element.Source_Element_Name_History + " - " + rawdata.Count(), EventLogEntryType.Information);
            }
            catch (Exception ex)
            {
                this.EventLog.WriteEntry("Error while getting the GetRowsForEachTable with table " + element.Source_Element_Name_History + " Connection " + _dto_connector.DatabaseName + " - Error" + ex.Message + " - Inner exception " + ex.InnerException, EventLogEntryType.Error);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: weedkiller/Analytics
 private static IList <RawDataDTO> GetRawData(ElementDTO element, DateTime fromdate, DateTime ToDate, ConnectorDTO _dto_connector, InnonAnalyticsEngineEntities _dbcontext)
 {
     try
     {
         IRawDataRepository _rawDataRepository = new RawDataRepository();
         return(_rawDataRepository.GetRowData(element.Source_Element_Name_History, Convert.ToDateTime(fromdate.ToString("yyyy-MM-dd HH:mm:ss.fff")), Convert.ToDateTime(ToDate.ToString("yyyy-MM-dd HH:mm:ss.fff")), _dto_connector, _dbcontext));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #3
0
        private async static void GetRowsForEachTable(ElementDTO element, ConnectorDTO _dto_connector, int index)
        {
            try
            {
                string information_of_element            = element.ID + "--" + element.Source_Element_Name_History + " Connection " + _dto_connector.DatabaseName;
                InnonAnalyticsEngineEntities _dbContext2 = new InnonAnalyticsEngineEntities();

                _dbContext2.Database.CommandTimeout = 300;

                //Console.WriteLine("From Date " + default_from_dt);
                //Console.WriteLine("To Date " + default_to_dt);
                IRawDataRepository _rawDataRepository = new RawDataRepository();

                //   Console.ReadLine();

                //IList<RawDataDTO> rawdata =
                Point_Measure_Fact_Service   point_measure_fact_service;
                tblDatawareHouseMigrationLog data_migration_log = new tblDatawareHouseMigrationLog();
                await Task.Run(() =>
                {
                    IList <RawDataDTO> list_RawDataDTO = new List <RawDataDTO>();
                    try
                    {
                        Console.WriteLine("Start For Table " + element.ID + "--" + element.Source_Element_Name_History + " -- From dt " + default_from_dt + " -- To date " + default_to_dt);
                        list_RawDataDTO = _rawDataRepository.GetRowData(element.Source_Element_Name_History, Convert.ToDateTime(default_from_dt.ToString("yyyy-MM-dd HH:mm:ss.fff")), Convert.ToDateTime(default_to_dt.ToString("yyyy-MM-dd HH:mm:ss.fff")), _dto_connector, _dbContext2);
                    }
                    catch (Exception ex)
                    {
                        Helper.WriteToFile(" [ " + System.DateTime.Now + " ] First Step fetching the bulk data from error " + ex.Message + " -- " + information_of_element);
                    }

                    return(list_RawDataDTO);
                })
                .ContinueWith((k) =>
                {
                    if (k.Result.Count > 0)
                    {
                        try
                        {
                            data_migration_log = _dbContext2.tblDatawareHouseMigrationLogs.Add(
                                new tblDatawareHouseMigrationLog
                            {
                                Element_ID         = element.ID,
                                Last_Run_Start     = System.DateTime.Now,
                                Total_Record_Fetch = 0,
                                Timestamp_From     = default_from_dt,
                            });
                            _dbContext2.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            Helper.WriteToFile(" [ " + System.DateTime.Now + " ] Sec Step saving in to the tblDatawareHouseMigrationLogs data from error " + ex.Message + " -- " + information_of_element);
                        }
                    }

                    return(k.Result);
                })
                .ContinueWith((x) =>
                {
                    IList <Point_Measure_Fact> point_measure_fact_list_dto = new List <Point_Measure_Fact>();
                    try
                    {
                        // x is last continue result (GetRowData returns the IList<RawData>)
                        //Save Final insert in to the database InnonAnalyticsWarehouse table Point_Mesaure_Fact
                        Console.WriteLine("Get Rows for Table " + element.Source_Element_Name_History + " - " + x.Result.Count(), EventLogEntryType.Information);
                        point_measure_fact_service = new Point_Measure_Fact_Service();
                        point_measure_fact_service.List_Point_Measure_Fact_Service(x.Result, element);

                        point_measure_fact_list_dto = point_measure_fact_service.List_Point_Measure_Fact_Service(x.Result, element);

                        FinalInsert(point_measure_fact_list_dto);
                    }
                    catch (Exception ex)
                    {
                        Helper.WriteToFile(" [ " + System.DateTime.Now + " ] Third Step final saving the data in to the point measure facts from error " + ex.Message + " -- " + information_of_element);
                    }

                    return(point_measure_fact_list_dto);
                })
                .ContinueWith((y) =>
                {
                    // y is last continue result
                    //update DatawareHouseMigrationLog table for the next run
                    if (y.Result.Count > 0)
                    {
                        data_migration_log.Last_Run_End       = System.DateTime.Now;
                        data_migration_log.Total_Record_Fetch = y.Result.Count;
                        data_migration_log.Timestamp_To       = Convert.ToDateTime(y.Result.LastOrDefault().Timestamp_To);
                        _dbContext2.SaveChangesAsync();
                    }
                    return(y.Result);
                }).ContinueWith((z) =>
                {
                    IList <RawDataDTO> rawdata = new List <RawDataDTO>();

                    try
                    {
                        //Checking the missing data
                        DatawarehouseConnectionContext ctx = new DatawarehouseConnectionContext();
                        ctx.Database.CommandTimeout        = 300;
                        rawdata = ctx.Database.SqlQuery <RawDataDTO>("EXEC GetRawMissingData '" + _dto_connector.ServerOrIP + "', '" +
                                                                     _dto_connector.ServerUserName + "' , '" + _dto_connector.ServerPassword + "', '" + _dto_connector.DatabaseName + "' , '" + element.Source_Element_Name_History + "' ,'" + Convert.ToDateTime(default_to_dt.AddYears(-1).ToShortDateString() + " 00:00:00").ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + element.ID).ToList();
                        ctx.Database.Connection.Close();
                    }
                    catch (Exception ex)
                    {
                        Helper.WriteToFile(" [ " + System.DateTime.Now + " ] Fourth getting missing data from error " + ex.Message + " -- " + information_of_element);
                    }
                    return(rawdata);
                }).ContinueWith((t) =>
                {
                    //Saving the missing data

                    IList <RawDataDTO> missingrawdata = new List <RawDataDTO>();
                    missingrawdata = t.Result;
                    try
                    {
                        Console.WriteLine("Missing " + element.Source_Element_Name_History + "- Total:-" + missingrawdata.Count());
                        point_measure_fact_service = new Point_Measure_Fact_Service();
                        point_measure_fact_service.List_Point_Measure_Fact_Service(missingrawdata, element);
                        IList <Point_Measure_Fact> point_measure_fact_list_dto = point_measure_fact_service.List_Point_Measure_Fact_Service(missingrawdata, element);

                        FinalInsert(point_measure_fact_list_dto);
                    }
                    catch (Exception ex)
                    {
                        Helper.WriteToFile(" [ " + System.DateTime.Now + " ] Fifth saving missing data from error " + ex.Message + " -- " + information_of_element);
                    }
                }).ContinueWith((r) =>
                {
                    Task.Factory.StartNew((x) =>
                    {
                        Helper.WriteToFile(" [ " + System.DateTime.Now + " ]  Deleting for " + +element.ID + "--" + element.Source_Element_Name_History);
                        Console.WriteLine(index + " delete duplicate data " + element.ID + "--" + element.Source_Element_Name_History);
                        DatawarehouseConnectionContext ctx_delete_duplicate = new DatawarehouseConnectionContext();
                        ctx_delete_duplicate.Database.CommandTimeout        = 300;
                        ctx_delete_duplicate.Database.ExecuteSqlCommand("EXEC Delete_Duplicate_Data " + element.ID);
                        ctx_delete_duplicate.Database.Connection.Close();
                        Console.WriteLine(index + " Finished duplicate data delete ");
                    }, TaskCreationOptions.DenyChildAttach);
                });

                //this.EventLog.WriteEntry("Get Rows for Table " + element.Source_Element_Name_History + " - " + rawdata.Count(), EventLogEntryType.Information);
            }
            catch (Exception ex)
            {
                string innerexp = (ex.InnerException != null) ? ex.InnerException.Message: "";
                Helper.WriteToFile("Error while getting the GetRowsForEachTable with table " + element.ID + "--" + element.Source_Element_Name_History + " Connection " + _dto_connector.DatabaseName + " - Error" + ex.Message + " - Inner exception " + innerexp);
            }
        }