Esempio n. 1
0
        private void GetFiles(XMLFileList xml, DirectoryInfo dir, string replaceFolder)
        {
            var rootFolder = new DirectoryInfo(root).Name;

            foreach (var item in dir.GetFiles())
            {
                RunDoShowInfo("检测文件:" + item.Name + "\n");
                var fileinfo = new XMLFileInfo();
                var file     = new FileInfo(item.FullName);
                fileinfo.Name = item.Name;
                RunDoShowInfo("计算Hash值..\n");
                fileinfo.Hash = Utility.GetMD5Value(item.FullName);
                RunDoShowInfo("Hash值:" + fileinfo.Hash + "\n");
                var oP = rootFolder + item.FullName.Split(new string[] { rootFolder }, StringSplitOptions.RemoveEmptyEntries)[1];
                fileinfo.Address     = oP;
                fileinfo.InstallPath = oP.Replace(replaceFolder, "");
                RunDoShowInfo("当前文件检测完毕!\n");
                if (versionXML.x_ProcessInfo.path == item.FullName)
                {
                    versionXML.x_ProcessInfo.path = fileinfo.InstallPath;
                }
                xml.Files.Add(fileinfo);
            }
            foreach (var item in dir.GetDirectories())
            {
                RunDoShowInfo("进入目录:" + item.FullName + "\n");
                GetFiles(xml, item, replaceFolder);
            }
        }
Esempio n. 2
0
        private void GetFiles(XMLFileList xml, DirectoryInfo dir, string replaceFolder)
        {
            var rootFolder = new DirectoryInfo(GlobalData.config.config_Create.rootDirectory).Name;

            foreach (var item1 in Directory.GetFiles(dir.FullName, "*", SearchOption.AllDirectories))
            {
                RunDoShowProgressBar(++pvalue, pmax);
                RunDoShowPercent((pvalue / (float)pmax).ToString("0%"));
                var item = new FileInfo(item1);
                RunDoShowCheckInfo("检测文件:" + item.Name + "\n");
                var fileinfo = new XMLFileInfo();
                var file     = new FileInfo(item.FullName);
                fileinfo.Name = item.Name;
                RunDoShowCheckInfo("计算Hash值..\n");
                fileinfo.Hash = Utility.GetMD5Value(item.FullName);
                RunDoShowCheckInfo("Hash值:" + fileinfo.Hash + "\n");
                var oP = rootFolder + item.FullName.Split(new string[] { rootFolder }, StringSplitOptions.RemoveEmptyEntries)[1];
                fileinfo.Address     = oP;
                fileinfo.InstallPath = oP.Replace(replaceFolder, "");
                RunDoShowCheckInfo("当前文件检测完毕!\n");
                if (versionXML.x_ProcessInfo.path == item.FullName)
                {
                    versionXML.x_ProcessInfo.path = fileinfo.InstallPath;
                }
                xml.Files.Add(fileinfo);
            }
            //foreach (var item in dir.GetDirectories())
            //{
            //    RunDoShowCheckInfo("进入目录:" + item.FullName + "\n");
            //    GetFiles(xml, item, replaceFolder);
            //}
        }
Esempio n. 3
0
        /// <method>
        /// Read the XML content from file into dictionary
        /// </method>
        public void ProcessXMLFile()
        {
            int seqNo = 0;

            // If files exist then delete All files from the directory else create directory
            if (Directory.Exists(LAXMLFilesPath))
            {
                foreach (string file in Directory.GetFiles(LAXMLFilesPath))
                {
                    File.Delete(file);
                }
            }
            else
            {
                Directory.CreateDirectory(LAXMLFilesPath);
            }

            //Get the XML files from input path and read the content and store it in XML dictionary
            foreach (string path in Directory.GetFiles(inputXMLFilesPath))
            {
                StringBuilder sb               = new StringBuilder();
                bool          isDocIdElement   = false;
                string        docId            = string.Empty;
                string        docIdElementName = "docinfo:doc-id";
                XmlTextReader xmlReader        = new XmlTextReader(path);
                while (xmlReader.Read())
                {
                    switch (xmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (xmlReader.Name.ToLower() == docIdElementName)
                        {
                            isDocIdElement = true;
                        }
                        break;

                    case XmlNodeType.Text:
                        if (isDocIdElement)
                        {
                            docId          = xmlReader.Value;
                            isDocIdElement = false;
                        }

                        sb.AppendLine(xmlReader.Value.Trim());
                        break;

                    case XmlNodeType.EndElement:
                        break;
                    }
                }

                docId = docId.Replace("-", "_");
                string xmlFileName = LAXMLFilesPath + "\\" + docId + ".txt";
                File.WriteAllText(xmlFileName, sb.ToString());
                Console.WriteLine(++seqNo + " XML file Processed : " + docId);


                //Check docId is already exist or not
                if (dictXmlFiles.ContainsKey(docId) == true)
                {
                    duplicateXmlFilesName.Add(docId);
                }
                else
                {
                    dictXmlFiles.Add(docId, sb.ToString());
                    var xmlInfo = new XMLFileInfo()
                    {
                        XMLFileName = Path.GetFileName(path),
                        XMLDocID    = docId
                    };
                    xmlFileInfos.Add(xmlInfo);
                }
            }
        }