private static void GetFiles(StringCollection colFiles, ProcessingErrors colErrors, string sPathName, params string[] sFilePattern) { try { DirectoryInfo diBase = new DirectoryInfo(sPathName); foreach (string pattern in sFilePattern) { foreach (FileInfo fInfo in diBase.GetFiles(pattern)) { try { if ((fInfo.Attributes & FileAttributes.ReparsePoint) > 0) { continue; } if (!colFiles.Contains(fInfo.FullName)) { colFiles.Add(fInfo.FullName); } } catch (Exception ex) { colErrors.Add(new ProcessingError(fInfo.FullName, ex)); } } foreach (DirectoryInfo diSub in diBase.GetDirectories()) { try { if ((diSub.Attributes & FileAttributes.ReparsePoint) > 0) { continue; } GetFiles(colFiles, colErrors, diSub.FullName, pattern); } catch (Exception ex) { colErrors.Add(new ProcessingError(diSub.FullName, ex)); } } } } catch (Exception ex) { colErrors.Add(new ProcessingError(sPathName, ex)); } }
public virtual void ReadFrom(XElement xE) { Id = null; Status = null; ProgressStats = null; UploadUrl = null; DownloadUrl = null; ProcessingErrors = null; DiskUsageQuotaBalance = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "id") { Id = long.Parse(xItem.Value); } else if (localName == "status") { Status = BatchJobStatusExtensions.Parse(xItem.Value); } else if (localName == "progressStats") { ProgressStats = new ProgressStats(); ProgressStats.ReadFrom(xItem); } else if (localName == "uploadUrl") { UploadUrl = new TemporaryUrl(); UploadUrl.ReadFrom(xItem); } else if (localName == "downloadUrl") { DownloadUrl = new TemporaryUrl(); DownloadUrl.ReadFrom(xItem); } else if (localName == "processingErrors") { if (ProcessingErrors == null) { ProcessingErrors = new List <BatchJobProcessingError>(); } var processingErrorsItem = new BatchJobProcessingError(); processingErrorsItem.ReadFrom(xItem); ProcessingErrors.Add(processingErrorsItem); } else if (localName == "diskUsageQuotaBalance") { DiskUsageQuotaBalance = long.Parse(xItem.Value); } } }
private static void CreateXML_1(string sFileName, StringCollection colFiles, ProcessingErrors colErrors) { XmlDocument xmlFile = new XmlDocument(); XmlElement xmlAppdetect; XmlElement xmlFiles; XmlElement xmlFileName; XmlElement xmlFileResources; XmlElement xmlFileResource; XmlElement xmlIconImprint; XmlElement xmlFileBinImprint; XmlElement xmlErrorReport; XmlElement xmlError; xmlFile.AppendChild(xmlFile.CreateXmlDeclaration("1.0", "UTF-8", "")); xmlAppdetect = xmlFile.CreateElement("AppDetect"); xmlAppdetect.SetAttribute("ComputerName", System.Environment.MachineName); xmlAppdetect.SetAttribute("UserName", System.Environment.UserName); xmlAppdetect.SetAttribute("ProcessTime", System.DateTime.Now.ToString("yyyyMMddHHmmss")); foreach (string sFile in colFiles) { try { xmlFiles = xmlFile.CreateElement("File"); xmlFileName = xmlFile.CreateElement("Name"); xmlFileName.SetAttribute("FileName", Path.GetFileName(sFile)); xmlFileName.SetAttribute("PathName", Path.GetDirectoryName(sFile)); FileInfo FileInfo = new FileInfo(sFile); using (FileStream fin = FileInfo.Open(FileMode.Open, FileAccess.Read)) { xmlFileName.SetAttribute("Size", FileInfo.Length.ToString()); xmlFiles.AppendChild(xmlFileName); xmlFileResources = xmlFile.CreateElement("Resources"); PEFile pe = new PEFile(fin, (int)FileInfo.Length); foreach (KeyValuePair <string, string> dVS in pe.VersionInfo) { xmlFileResource = xmlFile.CreateElement("Resource"); xmlFileResource.SetAttribute("Name", dVS.Key.Replace(" ", "")); xmlFileResource.SetAttribute("Value", dVS.Value); xmlFileResources.AppendChild(xmlFileResource); } xmlFiles.AppendChild(xmlFileResources); xmlFileBinImprint = xmlFile.CreateElement("BinImprint"); xmlFileBinImprint.SetAttribute("Imprint", pe.BinImprint); xmlFiles.AppendChild(xmlFileBinImprint); pe.Dispose(); uint imprint = IconImprint.GetCRCFromIcon(sFile); if (imprint != 0) { xmlIconImprint = xmlFile.CreateElement("IconImprint"); xmlIconImprint.SetAttribute("Imprint", imprint.ToString("X8")); xmlFiles.AppendChild(xmlIconImprint); } } xmlAppdetect.AppendChild(xmlFiles); } catch (Exception ex) { colErrors.Add(new ProcessingError(sFile, ex)); } } xmlErrorReport = xmlFile.CreateElement("ErrorReport"); foreach (ProcessingError pError in colErrors) { xmlError = xmlFile.CreateElement("Message"); xmlError.SetAttribute("Type", "Error"); xmlError.SetAttribute("Number", "1"); xmlError.SetAttribute("File", pError.File); xmlError.SetAttribute("Text", pError.Exception.Message); xmlErrorReport.AppendChild(xmlError); } xmlAppdetect.AppendChild(xmlErrorReport); xmlFile.AppendChild(xmlAppdetect); XmlTextWriter xmlWriter = new XmlTextWriter(sFileName, System.Text.Encoding.GetEncoding("UTF-8")); xmlWriter.Formatting = Formatting.Indented; xmlFile.Save(xmlWriter); }