Пример #1
0
        static void Main(string[] args)
        {
            LandingRepository repo = new LandingRepository();

            logger.Info("~~~~ Program Started ~~~~");

            List <Landing_Table> import_tables = repo.GetLandingTables();

            foreach (Landing_Table table in import_tables)
            {
                logger.Info("Importing {0}", table.Table_Name);
                Landing_Table_Log TableLog = repo.New_Log_Record(table.id);

                try
                {
                    String password = RijndaelSimple.Decrypt(table.Source_Pass, "PLanning and Audit", "Diplomatic Persistance", "SHA1", 1, "AGHYEFIVOPJNSFRU", 128);

                    if (repo.TableExists(table.Dest_Schema, table.Table_Name))
                    {
                        logger.Debug("Table {0}.{1} exists", table.Dest_Schema, table.Table_Name);
                    }
                    else
                    {
                        logger.Debug("Table {0}.{1} does not exist", table.Dest_Schema, table.Table_Name);
                    }


                    TableLog.Start_Time = DateTime.Now;
                    TableLog.Success    = 0;
                    repo.Update_Log(TableLog);
                } catch (Exception ex)
                {
                    TableLog.Notes = "Exception: " + ex.Message;
                    logger.Error(ex, "Error loading table " + table.Table_Name);
                } finally
                {
                    logger.Info("Finished {0}", table.Table_Name);
                    TableLog.End_Time = DateTime.Now;
                    repo.Update_Log(TableLog);
                }
            }


            logger.Info("~~~~ Program Finished ~~~~");


            //System.Console.ReadKey();
            LogManager.Flush();
            LogManager.Shutdown();
        }
Пример #2
0
        public void ImportTable()
        {
            SourceTable      = tableName;
            DestinationTable = tableName;

            string[] ignoreRowCountTables = { "SWVTRAN" };

            logger.Info("Beginning landing for table {0}", Table.Table_Name);

            operation = repo.NewOperation(ExecutionId, string.Format("Data import for {0}.{1}", Table.Dest_Schema, Table.Table_Name));
            repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "OnStart", string.Format("Import {0}.{1} beginning", Table.Dest_Schema, Table.Table_Name), "Information");


            TableLog = repo.New_Log_Record(Table.id);

            try
            {
                SourceTableCount();
                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", string.Format("Source row count for {0}.{1} is {2}", Table.Dest_Schema, Table.Table_Name, TableLog.Source_Rows), "Information");

                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", string.Format("Starting to land table {0}.{1}", Table.Dest_Schema, Table.Table_Name), "Information");
                LandTable();
                LandingTableCount();
                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", string.Format("Finished landing {0}.{1} row count is {2}", Table.Dest_Schema, Table.Table_Name, TableLog.Landing_Rows), "Information");

                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", string.Format("Starting add hashes for table {0}.{1}", Table.Dest_Schema, Table.Table_Name), "Information");
                HashTable();
                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", string.Format("Finished adding hashes for table {0}.{1}", Table.Dest_Schema, Table.Table_Name), "Information");


                logger.Info("Rows in {0} source: {1}, landing: {2}", Table.Table_Name, TableLog.Source_Rows, TableLog.Landing_Rows);


                if (TableLog.Source_Rows != TableLog.Landing_Rows)
                {
                    if (!ignoreRowCountTables.Contains(Table.Table_Name))
                    {
                        throw new Exception("Source and landing table rows don't match, not continuing");
                    }
                    else
                    {
                        logger.Info("Exception Ignored for excluded table {0}.  Rowcount exception. Landing rows: {1} Stage rows: {2}", Table.Table_Name, TableLog.Landing_Rows, TableLog.Stage_Rows);
                    }
                }


                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", string.Format("Starting stage for {0}.{1}", Table.Dest_Schema, Table.Table_Name), "Information");
                StageTable();

                StageTableCount();
                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", string.Format("Finished stage for {0}.{1} row count is {2}", Table.Dest_Schema, Table.Table_Name, TableLog.Stage_Rows), "Information");

                logger.Info("Rows in {0} stage: {1}", Table.Table_Name, TableLog.Stage_Rows);

                if (TableLog.Stage_Rows == TableLog.Source_Rows)
                {
                    TableLog.Success = 1;
                    repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "Information", "Import finished and source/stage row counts match: " + TableLog.Source_Rows + ":" + TableLog.Stage_Rows + " rows", "Information");
                    operation.operation_status = "Success";
                }
                else
                {
                    TableLog.Success = 0;
                    repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "OnError", "Row Mismatch between source and staging table", "Error");
                    operation.operation_status = "Finished with row count error";
                }
            }

            catch (Exception ex)
            {
                logger.Error(ex, "Exception while landing {0}: {1}", Table.Table_Name, ex.Message);
                operation.operation_status = "Failed";

                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "OnError", "Exception while trying to import table: " + ex.Message + " " + ex.Source + " " + ex.StackTrace, "Error");

                operation.operation_status = "Failed";
            }

            finally
            {
                operation.end_time = DateTime.Now;

                repo.Update_Log(TableLog);
                repo.Update(operation);
                logger.Info("Finished landing for table {0}", Table.Table_Name);
                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable", "OnComplete", "Import finished and source/stage row counts match", "Information");
            }


            /*
             * hashing this out for now,   moving to simplistic method, revisit later
             * //try
             * //{
             *  if (GetSourceSchema())
             *  {
             *      if (GetDestSchema())
             *      {
             *          if (!SchemasMatch())
             *          {
             *              WriteToLog("info", "Schema's don't match, drop and recreating");
             *              DropDestTable();
             *              CreateDestTable();
             *          }
             *      }
             *      else
             *      {
             *          WriteToLog("info", "Destination Table doesn't exist, creating");
             *          CreateDestTable();
             *      }
             *
             *      // At this point the destination table should be good to go
             *      GetDestSchema(); // refresh the schema
             *
             *      DeleteAndImport();
             *  }
             *  else
             *  {
             *      WriteToLog("Error", "Source table does not exist");
             *  }
             * //}
             * //catch (Exception ex)
             * //{
             * //    WriteToLog("Error", "Unspecified error during import: "+ex.Message);
             *
             * //}
             */
        }