public LanCleaner(Cache shared_data, LanCleaner configuration) : base(shared_data, configuration) { FileDeletionCollection = configuration.FileDeletionCollection; // Clone the module variables table to the table that will contain the files deleted by the module. DeletedFilesTable = GlobalOutputTable.Clone(); }
private void ProcessFile() { DataRow fileContentRow = null; DataTable fileContentShell = null; // Load the file into the readers file object. Logger.WriteLine("BaseFileReader.OnProcess", " OPENING: " + FileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Open(this, new EventArgs()); // Load the file into the readers CompleteFileContents data table. Load(this, new EventArgs()); fileContentShell = CompleteFileContents.Clone(); fileContentShell.TableName = Name; // Add the cloned table to the shared data as the modul's output table. SharedData.Add(fileContentShell); if (EndRow == 0 || EndRow > CompleteFileContents.Rows.Count) { EndRow = CompleteFileContents.Rows.Count; } if (StartRow <= CompleteFileContents.Rows.Count) { // Loop through the CompleteFileContents.Rows until we reach EndRow. for (int i = (StartRow - 1); i <= EndRow - 1; i++) { // Copy the file's row contents to the reader's output table. fileContentRow = GlobalOutputTable.NewRow(); fileContentRow.ItemArray = CompleteFileContents.Rows[i].ItemArray; GlobalOutputTable.Rows.Add(fileContentRow); } Logger.WriteLine("BaseFileReader.OnProcess", " ", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("BaseFileReader.OnProcess", " STATUS: SUCCESSFULL", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("BaseFileReader.OnProcess", " ROWCOUNT: " + GlobalOutputTable.Rows.Count, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } else { Logger.WriteLine("BaseFileReader.OnProcess", " ", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("BaseFileReader.OnProcess", " STATUS: NO DATA", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } Close(this, new EventArgs()); }
protected override void OnProcess(object sender, EventArgs e) { foreach (FileDeletion file in FileDeletionCollection.Items) { if (TextParser.Parse(file.Enabled, DrivingData, SharedData, ModuleCommands).ToLower() == bool.TrueString.ToLower()) { if (TextParser.IsTableCommand(file.FileName, SharedData)) { foreach (DataRow row in TextParser.GetCommandTable(file.FileName, SharedData).Select(TextParser.Parse(file.Filter, DrivingData, SharedData, ModuleCommands))) { DrivingData = row; DeleteFile(file.FileName, file.Directory); DrivingData = null; } } else { DeleteFile(file.FileName, file.Directory, file.Filter); } } else { Logger.WriteLine("LanCleaner.Process", "", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("LanCleaner.Process", " SOURCE DIRECTORY: " + file.FileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("LanCleaner.Process", " ENABLED: " + TextParser.Parse(file.Enabled, DrivingData, SharedData, ModuleCommands), System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } } // Update the modules output table to contain all files deleted by this module. foreach (DataRow deleted_file in DeletedFilesTable.Rows) { GlobalOutputTable.Rows.Add(deleted_file.ItemArray); GlobalOutputTable.AcceptChanges(); } }
public void DeleteFile(string current_file_name, string current_directory, string filter) { DirectoryInfo current_directory_info = null; // Parse the directory and file name using the driving data. if (!string.IsNullOrEmpty(current_directory)) { current_directory = TextParser.Parse(current_directory, DrivingData, SharedData, ModuleCommands); } else { current_directory = TextParser.Parse(SharedData.TempFileDirectory, DrivingData, SharedData, ModuleCommands); } current_file_name = TextParser.Parse(current_file_name, DrivingData, SharedData, ModuleCommands); Logger.WriteLine("LanCleaner.Process", "", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("LanCleaner.Process", " SOURCE DIRECTORY: " + current_directory, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("LanCleaner.Process", " SEARCH PATTERN: " + current_file_name, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); // Verify the directory exists. if (System.IO.Directory.Exists(current_directory)) { // Get the directory the cleaner is referencing. current_directory_info = new DirectoryInfo(current_directory); // Collect the files. If a wildcard is used in the name, multiple files could be returned. var file_list = current_directory_info.GetFiles(current_file_name, SearchOption.TopDirectoryOnly).ToList(); Logger.WriteLine("LanCleaner.Process", " MATCHED FILE COUNT: " + file_list.Count, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); foreach (FileInfo info in file_list) { Logger.WriteLine("LanCleaner.Process", " MATCHED: " + info.Name, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); // Add the current file results to the modules global output table. SetModuleCommands(info); AddResults(); } Logger.WriteLine("LanCleaner.Process", "", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); if (!string.IsNullOrEmpty(filter)) { Logger.WriteLine("LanCleaner.Process", " FILTER: " + TextParser.Parse(filter, DrivingData, SharedData, ModuleCommands), System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } foreach (DataRow row in GlobalOutputTable.Select(TextParser.Parse(filter, DrivingData, SharedData, ModuleCommands))) { // Delete the files that meet the filter criteria. Logger.WriteLine("LanCleaner.Process", " DELETING: " + row["FileName"].ToString(), System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); System.IO.File.Delete(row["FileFullName"].ToString()); // Copy the files the module deleted to the DeleteFilesTable. DeletedFilesTable.Rows.Add(row.ItemArray); } // Accept the new rows to the table. DeletedFilesTable.AcceptChanges(); // Clear all the rows from the modules global output table. // This needs to be done because at this point the table will contain all files that // matched the results of CurrentDirectoryInfo.GetFiles and not just the files that // met the filter criteria. Once processing is complete for the module the global cache table // will be updated with the DeletedFilesTable. GlobalOutputTable.Rows.Clear(); } }