private void ProcessFiles(xmds.xmds xmds, string key, string type) { // Test for old files DateTime testDate = DateTime.Now.AddDays(ApplicationSettings.Default.LibraryAgentInterval * -1); // Track processed files int filesProcessed = 0; // Get a list of all the log files waiting to be sent to XMDS. DirectoryInfo directory = new DirectoryInfo(ApplicationSettings.Default.LibraryPath); // Loop through each file foreach (FileInfo fileInfo in directory.GetFiles("*" + type + "*")) { if (fileInfo.LastAccessTime < testDate) { Trace.WriteLine(new LogMessage("LogAgent - Run", "Deleting old file: " + fileInfo.Name), LogType.Info.ToString()); File.Delete(fileInfo.FullName); continue; } // Only process as many files in one go as configured if (filesProcessed >= ApplicationSettings.Default.MaxLogFileUploads) { break; } // construct the log message StringBuilder builder = new StringBuilder(); builder.Append("<log>"); foreach (string entry in File.ReadAllLines(fileInfo.FullName)) { builder.Append(entry); } builder.Append("</log>"); if (type == ApplicationSettings.Default.StatsLogFile) { xmds.SubmitStats(ApplicationSettings.Default.ServerKey, key, builder.ToString()); } else { xmds.SubmitLog(ApplicationSettings.Default.ServerKey, key, builder.ToString()); } // Delete the file we are on File.Delete(fileInfo.FullName); // Increment files processed filesProcessed++; } }
private void ProcessFiles(xmds.xmds xmds, string key, string type) { // Get a list of all the log files waiting to be sent to XMDS. string[] logFiles = Directory.GetFiles(ApplicationSettings.Default.LibraryPath, "*" + type + "*"); // Track processed files int filesProcessed = 0; // Loop through each file foreach (string fileName in logFiles) { // Only process as many files in one go as configured if (filesProcessed >= ApplicationSettings.Default.MaxLogFileUploads) { break; } // construct the log message StringBuilder builder = new StringBuilder(); builder.Append("<log>"); foreach (string entry in File.ReadAllLines(fileName)) { builder.Append(entry); } builder.Append("</log>"); if (type == ApplicationSettings.Default.StatsLogFile) { xmds.SubmitStats(ApplicationSettings.Default.ServerKey, key, builder.ToString()); } else { xmds.SubmitLog(ApplicationSettings.Default.ServerKey, key, builder.ToString()); } // Delete the file we are on File.Delete(fileName); // Increment files processed filesProcessed++; } }