/// <summary> /// Sync china local data from sql server to oracle /// </summary> protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.Now; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); string settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\China-local-sync.xml"); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); // Set Connection string settingManager.Init(string.Empty);//初始化 mapping strInfo.AppendFormat("Bond-misc-sync.xml data Sync begin at {0}(System Time)\n", DateTime.Now); strInfo.AppendFormat("Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); var lastSyncTime = new DateTime(1900, 1, 1); var currentSyncTime = DateTime.Now; using (var vavEntities = new VAVEntities()) { var date = vavEntities.SCHEDULERLOGs.Where(x => x.STATUS == 0 && x.JOBTYPE == this.JobType).Select( x => (DateTime?)x.STARTTIME).Max(); if (date != null) { lastSyncTime = date.Value.AddHours(-1.5); } } strInfo.AppendFormat("Last successfully sync time : {0}(System Time).\n", lastSyncTime); try { using (var dataSync = new DataSynchronizer(settingManager, lastSyncTime, currentSyncTime)) { dataSync.TableSynched += (sender, e) => strInfo.AppendFormat ("{0} rows have been synchronized from {1} to {2}.\n", e.NumOfRowsSynched, e.Source, e.Dest); dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); var sourceTable = settingManager.SourceTableName.Split(','); dataSync.Sync(sourceTable); } strInfo.AppendFormat("{0} table(s) be synchronized.\n", settingManager.TableMappings.Count()); var endTime = DateTime.Now; strInfo.AppendFormat("Synchronization completed at {0}.\n", endTime); logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.Now; logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }
/// <summary> /// Sync data from GeniusDB and hosted in .144 which is the transfer DB /// </summary> /// <seealso cref="M:Spring.Scheduling.Quartz.QuartzJobObject.Execute(Quartz.JobExecutionContext)"/> protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); string settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\Sync-SdLocalRefinery.xml"); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); // Set Connection string settingManager.Init(string.Empty);//初始化 mapping strInfo.AppendFormat("Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); var lastSyncTime = new DateTime(1900, 1, 1); var currentSyncTime = startTime.AddHours(8); using (var vavEntities = new VAVEntities()) { var date = vavEntities.SCHEDULERLOGs.Where(x => x.STATUS == 0 && x.JOBTYPE == this.JobType).Select( x => (DateTime?)x.STARTTIME).Max(); if (date != null) { lastSyncTime = date.Value.AddHours(-0.5); } } try { using (var dataSync = new DataSynchronizer(settingManager, lastSyncTime, currentSyncTime)) { dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); var sourceTable = settingManager.SourceTableName.Split(','); strInfo.Append(dataSync.SyncEachTableFromMaxMtime(sourceTable, "CreateDate")); //strInfo.Append(dataSync.Sync(sourceTable)); } var endTime = DateTime.UtcNow; logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow; logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }
/// <summary> /// Sync data from GeniusDB and hosted in .144 which is the transfer DB /// </summary> /// <seealso cref="M:Spring.Scheduling.Quartz.QuartzJobObject.Execute(Quartz.JobExecutionContext)"/> protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); string settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\EJVMigration2.xml"); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); // Set Connection string settingManager.Init(string.Empty);//初始化 mapping strInfo.AppendFormat("Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); var lastSyncTime = new DateTime(2017, 3, 17); var currentSyncTime = startTime.AddHours(8); try { using (var dataSync = new DataSynchronizer(settingManager, lastSyncTime, currentSyncTime)) { dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); var sourceTable = settingManager.SourceTableName.Split(','); strInfo.Append(dataSync.SyncEachTableFromMaxMtime(sourceTable, "asset_last_chg_dt")); //strInfo.Append(dataSync.Sync(sourceTable)); } var endTime = DateTime.UtcNow; //Update Bond Info strInfo.AppendFormat("Update Bond Info en&cn start at {0}.\n", DateTime.UtcNow.ToGMT8String()); SyncUtil.UpdateBondInfo(lastSyncTime, currentSyncTime); strInfo.AppendFormat("Update Bond Info en&cn completed at {0}.\n ", DateTime.UtcNow.ToGMT8String()); //Rebuild Index strInfo.AppendFormat("Rebuild Index at {0}.\n", DateTime.UtcNow.ToGMT8String()); var result1 = SolrClient.RebuildIndex("full"); endTime = DateTime.UtcNow; strInfo.AppendFormat("Rebuild Index completed at {0}.\n Result: {1}\n", DateTime.UtcNow.ToGMT8String(), result1); logEntity.ENDTIME = endTime; logEntity.JobStatus = (result1 == "Success") ? JobStatus.Success : JobStatus.Fail; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow; logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }
protected override void ExecuteInternal(JobExecutionContext context) { if (DateTime.Now.Hour < 9 || DateTime.Now.Hour > 18) { //"Only this time(9:00Am-6:00Pm) point synchronous;"; return; } var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime, JOBTYPE = JobType }; var strInfo = new StringBuilder(); string settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\MarketData-sync.xml"); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); // Set Connection string settingManager.Init(string.Empty);//初始化 mapping strInfo.AppendFormat("MarketData-sync.xml data Sync begin at {0}(System Time)\n", DateTime.Now); strInfo.AppendFormat("Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); var mtime = OracleHelper.GetSingle("SELECT max(MODIFYDATE) FROM ejvasset"); var lastSyncTime = mtime == null?Convert.ToDateTime("1999-1-1") : Convert.ToDateTime(mtime); var currentSyncTime = DateTime.Now; try { using (var dataSync = new DataSynchronizer(settingManager, lastSyncTime, currentSyncTime)) { dataSync.TableSynched += (sender, e) => strInfo.AppendFormat ("{0} rows have been synchronized from {1} to {2}.\n", e.NumOfRowsSynched, e.Source, e.Dest); dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); var sourceTable = settingManager.SourceTableName.Split(','); dataSync.Sync(sourceTable); } strInfo.AppendFormat("{0} table(s) be synchronized.\n", settingManager.TableMappings.Count()); var endTime = DateTime.Now; strInfo.AppendFormat("Synchronization completed at {0}.\n", endTime); logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); } catch (Exception e) { logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + e; } finally { logEntity.ENDTIME = DateTime.UtcNow; WriteLogEntity(logEntity); } }
/// <summary> /// Sync data from GeniusDB and hosted in .144 which is the transfer DB /// </summary> /// <seealso cref="M:Spring.Scheduling.Quartz.QuartzJobObject.Execute(Quartz.JobExecutionContext)"/> protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigFilePath); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); var destinationDbConn = string.Empty; settingManager.Init(destinationDbConn);//初始化 mapping //strInfo.AppendFormat("File data Sync begin at {0}\n", startTime.ToGMT8String()); strInfo.AppendFormat("<p>Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]</p>", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); strInfo.AppendFormat("<p>Source [Type: {0} Address: {1}]\n", "WebService", ConfigHelper.GetEndpointClientAddress("StorageServiceImplPort")); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]</p>", "WebService", ConfigHelper.GetEndpointClientAddress("StorageServiceImplPort1")); var lastSyncTime = getMaxDateTime(settingManager); // from last sync time var from = lastSyncTime; // to now - 1h var to = startTime.AddHours(8).AddHours(-settingManager.DeltaHours); strInfo.AppendFormat("<p>Max '{0}' of table '{1}' : {2}.</p>", settingManager.DateKeyColumn, settingManager.DateKeyTable, from); strInfo.AppendFormat("<p>Sync duration : {0} to : {1} .</p>", from, to); try { using (var dataSync = new DataSynchronizer(settingManager, from, to)) { dataSync.TableSynched += (sender, e) => LogFileSyncInfo(sender, e); dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); var sourceTable = settingManager.SourceTableName.Split(','); strInfo.Append(dataSync.Sync(sourceTable)); } strInfo.AppendFormat("{0} table(s) synchronized.\n", settingManager.TableMappings.Count()); var endTime = DateTime.UtcNow; //strInfo.AppendFormat("Synchronization completed at {0}.\n", endTime.ToGMT8String()); logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow; logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n<b>Exception detail:</b>\n" + exception + "\n<p>No tables synchronized.</p>"; WriteLogEntity(logEntity); } }
protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); var lastSyncTime = new DateTime(2016, 8, 22); var currentSyncTime = DateTime.Now; using (var cneEntities = new CnEEntities()) { var date = cneEntities.SCHEDULERLOGs.Where(x => x.STATUS == 0 && x.JOBTYPE == JobType).Select( x => (DateTime?)x.STARTTIME).Max(); if (date != null) { lastSyncTime = date.Value.AddHours(8); strInfo.AppendFormat("Last successfully sync time : {0}.\n", lastSyncTime); //Add Buffer lastSyncTime = lastSyncTime.AddHours(-1); } } try { string settingFilePath2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\CusteelTo144.xml"); var settingManager2 = new XmlSettingManager(File.ReadAllText(settingFilePath2)); var DestinationDbConn2 = string.Empty; settingManager2.Init(DestinationDbConn2);//初始化 mapping strInfo.AppendFormat("Source [Type: {0} Address: {1}]\n", settingManager2.SourceDb.Type, settingManager2.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", settingManager2.DestinationDb.Type, settingManager2.DestinationDb.Conn); using (var dataSync = new DataSynchronizer(settingManager2, lastSyncTime, currentSyncTime)) { dataSync.TableSynched += (sender, e) => strInfo.AppendFormat ("{0} rows have been synchronized from {1} view in Cne DB to {2} table in Cne DB.\n", e.NumOfRowsSynched, e.Source, e.Dest); dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); var sourceTable = settingManager2.SourceTableName.Split(','); dataSync.Sync(sourceTable); } strInfo.AppendFormat("{0} table(s) be synchronized.\n", settingManager2.TableMappings.Count()); /***********************/ var endTime = DateTime.UtcNow; strInfo.AppendFormat("Synchronization completed at {0}.\n", endTime.ToGmt8String()); logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow; logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }
/// <summary> /// Execute the actual job. The job data map will already have been /// applied as object property values by execute. The contract is /// exactly the same as for the standard Quartz execute method. /// </summary> /// <seealso cref="M:Spring.Scheduling.Quartz.QuartzJobObject.Execute(Quartz.JobExecutionContext)"/> protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime, JOBTYPE = JobType }; var strInfo = new StringBuilder(); string settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\File-To-IPP-sync.xml"); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); // Set Connection string var destinationDbConn = string.Empty; settingManager.Init(destinationDbConn);//初始化 mapping strInfo.AppendFormat("<p>Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]</p>\n", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); var from = getMaxDateTime(settingManager); var to = startTime.AddHours(8).AddHours(-settingManager.DeltaHours); strInfo.AppendFormat("<p>Max '{0}' of table '{1}' : {2}.</p>", settingManager.DateKeyColumn, settingManager.DateKeyTable, from); strInfo.AppendFormat("<p>Sync duration : {0} to : {1} .</p>", from, to); try { using (var dataSync = new DataSynchronizer(settingManager, from, to)) { dataSync.TableSynched += (sender, e) => strInfo.AppendFormat ("{0} rows have been synchronized from {1} view in CMAFileDB to {2} table in IPP DB.\n", e.NumOfRowsSynched, e.Source, e.Dest); dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); strInfo.Append(dataSync.Sync(new[] { "GetNewInstitution", "GetNewFile" })); } strInfo.AppendFormat("{0} table(s) be synchronized.\n", settingManager.TableMappings.Count()); //Update File Topic strInfo.AppendFormat("<p>Update File Topic start at {0}.\n", DateTime.UtcNow.ToGMT8String()); var result = SyncUtil.UpdateFileTopic(from, to); strInfo.AppendFormat("Update File Topic completed at {0}.\n Result: {1}</p>", DateTime.UtcNow.ToGMT8String(), result); //Rebuild Index strInfo.AppendFormat("<p>Rebuild Index at {0}.\n", DateTime.UtcNow.ToGMT8String()); var result1 = SolrClient.RebuildIndex("full"); var endTime = DateTime.UtcNow; strInfo.AppendFormat("Rebuild Index completed at {0}.\n Result: {1}</p>", DateTime.UtcNow.ToGMT8String(), result); if (result1 != "Success") { strInfo.AppendFormat("<p style=\"color:red;\">Solr rebuild failed:<br />{0}</p>", result1); } logEntity.ENDTIME = endTime; logEntity.JobStatus = (result == "Success" && result1 == "Success") ? JobStatus.Success : JobStatus.Fail; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow; logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n<b>Exception detail:</b>\n" + exception + "\n<p>No tables synchronized.</p>"; WriteLogEntity(logEntity); } }
/// <summary> /// Execute the actual job. The job data map will already have been /// applied as object property values by execute. The contract is /// exactly the same as for the standard Quartz execute method. /// </summary> /// <seealso cref="M:Spring.Scheduling.Quartz.QuartzJobObject.Execute(Quartz.JobExecutionContext)"/> protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime, JOBTYPE = JobType }; var strInfo = new StringBuilder(); string settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\dsos-new-increment-sync.xml"); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); // Set Connection string //var entityConnectionString = // ConfigurationManager.ConnectionStrings["VAVEntities"].ConnectionString; //var connectionStringBuilder = new EntityConnectionStringBuilder(entityConnectionString); //var DestinationDbConn = connectionStringBuilder.ProviderConnectionString; settingManager.Init(string.Empty);//初始化 mapping strInfo.AppendFormat("DSOS Sync begin at {0}\n", startTime); strInfo.AppendFormat("Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); // Get Last successfully date time. var lastSyncTime = new DateTime(2015, 3, 1); using (var vavEntities = new VAVEntities()) { var date = vavEntities.SCHEDULERLOGs.Where(x => x.STATUS == 0 && x.JOBTYPE == this.JobType).Select( x => (DateTime?)x.STARTTIME).Max(); if (date != null) { lastSyncTime = date.Value; //Add Buffer lastSyncTime = lastSyncTime.AddHours(-1.5); } } strInfo.AppendFormat("Last successfully sync time : {0}(Eastern Standard Time).\n", startTime); try { List <string> tables; //if (hour >= 12 && hour <= 14) //sync iss_def //{ // //Delete iss_def // strInfo.AppendFormat("Delete iss_def at {0}.\n", DateTime.UtcNow.ToGMT8String()); // var re = SyncUtil.Delete_Iss_Def(); // strInfo.AppendFormat("Delete iss_def at {0}.\n Result: {1}", DateTime.UtcNow.ToGMT8String(), re); // tables = GetDsosSrcTablesToSync().ToList(); //} //else //{ // tables = GetDsosSrcTablesToSync().ToList(); // var s = tables.Single(t => t == "govcorp..iss_def"); // tables.Remove(s); //} tables = settingManager.TableMappings.Select(t => t.Source).ToList(); using (var dataSync = new DataSynchronizer(settingManager, lastSyncTime, startTime)) { dataSync.TableSynched += (sender, e) => strInfo.AppendFormat ("{0} rows have been synchronized from {1} view in DSOS to {2} table in VAV DB.\n", e.NumOfRowsSynched, e.Source, e.Dest); dataSync.PostTaskExecuted += (sender, e) => strInfo.AppendFormat ("Post sync task {0} is executed.\n", e.TaskName); dataSync.Init(); dataSync.Sync(tables); } strInfo.AppendFormat("{0} table(s) be synchronized.\n", settingManager.TableMappings.Count()); strInfo.AppendFormat("Synchronization completed at {0}.\n", DateTime.UtcNow.ToGMT8String()); //Update Bond Info strInfo.AppendFormat("Update Bond Info en&cn start at {0}.\n", DateTime.UtcNow.ToGMT8String()); //var result = SyncUtil.UpdateBondInfo(lastSyncTime, currentSyncTime); var endTime = DateTime.UtcNow; //strInfo.AppendFormat("Update Bond Info en&cn completed at {0}.\n Result: {1}", DateTime.UtcNow.ToGMT8String(), result); ////Rebuild Index //strInfo.AppendFormat("Rebuild Index at {0}.\n", DateTime.UtcNow.ToGMT8String()); //var result1 = SolrClient.RebuildIndex("full"); //strInfo.AppendFormat("Rebuild Index completed at {0}.\n Result: {1}", DateTime.UtcNow.ToGMT8String(), result1); logEntity.ENDTIME = endTime; //logEntity.JobStatus = (result == "Success" && result1 == "Success") ? JobStatus.Success : JobStatus.Fail; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow; logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }
protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; string connStr = ConfigurationManager.AppSettings["mergeData"]; var conn = new OracleConnection(connStr); conn.Open(); var tran = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); var strInfo = new StringBuilder(); string settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\MySteel-data-sync.xml"); var settingManager = new XmlSettingManager(File.ReadAllText(settingFilePath)); // Set Connection string var destinationDbConn = string.Empty; settingManager.Init(destinationDbConn);//初始化 mapping strInfo.AppendFormat("Source [Type: {0} Address: {1}]\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", settingManager.DestinationDb.Type, settingManager.DestinationDb.Conn); DateTime lastSyncTime; var currentSyncTime = DateTime.Now; using (var cmd = new OracleCommand("SELECT max(dLastAccess) FROM RTMS_TABLEDATA ", conn)) { object obj = cmd.ExecuteScalar(); lastSyncTime = Convert.ToDateTime(obj.ToString()); strInfo.AppendFormat("Last successfully sync time : {0}.\n", obj); } try { using (var dataSync = new DataSynchronizer(settingManager, lastSyncTime, currentSyncTime)) { dataSync.TableSynched += (sender, e) => strInfo.AppendFormat ("{0} rows have been synchronized from {1} table in SYNC_REUTERS DB to {2} table in CnE DB.\n", e.NumOfRowsSynched, e.Source, e.Dest); dataSync.Init(); var sourceTable = settingManager.SourceTableName.Split(','); dataSync.Sync(sourceTable); } strInfo.AppendFormat("{0} table(s) be synchronized.\n", settingManager.TableMappings.Count()); var merge = new MergeData(); merge.ExecuteMetals(conn, tran); tran.Commit(); var endTime = DateTime.UtcNow; logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { tran.Rollback(); logEntity.ENDTIME = DateTime.UtcNow.AddDays(-1); logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }