private void checkFilesLoaded(Dictionary <string, clsFileList> processFiles) { string findFile = string.Empty; string destFilename = string.Empty; DocLibHelper dlh = new DocLibHelper(); // Check if we have anything to do if (processFiles.Count == 0) { return; } Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Checking files have loaded"); foreach (clsFileList f in processFiles.Values) { // PI UFL renames the files to use the following format: // <original filename><datetime>._OK findFile = String.Format("{0}*._OK", f.Filename.Substring(0, f.Filename.Length - 4)); DirectoryInfo di = new DirectoryInfo(f.Directory); FileInfo[] rgFiles = di.GetFiles(findFile); foreach (FileInfo fi in rgFiles) { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "File loaded: " + fi.FullName); destFilename = string.Format("{0}\\{1}", ConfigurationSettings.AppSettings["FolderLoaded"], f.Filename); Utils.WriteToLog(Utils.LogSeverity.Info, processName, String.Format("Moving file to {0}", destFilename)); Utils.CopyLocalFileFromTo(fi.FullName, destFilename, true); // log status in db var ProcessedFilesQuery = from processedFiles in windARTDataContext.ProcessFiles where processedFiles.Name == f.FullFilePath && processedFiles.FileStatus == (int)Utils.FileStatus.Verified select processedFiles; foreach (ProcessFile pf in ProcessedFilesQuery) { pf.FileStatus = (int)Utils.FileStatus.Loaded; pf.Name = destFilename; windARTDataContext.SubmitChanges(); // set Sharepoint status dlh.UpdateFileStatus(pf.ProcessFileId, Utils.FileStatus.Loaded, f.FileFormatId, f.SiteId); } } } }
private void parkFile(clsFileList vf, ProcessFile pf) { DocLibHelper dlh = new DocLibHelper(); // move file into Parked folder string destFilename = ConfigurationSettings.AppSettings["FolderParked"] + @"\" + vf.Filename; Utils.CopyLocalFileFromTo(vf.FullFilePath, destFilename, true); // set db status pf.FileStatus = (int)Utils.FileStatus.Parked; pf.Name = destFilename; windARTDataContext.SubmitChanges(); // set Sharepoint status dlh.UpdateFileStatus(pf.ProcessFileId, Utils.FileStatus.Parked, 0, 0); Utils.WriteToLog(Utils.LogSeverity.Warning, processName, vf.FullFilePath + " parked - unknown formart"); }
public void IdentifyFileFormat(Dictionary <string, clsFileList> verifyFiles) { List <String> importedFileContent; bool headersMatch = false; bool multiLineHeadersMatch = false; DocLibHelper dlh = new DocLibHelper(); string destFilename = string.Empty; foreach (clsFileList vf in verifyFiles.Values) { importedFileContent = loadFileFromList(vf); if (importedFileContent == null) { Utils.DeleteMissingFileinDB(vf); continue; } // Did we load a file with content? // Only check data matches if we did if (importedFileContent != null && importedFileContent.Count > 0) { multiLineHeadersMatch = false; headersMatch = true; // repeat whilst we are finding a header // but mismatching the multiline header rows while (headersMatch && !multiLineHeadersMatch) { headersMatch = checkHeaderMatchs(importedFileContent, vf); // Now we have the fileFormatId, check the multi line details match if (headersMatch) { multiLineHeadersMatch = checkMultiLineHeaderMatchs(importedFileContent, vf); } } } var ProcessedFilesQuery = from processedFiles in windARTDataContext.ProcessFiles where processedFiles.Name == vf.FullFilePath && processedFiles.FileStatus == (int)Utils.FileStatus.ReadyForImport select processedFiles; foreach (ProcessFile pf in ProcessedFilesQuery) { if (headersMatch && multiLineHeadersMatch) { // insert date from Julian date insertDateFromJulianDate(importedFileContent); // save file contents to file destFilename = string.Format("{0}\\f{1}_{2}", ConfigurationSettings.AppSettings["FolderVerified"], vf.FileFormatId.ToString().PadLeft(4, '0'), vf.Filename); saveToFile(importedFileContent, destFilename); // remove original file File.Delete(vf.FullFilePath); // set db status pf.FileStatus = (int)Utils.FileStatus.Verified; pf.FileFormatId = vf.FileFormatId; pf.Name = destFilename; pf.SiteId = vf.SiteId; windARTDataContext.SubmitChanges(); // set Sharepoint status dlh.UpdateFileStatus(pf.ProcessFileId, Utils.FileStatus.Verified, (int)pf.FileFormatId, (int)pf.SiteId); Utils.WriteToLog(Utils.LogSeverity.Info, processName, vf.FullFilePath + " verified as formart " + vf.FileFormatId); unParkFile(vf); } else { parkFile(vf, pf); } } } }
public void GetEmail() { bool connected = false; Utils.WriteToLogStart(processName); if (Utils.GetKeyFromConfig("SkipSharepoint") != "True") { DocLibHelper dlh = new DocLibHelper(); Utils.WriteToLog(Utils.LogSeverity.Info, processName, "About to get sharepoint list"); System.Xml.XmlNode emailDetails = dlh.GetList(Utils.GetKeyFromConfig("ApplicationConfigurationSite"), Utils.GetKeyFromConfig("EmailReaderList")); Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Finished getting sharepoint list"); // null return means we had a problem contacting sharepoint if (emailDetails != null) { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "About to read sharepoint list"); // copy the xml structure to a dataset DataSet objDataSet = new DataSet(); XmlNodeReader ObjXmlreadrer = new XmlNodeReader(emailDetails); objDataSet.ReadXml(ObjXmlreadrer); foreach (DataRow row in objDataSet.Tables[1].Rows) { #region assign dataset to vars title = row["ows_Title"].ToString(); emailServerType = row["ows_EmailServerType"].ToString(); serverAddress = row["ows_ServerAddress"].ToString(); emailAccount = row["ows_EmailAccount"].ToString(); emailPassword = row["ows_EmailPassword"].ToString(); destinationFolder = row["ows_DestinationFolder"].ToString(); SSL = row["ows_SSL"].ToString(); if (row["ows_Port"].ToString() != "") { port = int.Parse(row["ows_Port"].ToString()); } immediateExcelExtract = row["ows_ImmediateExcelExtract"].ToString(); enabled = row["ows_Enabled"].ToString(); domain = row["ows_Domain"].ToString(); #endregion if (int.Parse(enabled) == 1) { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Init Exchange mailbox"); // Argh, the class ExchangeClient does not extend ProtocolClient, like the others... // So have to deal with with this type separately if (emailServerType.ToUpper() == "EXCHANGE") { ExchangeClient exchangeClient = null; exchangeClient = new ExchangeClient(serverAddress, emailAccount, emailPassword, "HE1"); readInbox(exchangeClient); } else { ProtocolClient client = null; if (emailServerType.ToUpper() == "POP3") { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Init POP3 mailbox"); client = new Pop3Client(); } else if (emailServerType.ToUpper() == "IMAP") { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Init IMAP mailbox"); client = new ImapClient(); } Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Connecting..."); connected = connect(client); Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Connected"); if (connected) { Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Reading mailbox..."); readInbox(client); Utils.WriteToLog(Utils.LogSeverity.Info, processName, "Finished reading mailbox"); } } } } } else { Utils.WriteToLog(Utils.LogSeverity.Warning, processName, "Problem accessing SharePoint list"); } } else { title = "Test"; emailServerType = "IMAP"; serverAddress = "imap.gmail.com"; emailAccount = "*****@*****.**"; emailPassword = "******"; destinationFolder = @"C:\PipelineData\0.EmailFolder"; SSL = "Yes"; port = 993; ProtocolClient client = null; if (emailServerType.ToUpper() == "POP3") { client = new Pop3Client(); } else if (emailServerType.ToUpper() == "IMAP") { client = new ImapClient(); } connected = connect(client); if (connected) { readInbox(client); } } Utils.WriteToLogFinish(processName); }
public void processEncryptedFiles(Dictionary<string, clsFileList> encryptedFiles) { DocLibHelper dlh = new DocLibHelper(); string newFilename = string.Empty; foreach (clsFileList cfl in encryptedFiles.Values) { //if (cfl.Encrypted) //{ Utils.WriteToLog(Utils.LogSeverity.Info, processName, String.Format("Attempting to decrypt: {0}", cfl.FullFilePath)); // Ensure the destination file doesn't exist // otherwise the NRG app will create a new filename! newFilename = Utils.GetKeyFromConfig("FolderReadyForImport") + @"\" + Utils.DropExtension(cfl.Filename) + ".txt"; File.Delete(newFilename); bool result = Utils.Exec(Utils.GetKeyFromConfig("NRGExecutable"), String.Format("/s \"{0}\" ", cfl.FullFilePath), true); // Check new file exists bool newFileExists = File.Exists(newFilename); if (result && newFileExists) { // Update status in MOSS to decrypted dlh.UpdateFileStatus(cfl.ProcessFileId, Utils.FileStatus.Decrypted, cfl.FileFormatId, cfl.SiteId); // Update status in DB Utils.UpdateStatusInDB(cfl, Utils.FileStatus.Decrypted); // Remove original encrypted file File.Delete(cfl.FullFilePath); // add to db // add to sharepoint cfl.OriginalFullFilepath = cfl.FullFilePath; cfl.ProcessFileId = 0; cfl.FullFilePath = newFilename; cfl.Encrypted = false; // addNewFileToDB Utils.RecordFileDetailsInDB(cfl, processName); // addNewFileToSharePoint Utils.CopyFilesToDocumentLibrary(cfl, Utils.FileStatus.ReadyForImport, processName); } else { try { Utils.WriteToLog(Utils.LogSeverity.Critical, processName, String.Format("Error decrypting: {0}", cfl.FullFilePath)); // Move problematic file File.Delete(Utils.GetKeyFromConfig("FolderParked") + @"\" + cfl.Filename); if (File.Exists(cfl.FullFilePath)) { File.Move(cfl.FullFilePath, Utils.GetKeyFromConfig("FolderParked") + @"\" + cfl.Filename); // Update status in DB Utils.UpdateStatusInDB(cfl, Utils.FileStatus.Parked); // Update status in MOSS to decrypted dlh.UpdateFileStatus(cfl.ProcessFileId, Utils.FileStatus.Parked, cfl.FileFormatId, cfl.SiteId); } else { //the file does not exist. Remove the entry from processfile and report the action Utils.WriteToLog(Utils.LogSeverity.Info, processName, String.Format("File does not exist, removing from listing: {0}", cfl.FullFilePath)); Utils.DeleteMissingFileinDB(cfl); } } catch (Exception e) { Utils.WriteToLog(Utils.LogSeverity.Critical, processName, String.Format("Error moving file to parked folder: {0}", e.Message)); } } //} } }