Exemple #1
0
        private List <EmailDetail> GetEmailList(DateTime lastSyncTime, SenderFilter attFetcherSenderFilter)
        {
            attFetcher.AppendFilter(attFetcherSenderFilter);
            attFetcher.Execute(lastSyncTime);
            List <EmailDetail> emails = attFetcher.GetEmailDetailList();

            return(emails);
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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();
            }
        }
Exemple #5
0
        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);
            }
        }