Example #1
0
        private void tableCopyTriggerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (tableCopyInProgress == false)
            {
                tableCopyInProgress        = true;
                tableCopyTimerTriggerCount = 0;

                try
                {
                    List <TableCopier> tableCopierList = MongoDB_DAL.GetListOfTableCopiers();

                    foreach (var item in tableCopierList)
                    {
                        item.FetchDataAndImport();
                    }

                    tableCopyInProgress        = false;
                    tableCopyTimerTriggerCount = 0;
                }
                catch (Exception ex)
                {
                    tableCopierServiceLog.Error(ex);
                }
            }
            else
            {
                tableCopyTimerTriggerCount++;
                if (tableCopyTimerTriggerCount >= Convert.ToInt32(ConfigurationManager.AppSettings["TableCopyTimerCounter"].ToString()))
                {
                    tableCopyTimerTriggerCount = 0;
                    tableCopyInProgress        = false;
                }
            }
        }
Example #2
0
        ////uncomment below code and comment above codes for debugging
        //public void Run()
        //{
        //    OnStart(null);
        //}

        protected override void OnStart(string[] args)
        {
            try
            {
                tableCopierServiceLog.Info("******Started Running Vegam_Database_Table_CopierService*****");

                InitializeTypeMapDictionary();

                tableCopyTriggerTimer.Interval = int.Parse(ConfigurationManager.AppSettings["TableCopyTimerInterval"]);
                tableCopyTriggerTimer.Elapsed += tableCopyTriggerTimer_Elapsed;

                MongoDB_DAL.MongoDB_Initialize();

                try
                {
                    List <TableCopier> tableCopierList = MongoDB_DAL.GetListOfTableCopiers();

                    foreach (var item in tableCopierList)
                    {
                        item.FetchDataAndImport();
                    }
                }
                catch (Exception ex)
                {
                    tableCopierServiceLog.Error(ex);
                }

                tableCopyTriggerTimer.Start();
            }
            catch (Exception ex)
            {
                tableCopierServiceLog.Error(ex);
            }
        }
        public void FetchDataAndImport()
        {
            try
            {
                Database sourceDb = DatabaseFactory.CreateDatabase(SourceDbConnectionStringName);

                DataTable sourceDataTable = GetDataFromSourceDBTable(sourceDb);

                if (sourceDataTable == null || sourceDataTable.Rows.Count == 0)
                {
                    _tableCopierLog.Info(" No data fetched from source table for Table Copier ID : " + TableCopierID);
                    return;
                }
                else
                {
                    _tableCopierLog.Info(" Data fetched successfully from source table for Table Copier ID : " + TableCopierID);

                    InsertOrUpdateDataToDestiantionDBTable(ref sourceDataTable);

                    _tableCopierLog.Info(" Data updated successfully in destination table for Table Copier ID : " + TableCopierID);

                    DataRow[] insertSuccessRows = sourceDataTable.Select(_successColumnName + "=" + true);

                    switch (CopyType)
                    {
                    case TableCopyType.StatusBased:
                        //Updating the source table with a flag to indicate that these records are already migrated so that we dont create duplicate records in the next iteration
                        foreach (var row in insertSuccessRows)
                        {
                            OracleDB_DAL.UpdateValuesForRecord(sourceDb, null, SourceTableName, SourceTableUpdateFilters, row);
                        }
                        break;

                    case TableCopyType.SequenceBased:
                        break;

                    case TableCopyType.TimeStampBased:
                        var    te           = insertSuccessRows.OrderByDescending(z => int.Parse(z.Field <string>("FDATEVAL"))).ThenByDescending(z => int.Parse(z.Field <string>("FTIMEVAL")));
                        string lastSyncDate = te.First().Field <string>("FDATEVAL");
                        string lastSyncTime = te.First().Field <string>("FTIMEVAL");
                        MongoDB_DAL.UpdateLastSyncDateTime(TableCopierID, lastSyncDate, lastSyncTime);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                _tableCopierLog.Error(" Error Occured While Copying data for Table Copier ID : " + TableCopierID, ex);
            }
        }