/// <summary> /// /// </summary> public void WriteLogEntity(SCHEDULERLOG logEntity) { using (var cneEntities = new CnEEntities()) { logEntity.JOBTYPE = JobType; cneEntities.SCHEDULERLOGs.Add(logEntity); cneEntities.SaveChanges(); } var detail = logEntity.RUNDETAIL; if (!String.IsNullOrEmpty(detail)) { detail = detail.Replace("\n", "<br/>"); } var str = String.Format("<Html><Body style='font-family:Verdana;font-size:12'><h2 style='color:{5}'>[{0}] Scheduler job \"<b>{1}</b>\" finished.</h2><hr/><p>Job Type:{1}</p><p>Start Time:{2}</p><p>End Time:{3}</p><p><b>Detail:</b></p><p>{4}</p></Body></Html>", logEntity.JobStatus, logEntity.JOBTYPE, logEntity.STARTTIME.ToGmt8String(), logEntity.ENDTIME.ToGmt8String(), detail, logEntity.JobStatus == JobStatus.Success ? "green" : "red"); if (logEntity.JobStatus == JobStatus.Success) { _log.Info(str); } else { _log.Error(str); } }
protected override void ExecuteInternal(JobExecutionContext context) { string connStr = ConfigurationManager.AppSettings["mergeData"].ToString(); SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlTransaction tran = conn.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted); var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); strInfo.AppendFormat("ChinaJci data Sync begin at {0}\n", DateTime.UtcNow.ToGmt8String()); var lastSyncTime = new DateTime(1900, 1, 1); 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) { //ToGMT8 lastSyncTime = date.Value.AddHours(8); } } try { #region 执行数据同步程序 MergeData merge = new MergeData(); //merge.Execute(conn, tran); tran.Commit(); #endregion 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) { tran.Rollback(); logEntity.ENDTIME = DateTime.UtcNow.AddDays(-1); logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } finally { conn.Close(); } }
protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var lastSyncTime = Convert.ToDateTime("2014-04-03"); using (var cneEntities = new CnEEntities()) { DateTime lastTime = DateTime.UtcNow.AddDays(-1); var date = cneEntities.SCHEDULERLOGs.Where(x => x.STATUS == 0 && x.JOBTYPE == JobType && x.STARTTIME < lastTime).Select( x => (DateTime?)x.STARTTIME).Max(); if (date != null) { lastSyncTime = date.Value.AddHours(8); } } var strInfo = new StringBuilder(); try { #region 执行数据同步程序 var settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\Ftp-MySteel-data-sync.xml"); var settingManager = new FtpSyncXmlManager(File.ReadAllText(settingFilePath), lastSyncTime.AddHours(8), startTime.AddHours(8)); settingManager.Init(); strInfo.AppendFormat("FTP DownLoad begin at {0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); strInfo.AppendFormat("Source [Type: {0} Address: {1}]\r\n", settingManager.SourceDb.Type, settingManager.SourceDb.Conn); var ftpSync = new FtpSyncLoad(settingManager, strInfo); ftpSync.Excute(); #endregion var endTime = DateTime.UtcNow; strInfo.AppendFormat("DownLoad completed at {0}.\r\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); } }
protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); strInfo.AppendFormat("WmpArea Sync begin at {0}\n", DateTime.UtcNow.ToGmt8String()); var lastSyncTime = Convert.ToDateTime("1900-1-1"); 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) { //ToGMT8 lastSyncTime = date.Value.AddHours(8); strInfo.AppendFormat("Last successfully time : {0}.\n", lastSyncTime); //Add Buffer lastSyncTime = lastSyncTime.AddHours(-1); } } try { #region 执行数据同步程序 var wmpArea = new WmpArea(); wmpArea.SyncData(strInfo, lastSyncTime); #endregion 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.AddDays(-1); logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }
public DateTime GetLastSyncTime() { var lastSyncTime = new DateTime(2001, 1, 1); using (var cneEntities = new CnEEntities()) { var date = cneEntities.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); } } return(lastSyncTime); }
public void Excute() { Log.Append("<table border=\"1\" style=\"border: 1px solid black; border-collapse: collapse;font-size: 14px;\"><tr style=\"font-size: 16px;font-weight: bold;text-align: center;\"><td>Data provider</td><td>JOBtype</td><td>source</td><td>destination</td><td>description</td><td>Frequency</td><td>Last Updated Date</td><td>Updated Rows</td></tr>"); foreach (var map in _monitorMaps) { using (var cneEntities = new CnEEntities()) { DateTime last = Convert.ToDateTime(_lastDate).AddHours(-8); var successCount = cneEntities.SCHEDULERLOGs.Where(x => x.STATUS == 0 && x.JOBTYPE == map.JobType && x.STARTTIME > last).Select(x => x.ID).Count(); var failCount = cneEntities.SCHEDULERLOGs.Where(x => x.STATUS == 1 && x.JOBTYPE == map.JobType && x.STARTTIME > last).Select(x => x.ID).Count(); var lastUpdateTime = cneEntities.SCHEDULERLOGs.Where(x => x.JOBTYPE == map.JobType).OrderByDescending(x => x.STARTTIME).Select(x => x.STARTTIME).First(); foreach (var source in map.Mappings) { Log.Append("<tr><td>" + source.DataProvider + "</td>"); Log.Append("<td>" + map.JobType + "</td>"); Log.Append("<td>" + source.Source + "</td>"); if (source.DestinationType == "FTP") { Log.Append("<td>" + source.DataProvider + " FTP</td>"); } else { Log.Append("<td>" + source.DestinationAddress + "</td>"); } Log.Append("<td>" + source.Description + "</td>"); //Log.Append("<td>" + successCount + "</td>"); //Log.Append("<td>" + failCount + "</td>"); Log.Append("<td>" + map.TriggerInterval + "</td>"); Log.Append("<td>" + lastUpdateTime + "</td>"); Log.Append("<td>"); switch (source.DestinationType) { case "SQLSERVER": MonitorDb(source); break; case "FTP": MonitorFtp(source); break; } Log.Append("</td></tr>"); } } } Log.Append("</table>"); }
protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); try { var lastSyncTime = new DateTime(2016, 9, 28); 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) { //ToGMT8 lastSyncTime = date.Value.AddHours(8); } } #region 执行数据同步程序 var fn = new FxNews(); fn.GetWebData(strInfo, lastSyncTime); #endregion var endTime = DateTime.UtcNow; logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow.AddDays(-1); 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 }; var lastSyncTime = Convert.ToDateTime("2016-12-18"); 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; } } var strInfo = new StringBuilder(); try { #region 执行数据同步程序 var mapListFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\Ftp-Map-data-sync.xml"); var doc = new XmlDocument(); doc.Load(mapListFilePath); var maplist = doc.SelectNodes("settings/map"); var arr = new ArrayList(); if (maplist != null) { foreach (XmlNode map in maplist) { arr.Add(map.InnerText); } } strInfo.AppendFormat("Source [Type: ORACLE Address: Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.35.63.143)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME = CMADB)));User Id=cne;Password=cne;]"); foreach (var map in arr) { strInfo.Append("\r\n"); var settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\" + map); var settingManager = new FtpSyncXmlManager(File.ReadAllText(settingFilePath), lastSyncTime.AddHours(8), startTime.AddHours(8)); settingManager.Init(); var ftpSync = new FtpSyncLoad(settingManager, strInfo); ftpSync.Excute(); } #endregion 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); } }
protected override void ExecuteInternal(JobExecutionContext context) { string connStr = ConfigurationManager.AppSettings["mergeData"]; OracleConnection conn = new OracleConnection(connStr); conn.Open(); OracleTransaction tran = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); strInfo.AppendFormat("Source [Email:{0},Title:{1}]\n", ConfigurationManager.AppSettings["LongZhongSenderFilter"], ConfigurationManager.AppSettings["LongZhongTitleFilter"]); strInfo.AppendFormat("Destination [Type: Oracle DB, Address: {0}]\n", connStr); var lastSyncTime = Convert.ToDateTime("2016-11-16"); 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) { //ToGMT8 lastSyncTime = date.Value.AddHours(8); } } try { #region 执行数据同步程序 var attFetcherSever = ConfigurationManager.AppSettings["CnEServer"]; int attFetcherPort = int.Parse(ConfigurationManager.AppSettings["CnEPort"]); bool attFetcherUsingSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["CnEUsingSsl"]); string attFetcherUserName = ConfigurationManager.AppSettings["CnEUserName"]; string attFetcherPassWord = ConfigurationManager.AppSettings["CnEPassWord"]; string attFetcherSavingPath = ConfigurationManager.AppSettings["LongZhongSavingPath"]; var attFetcher = new IMAP4AttFetcher(attFetcherSever, attFetcherPort, attFetcherUsingSsl, attFetcherUserName, attFetcherPassWord, attFetcherSavingPath); var attFetcherSenderFilter = new SenderFilter(); /*Filter example. If there are more filters , please write like below.*/ string[] senders = ConfigurationManager.AppSettings["LongZhongSenderFilter"].Split(';'); foreach (var sender in senders) { var senderRegex = new Regex(sender, RegexOptions.Compiled); attFetcherSenderFilter.SetRule(senderRegex); } attFetcher.AppendFilter(attFetcherSenderFilter); var attFetcherTitleFilter = new TitleFilter(); var titleRegex = new Regex(ConfigurationManager.AppSettings["LongZhongTitleFilter"], RegexOptions.Compiled); attFetcherTitleFilter.SetRule(titleRegex); attFetcher.AppendFilter(attFetcherTitleFilter); attFetcher.Execute(lastSyncTime); /*Get the saved attachment names.*/ var attachmentFileNames = attFetcher.GetAttachmentFileNames(); //List<string> attachmentFileNames = Directory.GetFiles(@"C:\DataFeedApp\Scheduler\CnE\LongZhong").ToList<string>(); foreach (var tempattachname in attachmentFileNames) { LongZhongExcelManager manager = new LongZhongExcelManager(); manager.GetCellsByFirstSheet(tempattachname, strInfo); } var fold = new DirectoryInfo(attFetcherSavingPath); if (fold.Exists) { FileInfo[] files = fold.GetFiles(); foreach (FileInfo f in files)//删除目录下所有文件 { f.Delete(); } } if (attachmentFileNames.Count > 0) { MergeData merge = new MergeData(); merge.ExecuteLongZhongExcel(conn, tran); tran.Commit(); strInfo.Append("Execute Procedure : CREATEMAXENERGYYIELDTABLE, CREATEMAXCHEMISTRYOUTPUTTABLE \r\n"); strInfo.Append("Insert Into Table : GDT_CHEMISTRYOUTPUTMAX, GDT_ENERGYYIELDMAX \r\n"); } else { strInfo.Append("No files found\r\n"); } #endregion var endTime = DateTime.UtcNow; logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); //merge data from temp to persistence } catch (Exception exception) { tran.Rollback(); logEntity.ENDTIME = DateTime.UtcNow.AddDays(-1); logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } finally { conn.Close(); conn.Dispose(); } }
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); } }
protected override void ExecuteInternal(JobExecutionContext context) { var strInfo = new StringBuilder(); #region 执行数据同步程序 if (DateTime.Now.Hour <= 15 || DateTime.Now.Hour >= 22) { strInfo.Append("Only this time(15:00Am-10:00Pm) point synchronous;"); return; } #endregion string connStr = ConfigurationManager.AppSettings["mergeData"].ToString(); OracleConnection conn = new OracleConnection(connStr); conn.Open(); OracleTransaction tran = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; strInfo.AppendFormat("Destination [Type: Oracle DB, Address: {0}]\n" + "\r\n", connStr); var lastSyncTime = new DateTime(2016, 9, 02); 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) { //ToGMT8 lastSyncTime = date.Value.AddHours(8); } } try { #region 执行数据同步程序 var ch = new ChinaJci(); var sbSync = new StringBuilder(); ch.SyncChinaJciData(ref sbSync, lastSyncTime.ToString("yyyy-MM-dd")); strInfo.AppendFormat(sbSync.ToString()); #endregion MergeData merge = new MergeData(); merge.Execute(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); } finally { conn.Close(); } }
protected override void ExecuteInternal(JobExecutionContext context) { var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); var lastSyncTime = Convert.ToDateTime("2014-01-21"); 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; } } try { #region 执行数据同步程序 var attFetcherSever = ConfigurationManager.AppSettings["CnEServer"]; int attFetcherPort = int.Parse(ConfigurationManager.AppSettings["CnEPort"]); bool attFetcherUsingSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["CnEUsingSsl"]); string attFetcherUserName = ConfigurationManager.AppSettings["CnEUserName"]; string attFetcherPassWord = ConfigurationManager.AppSettings["CnEPassWord"]; string attFetcherSavingPath = ConfigurationManager.AppSettings["NationaSavingPath"]; var attFetcher = new IMAP4AttFetcher(attFetcherSever, attFetcherPort, attFetcherUsingSsl, attFetcherUserName, attFetcherPassWord, attFetcherSavingPath); var attFetcherSenderFilter = new SenderFilter(); /*Filter example. If there are more filters , please write like below.*/ string[] senders = ConfigurationManager.AppSettings["NationaSenderFilter"].Split(';'); foreach (var sender in senders) { var senderRegex = new Regex(sender, RegexOptions.Compiled); attFetcherSenderFilter.SetRule(senderRegex); } attFetcher.AppendFilter(attFetcherSenderFilter); //var attFetcherTitleFilter = new TitleFilter(); //var titleRegex = new Regex(ConfigurationManager.AppSettings["NationaTitleFilter"], RegexOptions.Compiled); //attFetcherTitleFilter.SetRule(titleRegex); //attFetcher.AppendFilter(attFetcherTitleFilter); attFetcher.Execute(lastSyncTime); var attachmentFileNames = attFetcher.GetAttachmentFileNames(); strInfo.AppendFormat("Source [Type: Email , Sender: {0} ]\n", ConfigurationManager.AppSettings["NationaSenderFilter"]); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", "Oracle", ConfigurationManager.AppSettings["CnECon"]); foreach (var tempattachname in attachmentFileNames) { var nb = new NationalBureau(); nb.ImportTheWholeExcel(tempattachname, strInfo); } var fold = new DirectoryInfo(attFetcherSavingPath); if (fold.Exists) { FileInfo[] files = fold.GetFiles(); foreach (FileInfo f in files)//删除目录下所有文件 { f.Delete(); } } if (attachmentFileNames.Count == 0) { strInfo.Append("No find files .\r\n"); } #endregion var endTime = DateTime.UtcNow; logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo.ToString(); WriteLogEntity(logEntity); } catch (Exception exception) { logEntity.ENDTIME = DateTime.UtcNow.AddDays(-1); logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; WriteLogEntity(logEntity); } }
protected override void ExecuteInternal(JobExecutionContext context) { var connStr = ConfigurationManager.AppSettings["mergeData"]; var conn = new OracleConnection(connStr); conn.Open(); OracleTransaction tran = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); strInfo.AppendFormat("Source [Email:{0}]\n", ConfigurationManager.AppSettings["CoffedSenderFilter"]); strInfo.AppendFormat("Destination [Type: Oracle DB, Address: {0}]\n", connStr); strInfo.AppendFormat("Destination Table:Cofeed\n" + "\r\n"); var lastSyncTime = Convert.ToDateTime("2016-09-03"); 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) { //ToGMT8 lastSyncTime = date.Value.AddHours(8); } } try { StringBuilder sb = new StringBuilder(); #region 执行数据同步程序 var attFetcherSever = ConfigurationManager.AppSettings["CnEServer"]; int attFetcherPort = int.Parse(ConfigurationManager.AppSettings["CnEPort"]); bool attFetcherUsingSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["CnEUsingSsl"]); string attFetcherUserName = ConfigurationManager.AppSettings["CnEUserName"]; string attFetcherPassWord = ConfigurationManager.AppSettings["CnEPassWord"]; string attFetcherSavingPath = ConfigurationManager.AppSettings["CoffedSavingPath"]; var attFetcher = new IMAP4AttFetcher(attFetcherSever, attFetcherPort, attFetcherUsingSsl, attFetcherUserName, attFetcherPassWord, attFetcherSavingPath); var attFetcherSenderFilter = new SenderFilter(); string[] senders = ConfigurationManager.AppSettings["CoffedSenderFilter"].Split(';'); foreach (var sender in senders) { var senderRegex = new Regex(sender, RegexOptions.Compiled); attFetcherSenderFilter.SetRule(senderRegex); } attFetcher.AppendFilter(attFetcherSenderFilter); var attFetcherTitleFilter = new TitleFilter(); var titleRegex = new Regex(ConfigurationManager.AppSettings["CoffedTitleFilter"], RegexOptions.Compiled); attFetcherTitleFilter.SetRule(titleRegex); attFetcher.AppendFilter(attFetcherTitleFilter); attFetcher.Execute(lastSyncTime); var attachmentFileNames = attFetcher.GetAttachmentFileNames(); foreach (var tempattachname in attachmentFileNames) { CofeedManager manager = new CofeedManager(); manager.GetCellsByFirstSheet(tempattachname, sb); } strInfo.Append(sb); var fold = new DirectoryInfo(attFetcherSavingPath); if (fold.Exists) { FileInfo[] files = fold.GetFiles(); foreach (FileInfo f in files)//删除目录下所有文件 { f.Delete(); } } #endregion if (attachmentFileNames.Count > 0) { MergeData merge = new MergeData(); merge.Execute(conn, tran); tran.Commit(); strInfo.Append("Execute Procedure : createMaxAgricultrueTable \r\n"); strInfo.Append("Insert Into Table : GDT_AgricultureMax \r\n"); } else { strInfo.Append("No files found\r\n"); } var settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\Ftp-Cofeed-data-sync.xml"); var settingManager = new FtpSyncXmlManager(File.ReadAllText(settingFilePath), lastSyncTime, startTime.AddHours(8)); settingManager.Init(); var ftpSync = new FtpSyncLoad(settingManager, strInfo); ftpSync.Excute(); 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); } finally { conn.Close(); } }
protected override void ExecuteInternal(Quartz.JobExecutionContext context) { string connStr = ConfigurationManager.AppSettings["mergeData"].ToString(); OracleConnection conn = new OracleConnection(connStr); conn.Open(); OracleTransaction tran = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); strInfo.AppendFormat("Source [Email:{0}]\n", ConfigurationManager.AppSettings["CoffedProductSenderFilter"]); strInfo.AppendFormat("Destination [Type: Oracle DB, Address: {0}]\n", connStr); var lastSyncTime = Convert.ToDateTime("2016-11-14"); 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.AddMinutes(-10); } } try { #region 执行数据同步程序 var attFetcherSever = ConfigurationManager.AppSettings["CnEServer"]; int attFetcherPort = int.Parse(ConfigurationManager.AppSettings["CnEPort"]); bool attFetcherUsingSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["CnEUsingSsl"]); string attFetcherUserName = ConfigurationManager.AppSettings["CnEUserName"]; string attFetcherPassWord = ConfigurationManager.AppSettings["CnEPassWord"]; string attFetcherSavingPath = ConfigurationManager.AppSettings["CoffedProductSavingPath"]; var attFetcher = new IMAP4AttFetcher(attFetcherSever, attFetcherPort, attFetcherUsingSsl, attFetcherUserName, attFetcherPassWord, attFetcherSavingPath); var attFetcherSenderFilter = new SenderFilter(); string[] senders = ConfigurationManager.AppSettings["CoffedProductSenderFilter"].Split(';'); foreach (var sender in senders) { var senderRegex = new Regex(sender, RegexOptions.Compiled); attFetcherSenderFilter.SetRule(senderRegex); } attFetcher.AppendFilter(attFetcherSenderFilter); attFetcher.Execute(lastSyncTime); var attachmentFileNames = attFetcher.GetAttachmentFileNames(); // List<string> attachmentFileNames = Directory.GetFiles(@"C:\DataFeedApp\Scheduler\CnE\CoffedProductData").ToList<string>(); for (int i = attachmentFileNames.Count - 1; i >= 0; i--) { var tempattachname = attachmentFileNames[i]; if (tempattachname.IndexOf("Productinventory") != -1) { CofeedProductManager c = new CofeedProductManager(); c.GetCellsByFirstSheet(tempattachname, strInfo); } else if (tempattachname.IndexOf("week") != -1) { CoffedWeekManager c = new CoffedWeekManager(); c.GetCellsByFirstSheet(tempattachname, strInfo); } } var fold = new DirectoryInfo(attFetcherSavingPath); if (fold.Exists) { FileInfo[] files = fold.GetFiles(); foreach (FileInfo f in files)//删除目录下所有文件 { f.Delete(); } } if (attachmentFileNames.Count > 0) { MergeData m = new MergeData(); m.ExecuteCoffedAndMetalMax(conn, tran); strInfo.Append("Execute Procedure : CREATEMAXAGRICULTRUEOUTPUT\r\n"); strInfo.Append("Insert Into Table : GDT_AGRICULTRUEOUTPUTMAX, GDT_ENERGYYIELDMAX \r\n"); //生成MAX表; //ExecuteCoffedAndMetalMax tran.Commit(); } else { strInfo.Append("No files found\r\n"); } ; #endregion 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); } }
public static void ExcuteMailSync(string jobType, DateTime syncStartTime, string attFetcherSavingPath, string senderFilter, string titleFilter, string userName, string password , Action <SCHEDULERLOG> saveLog , Action <List <string>, StringBuilder> syncCallback , Action <OracleConnection, OracleTransaction> mergeCallback ) { string connStr = ConfigurationManager.AppSettings["mergeData"]; OracleConnection conn = new OracleConnection(connStr); conn.Open(); OracleTransaction tran = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); var startTime = DateTime.UtcNow; var logEntity = new SCHEDULERLOG { STARTTIME = startTime }; var strInfo = new StringBuilder(); var lastSyncTime = syncStartTime; 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; } } try { #region 执行数据同步程序 strInfo.AppendFormat("Source [Type: Email , Sender: {0} ,Title {1} ]\n", senderFilter, titleFilter); strInfo.AppendFormat("Destination [Type: {0} Address: {1}]\n", "Oracle", connStr); var attFetcherSever = ConfigurationManager.AppSettings["CnEServer"]; int attFetcherPort = int.Parse(ConfigurationManager.AppSettings["CnEPort"]); bool attFetcherUsingSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["CnEUsingSsl"]); string attFetcherUserName = userName; string attFetcherPassWord = password; var attFetcher = new IMAP4AttFetcher(attFetcherSever, attFetcherPort, attFetcherUsingSsl, attFetcherUserName, attFetcherPassWord, attFetcherSavingPath); var attFetcherSenderFilter = new SenderFilter(); /*Filter example. If there are more filters , please write like below.*/ string[] senders = senderFilter.Split(';'); foreach (var sender in senders) { var senderRegex = new Regex(sender, RegexOptions.Compiled); attFetcherSenderFilter.SetRule(senderRegex); } attFetcher.AppendFilter(attFetcherSenderFilter); if (!string.IsNullOrEmpty(titleFilter)) { var attFetcherTitleFilter = new TitleFilter(); var titleRegex = new Regex(titleFilter, RegexOptions.Compiled); attFetcherTitleFilter.SetRule(titleRegex); attFetcher.AppendFilter(attFetcherTitleFilter); } attFetcher.Execute(lastSyncTime); /*Get the saved attachment names.*/ var attachmentFileNames = attFetcher.GetAttachmentFileNames(); //var attachmentFileNames=new List<string>(); //attachmentFileNames.Add(@"C:\DataFeedApp\Scheduler\CnE\路透数据20161109.xls"); StringBuilder sb = new StringBuilder(); //var attachmentFileNames = Directory.GetFiles(@"C:\xx\troil").ToList<string>(); syncCallback(attachmentFileNames, sb); var fold = new DirectoryInfo(attFetcherSavingPath); if (fold.Exists) { FileInfo[] files = fold.GetFiles(); foreach (FileInfo f in files)//删除目录下所有文件 { f.Delete(); } } if (attachmentFileNames.Count == 0) { strInfo.Append("No find files .\r\n"); } #endregion var endTime = DateTime.UtcNow; logEntity.ENDTIME = endTime; logEntity.JobStatus = JobStatus.Success; logEntity.RUNDETAIL = strInfo + sb.ToString(); saveLog(logEntity); //merge data from temp to persistence if (mergeCallback != null) { mergeCallback(conn, tran); } tran.Commit(); } catch (Exception exception) { tran.Rollback(); logEntity.ENDTIME = DateTime.UtcNow.AddDays(-1); logEntity.JobStatus = JobStatus.Fail; logEntity.RUNDETAIL = strInfo + "\n" + exception; saveLog(logEntity); } finally { conn.Close(); conn.Dispose(); } }