Esempio n. 1
0
        /// <summary>
        /// Load all xml file and convert to List<Type>
        /// </summary>
        /// <returns></returns>
        public static List <Models.Type> LoadTypes(ECMA2Yaml.Models.ECMAStore store)
        {
            string xmlFolder    = _xmlDataFolder.Replace(_repoRootFolder, "").Trim(Path.DirectorySeparatorChar);
            var    typeFileList = _fileAccessor.ListFiles("*.xml", xmlFolder, allDirectories: true);
            ConcurrentBag <Models.Type> typeList = new ConcurrentBag <Models.Type>();
            ParallelOptions             opt      = new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            Parallel.ForEach(typeFileList, opt, typeFile =>
            {
                XDocument xmlDoc = XDocument.Load(typeFile.AbsolutePath);

                if (xmlDoc.Root.Name.LocalName == "Type")
                {
                    Models.Type t = ConvertToType(xmlDoc, store);
                    if (t != null)
                    {
                        typeList.Add(t);
                    }
                }
            });

            return(typeList.ToList());
        }
Esempio n. 2
0
        public void RepairAll()
        {
            _fileAccessor = new FileAccessor(_sourceFolder, null);
            var           allXmlFileList        = _fileAccessor.ListFiles("*." + _fileExtension, _sourceFolder, allDirectories: true).ToList();
            List <string> needRepairXmlFileList = new List <string>();
            List <string> msdnUrlList           = new List <string>();

            int modifyFileCounter = 0;

            for (int i = 0; i < allXmlFileList.Count(); i++)
            {
                var xmlFile = allXmlFileList[i];
                if (RepairFile(xmlFile.AbsolutePath))
                {
                    modifyFileCounter++;
                }
                if (modifyFileCounter >= _batchSize)
                {
                    break;
                }
            }
            string message = $"Repair done, Total file:{allXmlFileList.Count()}, updated file:{modifyFileCounter}";

            WriteLine(message);
            logMessages.Add(message);
        }