public bool SaveOrUpdateOMRecords(OMNITURE_DATA omData, string fweek) { bool isFileSaved = false; try { using (var ctx = new TODEntities()) { DateTime currDate = TodDateUtils.GetCurrentTimeInIST(); string fiscalweek = TodDateUtils.GetWeekOfYearFor(TodDateUtils.GetCurrentTimeInIST()); DateTime ceStartDate = currDate.AddDays(-7).Date; DateTime ceEndDate = currDate.AddDays(-1).Date; omData.FW_ID = fweek; omData.FW_START_DATE = ceStartDate; omData.FW_END_DATE = ceEndDate; omData.REP_GEN_DATE = currDate; omData.OMNITURE_STATUS = "Success"; ctx.OMNITURE_DATA.Attach(omData); ctx.Entry <OMNITURE_DATA>(omData).State = omData.SEQUENCE_ID == 0 ? EntityState.Added : EntityState.Unchanged; ctx.SaveChanges(); } isFileSaved = true; } catch (Exception e) { log.Info(e.Message); isFileSaved = false; } return(isFileSaved); }
public void Execute(IJobExecutionContext context) { log.Info("Comment Extractor Execution started at : " + TodDateUtils.GetCurrentTimeInIST().Date); string userID = "delltools"; string password = "******"; AutoResetEvent resultEvent = new AutoResetEvent(false); //string result = null; browser = new IEBrowser(visible, userID, password, resultEvent); //browser = new IEBrowser(visible, "delltools", "g9eDx5IWlseQEeSvknxz", resultEvent); // wait for the third thread getting result and setting result event EventWaitHandle.WaitAll(new AutoResetEvent[] { resultEvent }); // the result is ready later than the result event setting somtimes //while (browser == null || browser.HtmlResult == null) Thread.Sleep(5); //result = browser.HtmlResult; //if (!visible) browser.Dispose(); Dispose(); //throw new NotImplementedException(); log.Info("Comment Extractor Execution completed @ " + TodDateUtils.GetCurrentTimeInIST().Date); //return (Task)context.Result; }
public static void StartAsync() { bool jobExecStatus = false; string schlogMessage = ""; try { //IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); log.Info("Scheduler instance invoked."); ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); IScheduler scheduler = schedulerFactory.GetScheduler(); IJobDetail job = JobBuilder.Create <SchedulerJob>().Build(); log.Info("Job instance created"); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("CEExtractorJob", "CEJOB") //"0 30 10 - 13 ? *WED,FRI" //"0 0 11 ? *MON" //.WithCronSche1dule("0 20 * 1/1 * ? *") //every 15 minutes //.WithCronSchedule("0 0/50 * * * ?") //every mon @ 1 PM IST Run the job and extract Comment Extractor Details .WithCronSchedule("0 0 13 ? * MON") //.StartAt(DateTime.UtcNow) .StartNow() .WithPriority(1) .Build(); log.Info("Job Trigger created"); scheduler.ScheduleJob(job, trigger); schedulerJobMessage = "Comment Extraction Scheduled to run @ " + TodDateUtils.GetCurrentTimeInIST(); log.Info("Scheduler scheduled instantiation successfully"); //register to listeners // add scheduler listener //scheduler.ListenerManager.AddSchedulerListener(); TodSchedulerJobListener todjoblistener = new TodSchedulerJobListener("CESchJobListener"); JobKey jk = new JobKey("CEExtractorJob", "CEJOB"); // add global job listener scheduler.ListenerManager.AddJobListener(todjoblistener, GroupMatcher <JobKey> .AnyGroup()); // add global trigger listener // scheduler.ListenerManager.AddTriggerListener(new GlobalTriggerListener(), GroupMatcher<TriggerKey>.AnyGroup()); //sched.ListenerManager.AddJobListener(todjoblistener, KeyMatcher<JobKey>.KeyEquals(jk)); log.Info("Scheduler registered successfully for job listener"); schlogMessage = "Scheduler scheduled successfully @ " + TodDateUtils.GetCurrentTimeInIST(); scheduler.Start(); log.Info("scheduler instance created and started"); jobExecStatus = true; } catch (Exception e) { log.Debug("Exception Occured. Detailed Exception is : "); log.Debug("--------"); log.Debug(e.Message); log.Debug("---------"); log.Debug("Stacktrace of the error is : \n" + e.StackTrace); schlogMessage = "Comment Extraction scheduled for " + DateTime.Now + " failed. Please check with Administrator for more details."; jobExecStatus = false; } //save the execution status with message to database scheduler log. try { using (var ctx = new TODEntities()) { TOD_TransactionLog todlog = new TOD_TransactionLog(); todlog.logtype = "CESCHLOG"; todlog.logdate = DateTime.Now.Date.ToString(); todlog.logMessage = schlogMessage; todlog.logStatus = jobExecStatus.ToString(); ctx.TOD_TransactionLog.Add(todlog); ctx.SaveChanges(); } } catch (Exception e) { log.Debug("Exception Occured. Detailed Exception is : "); log.Debug("--------"); log.Debug(e.Message); log.Debug("---------"); log.Debug("Stacktrace of the error is : \n" + e.StackTrace); schlogMessage = "Database Connection lazy initialization failed. Please check with administrator for more details."; jobExecStatus = false; } }
// DocumentCompleted event handle void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { HtmlDocument doc = null; string docUrl = ieBrowser.Url.ToString(); bool isErrorSet = false; try { /*if (doc.Title.Equals("Welcome to Windows Live") && loginCount++ < 3) * { * // set email address and password, and try to login three times * try { doc.GetElementById("i0116").SetAttribute("value", userName); } catch { * ieBrowser.Navigate("http://login.live.com/#"); * return; * } * doc.GetElementById("i0118").SetAttribute("value", password); * doc.GetElementById("idSIButton9").InvokeMember("click"); * } * else * { * // request jscript to call c# callback function with a parameter of navigation counter * doc.InvokeScript("setTimeout", new object[] { string.Format("window.external.getHtmlResult({0})", navigationCounter), 10 }); * }*/ if (docUrl.StartsWith(signinUrl)) { doc = ((WebBrowser)sender).Document; doc.GetElementById("UserName").SetAttribute("value", userName); doc.GetElementById("Password").SetAttribute("value", password); doc.GetElementById("loginButton").InvokeMember("click"); } } catch (Exception re) { log.Info("Sign-In to Reach Server failed. Error is : " + re.StackTrace); isErrorSet = true; } if (!isErrorSet) { try { if (docUrl.Contains(singintokenUrl)) { ieBrowser.Navigate(ceUrl); isErrorSet = false; } } catch (Exception ne) { log.Info("Reach Server Navigation failed. Error is : " + ne.StackTrace); isErrorSet = true; } if (!isErrorSet) { // request jscript to call c# callback function with a parameter of navigation counter //doc.InvokeScript("setTimeout", new object[] { string.Format("window.external.getHtmlResult({0})", navigationCounter), 10 });*/ if (docUrl.Equals(ceUrl)) { string tempDir = "C:/IDTools/temp"; DirectoryInfo di; string tempFileName = null; String tempFile = "/tempReachFormat.xml"; XmlDocument xmlDoc = null; XmlNodeList xnList = null; try { if (!Directory.Exists(tempDir)) { di = Directory.CreateDirectory(tempDir); tempFileName = di.FullName + tempFile; } else { tempFileName = tempDir + tempFile; } StreamWriter writer = File.CreateText(tempFileName); writer.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); //.Replace("- <", "<").Replace("&","&")); StringBuilder strb = new StringBuilder(ieBrowser.Document.Body.InnerText.ToString()); strb = strb.Replace("&", "&"); strb = strb.Replace("- <", "<").Replace("&", "&"); strb = strb.Replace("&", "&"); strb = strb.Replace("<", "<"); strb = strb.Replace(">", ">"); strb = strb.Replace("<lcform", "<lcform"); strb = strb.Replace("</lcform>", "</lcform>"); strb = strb.Replace("<name", "<name"); strb = strb.Replace("</name>", "</name>"); strb = strb.Replace("<email", "<email"); strb = strb.Replace("</email>", "</email>"); strb = strb.Replace("<summary", "<summary"); strb = strb.Replace("</summary>", "</summary>"); strb = strb.Replace("<description", "<description"); strb = strb.Replace("</description>", "</description>"); strb = strb.Replace("<reftext", "<reftext"); strb = strb.Replace("</reftext>", "</reftext>"); strb = strb.Replace("</xform>", "</xform>"); strb = strb.Replace("</instances>", "</instances>"); strb = strb.Replace("<instances", "<instances"); strb = strb.Replace("<xform", "<xform"); strb = strb.Replace("\" />", "\" />"); strb = strb.Replace("\">", "\">"); strb = strb.Replace("topic_title=\"\"?\"and \"? <subcommand>\"\"", "topic_title=\" <subcommand>\""); strb = strb.Replace("topic_title=\"Befehlszeilenhandbuch \"CLI Reference\"\"", "topic_title=\" Befehlszeilenhandbuch CLI Reference\""); writer.Write(strb.ToString()); xmlDoc = new XmlDocument(); /**string m = webBrowser1.Document.Body.InnerText.ToString().Replace("- <", "<"); * m = m.Replace("&", "&"); * m = m.Replace("<","<"); * m = m.Replace(">", ">"); * m = m.Replace("<lcform", "<lcform"); * m = m.Replace("</lcform>", "</lcform>"); * m = m.Replace("<name", "<name"); * m = m.Replace("</name>", "</name>"); * m = m.Replace("<email", "<email"); * m = m.Replace("</email>", "</email>"); * m = m.Replace("<summary", "<summary"); * m = m.Replace("</summary>", "</summary>"); * m = m.Replace("<description", "<description"); * m = m.Replace("</description>", "</description>"); * m = m.Replace("<reftext", "<reftext"); * m = m.Replace("</reftext>", "</reftext>"); * m = m.Replace("</xform>", "</xform>"); * m = m.Replace("</instances>", "</instances>"); * m = m.Replace("<instances", "<instances"); * m = m.Replace("<xform", "<xform"); * m = m.Replace("\" />", "\" />"); * m = m.Replace("\">","\">"); * m = m.Replace("topic_title=\"\"?\"and \"? <subcommand>\"\"", "topic_title=\"?and ? <subcommand>\""); * * /* temp to date the strings * DateTime tempdelete = Convert.ToDateTime("02/01/2016"); * string s2 = tempdelete.ToString("yyyy-MM-dd"); * DateTime dtnew = Convert.ToDateTime(s2); */ //MessageBox.Show(dtnew.AddDays(-7).ToString("MM-dd-yyyy")); // System.Console.Write(m);**/ // doc.Save(writer); writer.Close(); xmlDoc.Load(tempFileName); xnList = xmlDoc.SelectNodes("//lcform"); //File.Delete("LCR_Comments_" + String.Format("{0:yyyy_MM_dd}", DateTime.Today) + ".xlsx"); //FileInfo newFile = new FileInfo(@"D:\temp\LCR_Comments_" + String.Format("{0:yyyy_MM_dd}", DateTime.Today) + ".xlsx"); //FileInfo newFile = new FileInfo(@"LCR_Comments_" + String.Format("{0:yyyy_MM_dd}", DateTime.Today) + ".xlsx"); //ieBrowser.Dispose(); isErrorSet = false; log.Info("Comment Extraction completed Successfully from Reach Server."); } catch (Exception ce) { log.Info("Comment Extraction failed. Error is : " + ce.StackTrace); isErrorSet = true; } string schlogMessage = ""; //Save the Comments Extracted into the database if (!isErrorSet) { try { log.Info("Comment Extracted Data saving to Database initiated."); DateTime currDate = TodDateUtils.GetCurrentTimeInIST(); string fiscalweek = TodDateUtils.GetWeekOfYearFor(TodDateUtils.GetCurrentTimeInIST()); DateTime ceStartDate = currDate.AddDays(-7).Date; DateTime ceEndDate = currDate.AddDays(-1).Date; FW_CALENDAR fwcal = null; using (var ctx = new TODEntities()) { fwcal = new FW_CALENDAR(); fwcal.ID = 1; fwcal.Fiscal_Week = "FW" + fiscalweek; ctx.Entry <FW_CALENDAR>(fwcal).State = fwcal.Fiscal_Week == null ? EntityState.Added : EntityState.Unchanged; ctx.SaveChanges(); var ceDataList = new List <CE_DATA>(); foreach (XmlNode xn in xnList) { //prepare the cedata set based on the condition string tempDate = xn.Attributes["created"].Value; DateTime dt = Convert.ToDateTime(tempDate); if (dt.Date >= ceStartDate && dt.Date != DateTime.Now.Date) { CE_DATA cedataset = new CE_DATA(); cedataset.FW_CALENDAR = fwcal; cedataset.FW_ID = fwcal.Fiscal_Week; cedataset.REP_GEN_DATE = currDate; cedataset.CREATED_DATE = dt; cedataset.CREATED_TIME = dt; cedataset.FW_START_DATE = ceStartDate; cedataset.FW_END_DATE = ceEndDate; cedataset = processNodeAttributes(cedataset, xn); string tempText = xn.InnerText; string[] words = tempText.Split('|'); int interCoun = 7; for (int i = 0; i < words.Length; i++) { if (i != 0 && i % 2 == 0) { if (interCoun < 10) { //worksheet.Cells[columnCount, interCoun].Style.Numberformat.Format = "###0"; int temp = int.Parse(words[i]); //worksheet.Cells[columnCount, interCoun].Value = temp; switch (interCoun) { case 7: //accurate rating cedataset.ACCURATE_RATING = temp; break; case 8: //useful rating cedataset.USEFUL_RATING = temp; break; case 9: //easy to understand rating cedataset.EASY_TO_UNDERSTAND_RATING = temp; break; } } else { switch (interCoun) { case 10: //Article Resolved Issue cedataset.ARTICLE_SOLVED_ISSUE = words[i]; break; case 11: //feedback cedataset.FEEDBACK = words[i]; break; } //worksheet.Cells[columnCount, interCoun].Value = words[i]; } interCoun++; } } cedataset.CE_STATUS = "Success"; ctx.Entry <CE_DATA>(cedataset).State = cedataset.CE_SEQUENCE_ID == 0 ? EntityState.Added : EntityState.Unchanged; ceDataList.Add(cedataset); } } //attach the disconnected entities ctx.CE_DATA.AddRange(ceDataList); //save the cedata set to database ctx.SaveChanges(); schlogMessage = "Comment Extraction scheduled @ " + currDate + " successfully extracted " + ceDataList.Count() + " records. CE Next Scheduled is " + TodDateUtils.GetFutureTimeInIST(7); TodScheduler.schedulerJobMessage = schlogMessage; TodScheduler.schStatus = true; log.Info(schlogMessage); //save log info into log table TOD_TransactionLog todlog = new TOD_TransactionLog(); todlog.logtype = "CEDataLog"; todlog.logdate = DateTime.Now.Date.ToString(); todlog.logMessage = schlogMessage; todlog.logStatus = true.ToString(); ctx.TOD_TransactionLog.Add(todlog); ctx.SaveChanges(); } } catch (DbEntityValidationException dbev) { schlogMessage = "Comment Extraction scheduled @ " + TodDateUtils.GetCurrentTimeInIST() + " failed. CE Next Scheduled is " + TodDateUtils.GetFutureTimeInIST(7); TodScheduler.schedulerJobMessage = schlogMessage; log.Info(schlogMessage); TodScheduler.schStatus = false; log.Info(dbev.Message); log.Info("Saving CE Data Failed. Exception occured " + dbev.InnerException); } catch (DbUpdateException dbe) { schlogMessage = "Comment Extraction scheduled @ " + TodDateUtils.GetCurrentTimeInIST() + " failed. CE Next Scheduled is " + TodDateUtils.GetFutureTimeInIST(7); TodScheduler.schedulerJobMessage = schlogMessage; log.Info(schlogMessage); TodScheduler.schStatus = false; log.Info(dbe.Message); log.Info("Saving CE Data Failed. Exception occured " + dbe.InnerException); } DisposeBrowser(true); } } } } }