/// <summary> /// Move the spread sheet File to Quarantine /// </summary> /// <param name="s"></param> public void MoveToQuarantine(ForeCastFileInfo s) { try { String DirName = s.PathName + "\\" + "QUARANTINE\\"; String XlFile = s.XlsFile; int nindex = XlFile.LastIndexOf("\\"); String filename = XlFile.Substring(nindex + 1); String newfilename = DirName + DateAsStr(DateTime.Now) + "_" + filename; ///////////////////////////////////////////// /// /// IF Quarantine Folder does not exist /// Create a new one if (!Directory.Exists(DirName)) { Directory.CreateDirectory(DirName); } /////////////////////////////////////////// /// /// Copy the File to Quarantine /// if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile)) { throw new Exception(XlFile + " Copy: Cannot be accessed or opened by another app"); } File.Copy(XlFile, newfilename, true); ////////////////////////////////////////////// /// Delete the file /// if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile)) { throw new Exception(XlFile + " Cannot be accessed or opened by another app"); } File.Delete(XlFile); } catch (Exception e) { /////////////////////////////////////////////// /// /// Log the Exception /// System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString()); CSyntaxErrorLog.AddLine(e.ToString()); return; } }
/// <summary> /// Visit all the directories and return a list of files /// to process /// </summary> /// <param name="Path"></param> /// <param name="Filter"></param> /// <param name="first_time"></param> public void Visit(String Path, String Filter, bool first_time) { DirectoryInfo di = new DirectoryInfo(Path); DirectoryInfo[] dirs = di.GetDirectories("*.*"); if (first_time) { System.IO.FileInfo[] nts = di.GetFiles(Filter); foreach (FileInfo ns in nts) { ForeCastFileInfo fi = new ForeCastFileInfo(); fi.XlsFile = ns.FullName; fi.PathName = ns.DirectoryName; xls.Add(fi); } first_time = false; } // Iterate through all the directories // // foreach (DirectoryInfo diNext in dirs) { if (diNext.Name.ToUpper() == "BACKUP" || diNext.Name.ToUpper() == "QUARANTINE") { continue; } System.IO.FileInfo[] nts = diNext.GetFiles(Filter); foreach (FileInfo ns in nts) { ForeCastFileInfo fi = new ForeCastFileInfo(); fi.XlsFile = ns.FullName; fi.PathName = ns.DirectoryName; xls.Add(fi); } //// /// Recurse the subdirectories /// Visit(diNext.FullName + "\\", Filter, first_time); } }
/// <summary> /// Backup File /// </summary> /// <param name="s"></param> public void BackupFile(ForeCastFileInfo s) { try { String DirName = s.PathName + "\\" + "BACKUP\\"; String XlFile = s.XlsFile; int nindex = XlFile.LastIndexOf("\\"); String filename = XlFile.Substring(nindex + 1); String newfilename = DirName + DateAsStr(DateTime.Now) + "_" + filename; ///////////////////////////////////////////// /// /// IF Backup folder does not exist /// Create a new one if (!Directory.Exists(DirName)) { Directory.CreateDirectory(DirName); } ////////////////////////////////////// /// /// Move to Backup folder /// /// System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Copying File"); if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile)) { throw new Exception(XlFile + "Copy: Cannot be accessed or opened by another app"); } File.Copy(XlFile, newfilename, true); System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Finished Copying File"); if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile)) { throw new Exception(XlFile + "Delete: Cannot be accessed or opened by another app"); } File.Delete(XlFile); System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Finished Deleting File"); } catch (Exception e) { System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString()); CSyntaxErrorLog.AddLine(e.ToString()); return; } }
/// <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); } }