private void Retry_File_CreatedChanged(object sender, FileSystemEventArgs e) { if (m_FvInfoHolder.IsInitialized) { Task.Factory.StartNew((o) => { Thread.Sleep(500); FileSystemEventArgs args = (FileSystemEventArgs)o; var file = new FileInfo(args.FullPath); var xml = XElement.Load(args.FullPath); RootElementProcessor processor = new RootElementProcessor(m_FvInfoHolder); processor.Process(xml, file); file.Delete(); }, e); } }
protected override void ThreadFunction() { var dir = new DirectoryInfo(FvFinInputFolder); FileInfo[] files = dir.GetFiles("*.xml"); RootElementProcessor processor = new RootElementProcessor(this); int count = 0; foreach (var file in files) { if (!Running) { break; } if (count++ > MaxProcessFilesCount) { Trace.WriteLine("Too many files. Gets to Sleep.", "FLV"); break; } Trace.WriteLine("Processing file: {0}".format(file), "FLV"); if (!file.IsFileLocked()) { try { HashSet <string> uniqueSet = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); var elements = XDocument.Load(file.FullName).Descendants("root").ToList <XElement>(); foreach (XElement element in elements) { processor.Process(element, file, uniqueSet); Thread.Yield(); } Trace.WriteLine("Moving archive file: {0} to {1}".format(file.Name, ArchiveFolder), "FLV"); var name2 = Path.GetFileNameWithoutExtension(file.Name).Unique().Limit(250).concat(".xml"); var fileName = Path.Combine(ArchiveFolder, name2); file.MoveTo(fileName); } catch (Exception ex) { Trace.WriteLine("Error processing file: {0}".format(file.Name), "FLV"); Trace.WriteLine(ex.ToString(), "FLV"); Trace.WriteLine("Moving file to err folder: {0}".format(ErrorFolder), "FLV"); var fileName = Path.Combine(ErrorFolder, file.Name); new Action <string>((fn) => file.MoveTo(fn)).RunSafe(fileName); } finally { FireStep(); Trace.WriteLine("=============================", "FLV"); } } else { Trace.WriteLine("Splitter: File is locked: {0}".format(file), "FLV"); } } }