private bool FindDefAndContentFileName(string dirPath, string xmlFileName, out XMLDefContentFileName xMLDefContent)
        {
            xMLDefContent = default;
            var xmlFile = XDocument.Load(dirPath + "\\" + xmlFileName);
            IEnumerable <XMLDefContentFileName> elems = new List <XMLDefContentFileName>();

            elems = from el in xmlFile.Descendants("ValidityFixed")?.Elements("NamesList")
                    select new XMLDefContentFileName
            {
                roots           = el.Attribute("Roots")?.Value.Replace(" ", string.Empty),
                defFileName     = xmlFileName,
                contentFileName = xmlFile.XPathSelectElement("IGE-XAO_DIAGRAM_DEFINITION/Diagram/ContentFile/Content")?.
                                  Attribute("FileName")?.Value.Replace(@".\", string.Empty)
            };

            if (elems?.Count() > 0)
            {
                xMLDefContent = elems.First();
                if (xMLDefContent.contentFileName == null)
                {
                    _errorMessages.Add($"Content file does not exist for definition file {xMLDefContent.defFileName}");
                    return(false);
                }
                if (elems?.Count() > 1)
                {
                    _errorMessages.Add($"For def file {xMLDefContent.defFileName} cannot be more than 1 element 'NameList'");
                    return(false);
                }
                return(true);
            }
            return(false);
        }
        private HashSet <XMLDefContentFileName> FindPHPairFiles(string directoryPathXMLFiles)
        {
            DirectoryInfo          taskDirectory = new DirectoryInfo(directoryPathXMLFiles);
            IEnumerable <FileInfo> xmlFiles      = taskDirectory.GetFiles("*.xml", SearchOption.TopDirectoryOnly);

            HashSet <XMLDefContentFileName> setXMLDefContent = new HashSet <XMLDefContentFileName>(new XMLDefContentFileNameComparer());

            foreach (var fileName in xmlFiles)
            {
                if (fileName == null)
                {
                    _errorMessages.Add("File name is null for one of the xml files");
                    continue;
                }

                if (!setXMLDefContent.Contains(new XMLDefContentFileName {
                    contentFileName = fileName.Name
                }))
                {
                    XMLDefContentFileName xmlDefContent = new XMLDefContentFileName();
                    if (FindDefAndContentFileName(directoryPathXMLFiles, fileName.Name, out xmlDefContent))
                    {
                        setXMLDefContent.Add(xmlDefContent);
                    }
                }
            }
            return(setXMLDefContent);
        }
        private HashSet <XMLDefContentFileName> GetPHDefContentFilesAsync(IEnumerable <FileInfo> xmlFiles, string directoryPathXMLFiles)
        {
            List <Task> tasks = new List <Task>();
            HashSet <XMLDefContentFileName> setXMLDefContent = new HashSet <XMLDefContentFileName>(new XMLDefContentFileNameComparer());

            foreach (var fileName in xmlFiles)
            {
                if (fileName == null)
                {
                    _errorMessages.Add("File name is null for one of the xml files");
                    continue;
                }

                XMLDefContentFileName xmlDefContent = new XMLDefContentFileName();
                var result = Task.Run(() => FindDefAndContentFileName(directoryPathXMLFiles, fileName.Name, out xmlDefContent));
                tasks.Add(result);
                if (result.Result)
                {
                    lock (_xmlPH)
                    {
                        setXMLDefContent.Add(xmlDefContent);
                    }
                }
            }
            Task.WaitAll(tasks.ToArray());
            return(setXMLDefContent);
        }
        //private static void ValidationInfo(object sender, ValidationEventArgs args)
        //{
        //    if (args.Severity == XmlSeverityType.Warning)
        //        Console.WriteLine("\tWarning: Matching schema not found.  No validation occurred." + args.Message);
        //    else
        //        Console.WriteLine("\tValidation error: " + args.Message);

        //    //msg += e.Message + Environment.NewLine;

        //}

        private void CreateElementsInMappingFile(string directoryPathXMLFiles, XMLDefContentFileName xMLDefContent, XmlSchemaSet schema)
        {
            var contentFile = XDocument.Load(directoryPathXMLFiles + "\\" + xMLDefContent.contentFileName);

            if (xMLDefContent.contentFileName == null)
            {
                throw new ArgumentNullException(nameof(xMLDefContent.contentFileName));
            }

            if (ValidateXMLContentFile(contentFile, xMLDefContent.contentFileName, schema))
            {
                ConnectiveDeviceCalculation.CalculateContentFileForConnectiveDevice(contentFile, xMLDefContent);
                EquipmentCalculation.CalculateContentFileForEquipment(contentFile, xMLDefContent);
                NetCalculation.CalculateContentFileForNet(contentFile, xMLDefContent);
                WireCalculation.CalculateContentFileForWire(contentFile, xMLDefContent);
            }
        }