Exemple #1
0
        private void LoadFile(FileInfo fileInfo, bool printSuccess)
        {
            if (!fileInfo.Exists)
            {
                Log.Error($"Triple slash xml file does not exist: {fileInfo.FullName}");
                return;
            }

            xDoc = XDocument.Load(fileInfo.FullName);

            if (xDoc.Root == null)
            {
                Log.Error($"Triple slash xml file does not contain a root element: {fileInfo.FullName}");
                return;
            }

            if (xDoc.Root.Name != "doc")
            {
                Log.Error($"Triple slash xml file does not contain a doc element: {fileInfo.FullName}");
                return;
            }

            if (!xDoc.Root.HasElements)
            {
                Log.Error($"Triple slash xml file doc element not have any children: {fileInfo.FullName}");
                return;
            }

            if (xDoc.Root.Elements("assembly").Count() != 1)
            {
                Log.Error($"Triple slash xml file does not contain exactly 1 'assembly' element: {fileInfo.FullName}");
                return;
            }

            XElement xAssembly = xDoc.Root.Element("assembly");

            if (xAssembly.Elements("name").Count() != 1)
            {
                Log.Error($"Triple slash xml file assembly element does not contain exactly 1 'name' element: {fileInfo.FullName}");
                return;
            }

            string assembly = xAssembly.Element("name").Value;

            if (string.IsNullOrEmpty(assembly))
            {
                Log.Error($"Triple slash xml file assembly string is null or empty: {fileInfo.FullName}");
            }

            if (xDoc.Root.Elements("members").Count() != 1)
            {
                Log.Error($"Triple slash xml file does not contain exactly 1 'members' element: {fileInfo.FullName}");
                return;
            }

            int totalAdded = 0;

            if (XmlHelper.TryGetChildElement(xDoc.Root, "members", out XElement xeMembers))
            {
                foreach (XElement xeMember in xeMembers.Elements("member"))
                {
                    TripleSlashMember member = new TripleSlashMember(xeMember, assembly);

                    bool add = false;
                    foreach (string included in Config.IncludedAssemblies)
                    {
                        if (member.Assembly.StartsWith(included) ||
                            member.Name.Substring(2).StartsWith(included) ||
                            member.Namespace.StartsWith(included) ||
                            Configuration.ReplaceNamespace(member.Assembly).StartsWith(included))
                        {
                            add = true;
                            break;
                        }
                    }

                    foreach (string excluded in Config.ExcludedAssemblies)
                    {
                        if (member.Assembly.StartsWith(excluded) || member.Name.Substring(2).StartsWith(excluded))
                        {
                            add = false;
                            break;
                        }
                    }

                    if (add)
                    {
                        totalAdded++;
                        Members.Add(member);
                    }
                }
            }

            if (printSuccess && totalAdded > 0)
            {
                Log.Success($"{totalAdded} triple slash member(s) added from xml file '{fileInfo.FullName}'");
            }
        }
        public void LoadFile(FileInfo fileInfo, List <string> includedAssemblies, List <string> excludedAssemblies, bool printSuccess)
        {
            if (!fileInfo.Exists)
            {
                Log.Error(string.Format("Triple slash xml file does not exist: {0}", fileInfo.FullName));
                return;
            }

            xDoc = XDocument.Load(fileInfo.FullName);

            if (xDoc.Root == null)
            {
                Log.Error("Triple slash xml file does not contain a root element: {0}", fileInfo.FullName);
                return;
            }

            if (xDoc.Root.Name != "doc")
            {
                Log.Error("Triple slash xml file does not contain a doc element: {0}", fileInfo.FullName);
                return;
            }

            if (!xDoc.Root.HasElements)
            {
                Log.Error("Triple slash xml file doc element not have any children: {0}", fileInfo.FullName);
                return;
            }

            if (xDoc.Root.Elements("assembly").Count() != 1)
            {
                Log.Error("Tripls slash xml file does not contain exactly 1 'assembly' element: {0}", fileInfo.FullName);
                return;
            }

            if (xDoc.Root.Elements("members").Count() != 1)
            {
                Log.Error("Triple slash xml file does not contain exactly 1 'members' element: {0}", fileInfo.FullName);
                return;
            }

            XElement xeMembers = XmlHelper.GetChildElement(xDoc.Root, "members");

            foreach (XElement xeMember in xeMembers.Elements("member"))
            {
                TripleSlashMember member = new TripleSlashMember(xeMember);

                bool add = false;
                foreach (string included in includedAssemblies)
                {
                    if (member.Assembly.StartsWith(included))
                    {
                        add = true;
                        break;
                    }
                }

                foreach (string excluded in excludedAssemblies)
                {
                    if (member.Assembly.StartsWith(excluded))
                    {
                        add = false;
                        break;
                    }
                }

                if (add)
                {
                    Members.Add(member);
                }
            }

            if (printSuccess)
            {
                Log.Success("Triple slash xml file included: {0}", fileInfo.FullName);
            }
        }