예제 #1
0
        public SyncPCTablesProcess(string config)
        {
            new  SyncPCTablesLibrary(config);
            string nuConfig = config.Contains("\\\\")? config:config.Replace("\\", "\\\\");

            if (File.Exists(nuConfig))
            {
                if (SyncPCTablesLibrary.pcSyncType == SyncPCTablesLibrary.USE_PC_CARD_TYPE)
                {
                    string tableListScript = File.ReadAllText(SyncPCTablesLibrary.pcTableFetchScript);
                    tableListScript = tableListScript.Replace("PC_TABLE_NAME", SyncPCTablesLibrary.pcTableType);
                    DataTable tempTab = SyncPCTablesLibrary.getDataFromSQL(tableListScript, SyncPCTablesLibrary.sourceConnectionProps.getConnectionString());
                    foreach (DataRow row in tempTab.Rows)
                    {
                        foreach (DataColumn column in tempTab.Columns)
                        {
                            destinationTableList.Add(row[column].ToString());
                        }
                    }
                }
                else if (SyncPCTablesLibrary.pcSyncType == SyncPCTablesLibrary.USE_PC_CARD_LIST)
                {
                    destinationTableList = SyncPCTablesLibrary.pcTableSyncList;
                }

                Console.WriteLine("Starting synchronization of the following  tables:");
                SyncPCTablesLibrary.writeToLog("Starting synchronization of the following  tables:");
                int k = 0;
                foreach (string tableName in destinationTableList)
                {
                    ++k;
                    Console.WriteLine(k.ToString() + "." + tableName);
                    SyncPCTablesLibrary.writeToLog(k.ToString() + ". " + tableName);
                }

                int threads = destinationTableList.Count;

                syncThreads = new Thread[threads];
                int i = 0;
                foreach (string tableName in destinationTableList)
                {
                    if (!syncedTableList.Contains(tableName))
                    {
                        syncThreads[i] = new Thread(() => synchTables(tableName));
                        syncedTableList.Add(tableName);
                        ++i;
                    }
                }

                runSync();
            }
            else
            {
                Console.WriteLine("The specified configuration file: " + nuConfig + " does not exist. Please review configuration file parameter( -c ).");
            }
        }
예제 #2
0
        public SyncPCTablesProcess()
        {
            if (SyncPCTablesLibrary.pcSyncType == SyncPCTablesLibrary.USE_PC_CARD_TYPE)
            {
                string tableListScript = File.ReadAllText(SyncPCTablesLibrary.pcTableFetchScript);
                tableListScript = tableListScript.Replace("PC_TABLE_NAME", SyncPCTablesLibrary.pcTableType);
                DataTable tempTab = SyncPCTablesLibrary.getDataFromSQL(tableListScript, SyncPCTablesLibrary.sourceConnectionProps.getConnectionString());
                foreach (DataRow row in tempTab.Rows)
                {
                    foreach (DataColumn column in tempTab.Columns)
                    {
                        destinationTableList.Add(row[column].ToString());
                    }
                }
            }
            else if (SyncPCTablesLibrary.pcSyncType == SyncPCTablesLibrary.USE_PC_CARD_LIST)
            {
                destinationTableList = SyncPCTablesLibrary.pcTableSyncList;
            }

            Console.WriteLine("Starting synchronization of the following  tables:");
            SyncPCTablesLibrary.writeToLog("Starting synchronization of the following  tables:");
            int k = 0;

            foreach (string tableName in destinationTableList)
            {
                ++k;
                Console.WriteLine(k.ToString() + "." + tableName);
                SyncPCTablesLibrary.writeToLog(k.ToString() + "." + tableName);
            }

            int threads = SyncPCTablesLibrary.concurrentThreads;

            syncThreads = new Thread[threads];
            int i = 0;

            foreach (string tableName in destinationTableList)
            {
                if (!syncedTableList.Contains(tableName))
                {
                    ++i;
                    syncThreads[i] = new Thread(() => synchTables(tableName));
                    syncedTableList.Add(tableName);
                    Console.WriteLine("initialing thread " + i.ToString() + " for " + tableName);
                }
            }

            runSync();
        }
        public void runTableMerge(string sourceTable, string destinationTable)
        {
            string    placeHolder        = "CURRENT_TABLE_NAME";
            string    colScript          = SyncPCTablesLibrary.fetchColumnsScript.Replace(placeHolder, destinationTable).Replace(SyncPCTablesLibrary.destinationDatabase + "..", "");
            ArrayList columnList         = new ArrayList();
            ArrayList columnListNoBraces = new ArrayList();
            DataTable tempTab            = SyncPCTablesLibrary.getDataFromSQL(colScript, SyncPCTablesLibrary.destinationConnectionProps.getConnectionString());
            string    rowData            = "";

            foreach (DataRow row in tempTab.Rows)
            {
                foreach (DataColumn column in tempTab.Columns)
                {
                    rowData = "[" + row[column].ToString() + "]";
                    columnList.Add(rowData);
                    columnListNoBraces.Add(row[column].ToString());
                }
            }
            //	runBulkInsert(sourceTab, destTab);
            StringBuilder tableUpdateClauseBuilder = new StringBuilder();
            StringBuilder tableInsertClauseBuilder = new StringBuilder();
            StringBuilder columnListBuilder        = new StringBuilder();
            StringBuilder searchConditionsBuilder  = new StringBuilder();

            string srcTable  = "SOURCE";
            string destTable = "TARGET";

            foreach (string col in columnList)
            {
                tableUpdateClauseBuilder.Append(string.Format("{2}.{0}  = {1}.{0},", col, srcTable, destTable));
            }

            ArrayList searchFieldList = SyncPCTablesLibrary.rowSpecificFields.Count > 0?  SyncPCTablesLibrary.rowSpecificFields:columnListNoBraces;

            foreach (string col in searchFieldList)
            {
                searchConditionsBuilder.Append(string.Format("{2}.[{0}]  = {1}.[{0}] AND ", col, srcTable, destTable));
            }



            foreach (string col in columnList)
            {
                tableInsertClauseBuilder.Append(string.Format("{0},", col));
                columnListBuilder.Append(string.Format("{0},", col));
            }
            tableUpdateClauseBuilder = SyncPCTablesLibrary.removeNLastChars(tableUpdateClauseBuilder, 1);
            tableInsertClauseBuilder = SyncPCTablesLibrary.removeNLastChars(tableInsertClauseBuilder, 1);
            columnListBuilder        = SyncPCTablesLibrary.removeNLastChars(columnListBuilder, 1);
            searchConditionsBuilder  = SyncPCTablesLibrary.removeNLastChars(searchConditionsBuilder, 5);

            string mergeScript = SyncPCTablesLibrary.mergeScript.Replace("DESTINATION_SERVER", SyncPCTablesLibrary.destinationServer)
                                 .Replace("DESTINATION_DATABASE", SyncPCTablesLibrary.destinationDatabase)
                                 .Replace("DESTINATION_TABLE", destinationTable.Replace(SyncPCTablesLibrary.destinationDatabase + "..", ""))
                                 .Replace("SOURCE_SERVER", SyncPCTablesLibrary.sourceServer)
                                 .Replace("SOURCE_DATABASE", SyncPCTablesLibrary.sourceDatabase)
                                 .Replace("SOURCE_TABLE", sourceTable.Replace(SyncPCTablesLibrary.sourceDatabase + "..", ""))
                                 .Replace("SEARCH_CONDITIONS", searchConditionsBuilder.ToString())
                                 .Replace("TABLE_UPDATE_LIST", tableUpdateClauseBuilder.ToString())
                                 .Replace("TABLE_COLUMN_LIST", columnListBuilder.ToString())
                                 .Replace("TABLE_INSERT_LIST", tableInsertClauseBuilder.ToString());

            executOnServer(SyncPCTablesLibrary.destinationConnectionProps.getConnectionString(), mergeScript);
        }