コード例 #1
0
ファイル: AddinReader.cs プロジェクト: cake-build/website
        public AddinIndex Read(Stream stream)
        {
            var result = new List<Addin>();

            // Parse document.
            var document = new XmlDocument();
            document.Load(stream);

            // ReadElement all addins.
            var addinNodes = document.SelectNodes("/Addins/Addin");
            if (addinNodes != null)
            {
                foreach (XmlNode addinNode in addinNodes)
                {
                    var addin = new Addin();

                    ReadElement(addinNode, "Name", s => addin.Name = s);
                    ReadElement(addinNode, "Repository", s => addin.Repository = new Uri(s));
                    ReadElement(addinNode, "Website", s => addin.Website = new Uri(s));
                    ReadElement(addinNode, "Author", s => addin.Author = s);
                    ReadElement(addinNode, "Description", s => addin.Description = s);
                    ReadElement(addinNode, "Categories", s => addin.Categories.AddRange(ParseCategories(s)));

                    var nugetNode = addinNode.SelectSingleNode("NuGet");
                    if (nugetNode?.Attributes != null)
                    {
                        var id = nugetNode.Attributes["Id"].Value;
                        var version = nugetNode.Attributes["Version"]?.Value;

                        addin.PackageDefinition = new PackageDefinition
                        {
                            PackageName = id,
                            Version = version,
                            Metadata = addin
                        };

                        var filters = nugetNode.SelectNodes("Filter");
                        if (filters != null)
                        {
                            foreach (XmlNode filterNode in filters)
                            {
                                addin.PackageDefinition.Filters.Add(filterNode.InnerText);
                            }
                        }
                    }

                    result.Add(addin);
                }
            }

            return new AddinIndex(result);
        }