/// <summary> /// /// </summary> /// <param name="sheet"></param> /// <param name="column"></param> /// <param name="rec_num"></param> /// <returns></returns> public String GetColumnValue(String sheet, String column, int rec_num) { String name; try { name = ((DataTable)m_Table[sheet + "$"]).Columns[column].ToString(); } catch (Exception) { CSemanticErrorLog.AddLine("Column name contains space " + column + " " + sheet); throw new CParserException(-100, "Column name contains space", -1); } DataTable t = ((DataTable)m_Table[sheet + "$"]); Type st = t.Rows[rec_num][name].GetType(); object obj = (t.Rows[rec_num][name]); if (st == Type.GetType("System.DBNull")) { CSemanticErrorLog.AddLine("NULL VALUE FOUND IN " + sheet + " " + column); CSemanticErrorLog.AddLine("Entry Line " + Convert.ToString(rec_num + 1)); return(""); } return(obj.ToString()); }
/// <summary> /// /// </summary> /// <param name="SheetName"></param> /// <returns></returns> public bool CheckHourly() { String SheetName = "HOURLY_DISTRIBUTION"; String[] days; days = new String[7]; days[0] = "SUNDAY"; days[1] = "MONDAY"; days[2] = "TUESDAY"; days[3] = "WEDNESDAY"; days[4] = "THURSDAY"; days[5] = "FRIDAY"; days[6] = "SATURDAY"; DataTable tab = GetDataTable(SheetName); int rec_count = tab.Rows.Count; int index = 0; int jt = 0; while (index < rec_count) { DataRow row = tab.Rows[index]; int ctr = Convert.ToInt16(row["HOUR"]); String hr = Convert.ToString(row["DAY"]).Trim().ToUpper(); if (hr != days[jt % 7] || ctr != index % 24) { CSemanticErrorLog.AddLine("HOURLY_DISTRIBUTION worksheet invalid at row " + Convert.ToString(index + 1)); return(false); } index++; if (index % 24 == 0) { jt++; } } return(true); }
/// <summary> /// Check for Null /// </summary> /// <param name="sheet"></param> /// <param name="arr"></param> /// <returns></returns> public bool HasNull(String sheet, ArrayList arr) { int nCount = arr.Count; if (nCount == 0) { return(false); } DataTable t = GetDataTable(sheet); DataColumnCollection cols = t.Columns; try { int nItems = t.Rows.Count; int index = 0; while (index < nItems) { DataRow row = t.Rows[index]; for (int k = 0; k < arr.Count; ++k) { if (row[arr[k].ToString()].GetType() == Type.GetType("System.DBNull")) { CSemanticErrorLog.AddLine("Null or No data in Column = " + arr[k]); return(true); } } index++; } return(false); } catch (Exception e) { CSyntaxErrorLog.AddLine(e.ToString()); throw e; } }
//////////////////////////////////////////////////////// /// /// Here is the actual workhorse /// /// public static void ScanForForeCastData() { try { while (true) { //////////////////////////////// /// /// Clean up all the data /// CSyntaxErrorLog.Cleanup(); CSemanticErrorLog.Cleanup(); GlobalSettings.Cleanup(); /////////////////// /// /// Do Processing /// ScanAndProcess(); ///////////////////////////////////////// /// /// Sleep the Thread for 2 minutes. /// in the production build , it should run /// in an interval of at least 10 minutes /// /// System.GC.Collect(); System.Threading.Thread.Sleep(60000 * 5); } } catch (Exception e) { System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Exception thrown by the Thread"); System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString()); } return; }
/// <summary> /// Update Routine /// Loop as long as a valid file is found /// </summary> public bool Update() { bool bVal = true; while (true) { CDirectoryWalker x = new CDirectoryWalker(); x.Visit(m_rootPath, "*.XLS", true); ArrayList r = x.GetAllXls(); /////////////////////////////// /// if no more file is found ... /// stop this iteration /// if (r.Count == 0) { break; } foreach (ForeCastFileInfo s in r) { //////////////////////////////////////////////////// /// /// Stop processing , if thread has been requested to stop processing /// /// if (GlobalSettings.request_processing_thread_abort == true) { return(bVal); } /////////////////////////////// /// Clean up the Error Logs before /// we go for fresh processing /// CSemanticErrorLog.Cleanup(); CSyntaxErrorLog.Cleanup(); CSemanticErrorLog.Cleanup(); //////////////////////////////////////// /// /// Try to Validate the file /// GlobalSettings.oracle_connection_count = 0; GlobalSettings.excel_connection_count = 0; if (ValidateFile(s)) { System.GC.Collect(); /////////////////////////////////////////////// /// /// Validation and updation is successful /// Check for the backup_sheets flag and /// Back up the File , if it is true /// if (GlobalSettings.oracle_connection_count != 0) { System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.oracle_connection_count)); } if (GlobalSettings.excel_connection_count != 0) { System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.excel_connection_count)); } if (GlobalSettings.backup_sheets == true) { BackupFile(s); } } else { /////////////////////////////////// /// At least one stuff failed in this iteration /// left unused /// if (bVal) { bVal = false; } /////////////////////////////////////////////////// /// /// Failure in updating ForeCast Data /// Try to Quarantine the file , if /// quarantine_sheets flag is true /// if (GlobalSettings.oracle_connection_count > 0) { System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.oracle_connection_count)); } if (GlobalSettings.excel_connection_count > 0) { System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.excel_connection_count)); } if (GlobalSettings.quarantine_sheets == true) { MoveToQuarantine(s); } } } break; } return(bVal); }
/// <summary> /// Call the Excel content Validator /// </summary> /// <param name="s"></param> public bool ValidateFile(ForeCastFileInfo s) { CParser prs = null; CExcelDBUpdate upd = null; try { if (!ForeCastUpdatorService.CanFilebeAccessed(s.XlsFile)) { throw new Exception(s.XlsFile + " Cannot be accessed or opened by another app"); } String m_Country = this.GetCountryFromPath(s.XlsFile); String m_Segment = this.GetSegmentFromPath(s.XlsFile); System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Processing File ...." + s.XlsFile); String Prgs = (String)GlobalSettings.GetEntry("VALIDATION_SCRIPT"); String OrclConStr = (String)GlobalSettings.GetEntry("ORACLE_CONNECTION_STRING"); String ExcelConStr = "Provider=" + (String)GlobalSettings.GetEntry("EXCEL_PROVIDER"); ExcelConStr += "Data Source=" + s.XlsFile + ";"; ExcelConStr += (String)GlobalSettings.GetEntry("EXCEL_PROPERTIES"); CSemanticErrorLog.AddLine("Excel file = " + s.XlsFile); prs = new CParser(Prgs, m_Country, m_Segment); bool brs = prs.CallParser(ExcelConStr, OrclConStr); bool ret_val = true; if (brs == true) { upd = new CExcelDBUpdate(OrclConStr, prs.GetExcelReader()); ret_val = upd.UpdateAll(); if (ret_val == false) { CSemanticErrorLog.AddLine("FATAL ERROR WHILE UPDATING FORECAST DATA "); } } if (ret_val == true && brs == true) { if (GlobalSettings.allow_emails == true) { notify.TO = prs.GetEmail(); notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog(); notify.SendToExcelEmail(0); } if (GlobalSettings.event_logging == true) { if (!System.Diagnostics.EventLog.SourceExists("ForeCastLog")) { System.Diagnostics.EventLog.CreateEventSource("ForeCastLog", "DoForeCastLog"); } System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog() + prs.GetSyntaxLog()); } if (upd != null) { upd.Cleanup(); upd = null; } if (prs != null) { prs.CloseAll(); prs = null; } return(ret_val); } else { if (GlobalSettings.event_logging == true) { if (!System.Diagnostics.EventLog.SourceExists("ForeCastLog")) { System.Diagnostics.EventLog.CreateEventSource("ForeCastLog", "DoForeCastLog"); } System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog() + prs.GetSyntaxLog()); } if (GlobalSettings.allow_emails == true) { notify.TO = prs.GetEmail(); notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog(); notify.SendToExcelEmail(1); notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog() + prs.GetSyntaxLog(); notify.Send(1); } if (upd != null) { upd.Cleanup(); upd = null; } if (prs != null) { prs.CloseAll(); prs = null; } return(false); } } catch (Exception e) { System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString()); CSemanticErrorLog.AddLine(e.ToString()); if (GlobalSettings.event_logging == true) { if (!System.Diagnostics.EventLog.SourceExists("ForeCastLog")) { System.Diagnostics.EventLog.CreateEventSource("ForeCastLog", "DoForeCastLog"); } System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + CSemanticErrorLog.GetLog() + CSyntaxErrorLog.GetLog()); } if (GlobalSettings.allow_emails == true) { notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + CSemanticErrorLog.GetLog() + CSyntaxErrorLog.GetLog(); notify.Send(1); } if (upd != null) { upd.Cleanup(); upd = null; } if (prs != null) { prs.CloseAll(); prs = null; } return(false); } }