private void OnModify(object sender, FileSystemEventArgs e) { Utilities.Files fileUtil = new Utilities.Files(); while (fileUtil.IsFileLocked(e.FullPath)) { Thread.Sleep(500); } if (e.Name.StartsWith("SR")) // cannot use Config.Filter cause the * at the end of string... { Console.WriteLine("[INFO] New Structured Report"); Console.WriteLine(e.FullPath); Console.WriteLine(); Report report = new Report(); report.CreateFullReport(new FileInfo(e.FullPath), Config.tempOut); } File.Delete(e.FullPath); }
public bool BuildODT(DirectoryInfo tempDirectory, FileInfo outFile, bool deleteSourceFiles) { Utilities.Files fileUtil = new Utilities.Files(); if (!fileUtil.IsFileLocked(outFile.FullName)) { try { if (outFile.Exists) { Console.WriteLine("[INFO] Trying to backup old report."); outFile.CopyTo(outFile.FullName + ".bak", true); outFile.Delete(); } } catch (IOException copyError) { Console.WriteLine("[ERROR] Could not make backup file. Aborting.\nError:{0}", copyError.Message); return false; } try { Utilities.Zippit.MakeZip(tempDirectory.FullName, outFile.FullName); Console.WriteLine("[INFO] Created report: {0}", outFile.FullName); } catch (Exception ex) { // Win32Exception - An error occurred when opening the associated file. // ObjectDisposedException - The process object has already been disposed. // FileNotFoundException - The PATH environment variable has a string containing quotes. Console.WriteLine("[ERROR] ODT could not be created. Aborting.\nError:{0}", ex.Message); } if (deleteSourceFiles) { try { Directory.Delete(tempDirectory.FullName, true); Console.WriteLine("[INFO] Temporal files deleted."); } catch (IOException deleteError) { Console.WriteLine("[WARN] Could not delete temporal folder.\nError:{0}", deleteError.Message); return true; } } return true; } else { Console.WriteLine("[WARN] Destination file '{0}' locked by another application", outFile.Name); Console.WriteLine(); return false; } }