Exemple #1
0
        /*********
        ** Private methods
        *********/
        /// <summary>Parse valid mod compatibility entries.</summary>
        /// <param name="nodes">The HTML compatibility entries.</param>
        /// <param name="overridesById">The mod data overrides to apply, if any.</param>
        private IEnumerable <WikiModEntry> ParseModEntries(IEnumerable <HtmlNode> nodes, IDictionary <string, WikiDataOverrideEntry> overridesById)
        {
            foreach (HtmlNode node in nodes)
            {
                // extract fields
                string[] names           = this.GetAttributeAsCsv(node, "data-name");
                string[] authors         = this.GetAttributeAsCsv(node, "data-author");
                string[] ids             = this.GetAttributeAsCsv(node, "data-id");
                string[] warnings        = this.GetAttributeAsCsv(node, "data-warnings");
                int?     nexusID         = this.GetAttributeAsNullableInt(node, "data-nexus-id");
                int?     chucklefishID   = this.GetAttributeAsNullableInt(node, "data-cf-id");
                int?     curseForgeID    = this.GetAttributeAsNullableInt(node, "data-curseforge-id");
                string   curseForgeKey   = this.GetAttribute(node, "data-curseforge-key");
                int?     modDropID       = this.GetAttributeAsNullableInt(node, "data-moddrop-id");
                string   githubRepo      = this.GetAttribute(node, "data-github");
                string   customSourceUrl = this.GetAttribute(node, "data-custom-source");
                string   customUrl       = this.GetAttribute(node, "data-url");
                string   anchor          = this.GetAttribute(node, "id");
                string   contentPackFor  = this.GetAttribute(node, "data-content-pack-for");
                string   devNote         = this.GetAttribute(node, "data-dev-note");
                string   pullRequestUrl  = this.GetAttribute(node, "data-pr");

                // parse stable compatibility
                WikiCompatibilityInfo compatibility = new WikiCompatibilityInfo
                {
                    Status            = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-status") ?? WikiCompatibilityStatus.Ok,
                    BrokeIn           = this.GetAttribute(node, "data-broke-in"),
                    UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-unofficial-version"),
                    UnofficialUrl     = this.GetAttribute(node, "data-unofficial-url"),
                    Summary           = this.GetInnerHtml(node, "mod-summary")?.Trim()
                };

                // parse beta compatibility
                WikiCompatibilityInfo betaCompatibility = null;
                {
                    WikiCompatibilityStatus?betaStatus = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-beta-status");
                    if (betaStatus.HasValue)
                    {
                        betaCompatibility = new WikiCompatibilityInfo
                        {
                            Status            = betaStatus.Value,
                            BrokeIn           = this.GetAttribute(node, "data-beta-broke-in"),
                            UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-beta-unofficial-version"),
                            UnofficialUrl     = this.GetAttribute(node, "data-beta-unofficial-url"),
                            Summary           = this.GetInnerHtml(node, "mod-beta-summary")
                        };
                    }
                }

                // find data overrides
                WikiDataOverrideEntry overrides = ids
                                                  .Select(id => overridesById.TryGetValue(id, out overrides) ? overrides : null)
                                                  .FirstOrDefault(p => p != null);

                // yield model
                yield return(new WikiModEntry
                {
                    ID = ids,
                    Name = names,
                    Author = authors,
                    NexusID = nexusID,
                    ChucklefishID = chucklefishID,
                    CurseForgeID = curseForgeID,
                    CurseForgeKey = curseForgeKey,
                    ModDropID = modDropID,
                    GitHubRepo = githubRepo,
                    CustomSourceUrl = customSourceUrl,
                    CustomUrl = customUrl,
                    ContentPackFor = contentPackFor,
                    Compatibility = compatibility,
                    BetaCompatibility = betaCompatibility,
                    Warnings = warnings,
                    PullRequestUrl = pullRequestUrl,
                    DevNote = devNote,
                    Overrides = overrides,
                    Anchor = anchor
                });
            }
        }
Exemple #2
0
        /*********
        ** Private methods
        *********/
        /// <summary>Parse valid mod compatibility entries.</summary>
        /// <param name="nodes">The HTML compatibility entries.</param>
        private IEnumerable <WikiModEntry> ParseEntries(IEnumerable <HtmlNode> nodes)
        {
            foreach (HtmlNode node in nodes)
            {
                // extract fields
                string[] names           = this.GetAttributeAsCsv(node, "data-name");
                string[] authors         = this.GetAttributeAsCsv(node, "data-author");
                string[] ids             = this.GetAttributeAsCsv(node, "data-id");
                string[] warnings        = this.GetAttributeAsCsv(node, "data-warnings");
                int?     nexusID         = this.GetAttributeAsNullableInt(node, "data-nexus-id");
                int?     chucklefishID   = this.GetAttributeAsNullableInt(node, "data-cf-id");
                int?     modDropID       = this.GetAttributeAsNullableInt(node, "data-moddrop-id");
                string   githubRepo      = this.GetAttribute(node, "data-github");
                string   customSourceUrl = this.GetAttribute(node, "data-custom-source");
                string   customUrl       = this.GetAttribute(node, "data-url");
                string   anchor          = this.GetAttribute(node, "id");

                // parse stable compatibility
                WikiCompatibilityInfo compatibility = new WikiCompatibilityInfo
                {
                    Status            = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-status") ?? WikiCompatibilityStatus.Ok,
                    BrokeIn           = this.GetAttribute(node, "data-broke-in"),
                    UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-unofficial-version"),
                    UnofficialUrl     = this.GetAttribute(node, "data-unofficial-url"),
                    Summary           = this.GetInnerHtml(node, "mod-summary")?.Trim()
                };

                // parse beta compatibility
                WikiCompatibilityInfo betaCompatibility = null;
                {
                    WikiCompatibilityStatus?betaStatus = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-beta-status");
                    if (betaStatus.HasValue)
                    {
                        betaCompatibility = new WikiCompatibilityInfo
                        {
                            Status            = betaStatus.Value,
                            BrokeIn           = this.GetAttribute(node, "data-beta-broke-in"),
                            UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-beta-unofficial-version"),
                            UnofficialUrl     = this.GetAttribute(node, "data-beta-unofficial-url"),
                            Summary           = this.GetInnerHtml(node, "mod-beta-summary")
                        };
                    }
                }

                // parse SMAPI 3.0 readiness status
                WikiSmapi3Status smapi3Status = this.GetAttributeAsEnum <WikiSmapi3Status>(node, "data-smapi-3-status") ?? WikiSmapi3Status.Unknown;
                string           smapi3Url    = this.GetAttribute(node, "data-smapi-3-url");

                // yield model
                yield return(new WikiModEntry
                {
                    ID = ids,
                    Name = names,
                    Author = authors,
                    NexusID = nexusID,
                    ChucklefishID = chucklefishID,
                    ModDropID = modDropID,
                    GitHubRepo = githubRepo,
                    CustomSourceUrl = customSourceUrl,
                    CustomUrl = customUrl,
                    Compatibility = compatibility,
                    BetaCompatibility = betaCompatibility,
                    Smapi3Status = smapi3Status,
                    Smapi3Url = smapi3Url,
                    Warnings = warnings,
                    Anchor = anchor
                });
            }
        }
Exemple #3
0
        /*********
        ** Private methods
        *********/
        /// <summary>Parse valid mod compatibility entries.</summary>
        /// <param name="nodes">The HTML compatibility entries.</param>
        private IEnumerable <WikiModEntry> ParseEntries(IEnumerable <HtmlNode> nodes)
        {
            foreach (HtmlNode node in nodes)
            {
                // extract fields
                string[] names           = this.GetAttributeAsCsv(node, "data-name");
                string[] authors         = this.GetAttributeAsCsv(node, "data-author");
                string[] ids             = this.GetAttributeAsCsv(node, "data-id");
                string[] warnings        = this.GetAttributeAsCsv(node, "data-warnings");
                int?     nexusID         = this.GetAttributeAsNullableInt(node, "data-nexus-id");
                int?     chucklefishID   = this.GetAttributeAsNullableInt(node, "data-cf-id");
                int?     curseForgeID    = this.GetAttributeAsNullableInt(node, "data-curseforge-id");
                string   curseForgeKey   = this.GetAttribute(node, "data-curseforge-key");
                int?     modDropID       = this.GetAttributeAsNullableInt(node, "data-moddrop-id");
                string   githubRepo      = this.GetAttribute(node, "data-github");
                string   customSourceUrl = this.GetAttribute(node, "data-custom-source");
                string   customUrl       = this.GetAttribute(node, "data-url");
                string   anchor          = this.GetAttribute(node, "id");
                string   contentPackFor  = this.GetAttribute(node, "data-content-pack-for");
                string   devNote         = this.GetAttribute(node, "data-dev-note");
                string   pullRequestUrl  = this.GetAttribute(node, "data-pr");
                IDictionary <string, string> mapLocalVersions  = this.GetAttributeAsVersionMapping(node, "data-map-local-versions");
                IDictionary <string, string> mapRemoteVersions = this.GetAttributeAsVersionMapping(node, "data-map-remote-versions");
                string[] changeUpdateKeys = this.GetAttributeAsCsv(node, "data-change-update-keys");

                // parse stable compatibility
                WikiCompatibilityInfo compatibility = new WikiCompatibilityInfo
                {
                    Status            = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-status") ?? WikiCompatibilityStatus.Ok,
                    BrokeIn           = this.GetAttribute(node, "data-broke-in"),
                    UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-unofficial-version"),
                    UnofficialUrl     = this.GetAttribute(node, "data-unofficial-url"),
                    Summary           = this.GetInnerHtml(node, "mod-summary")?.Trim()
                };

                // parse beta compatibility
                WikiCompatibilityInfo betaCompatibility = null;
                {
                    WikiCompatibilityStatus?betaStatus = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-beta-status");
                    if (betaStatus.HasValue)
                    {
                        betaCompatibility = new WikiCompatibilityInfo
                        {
                            Status            = betaStatus.Value,
                            BrokeIn           = this.GetAttribute(node, "data-beta-broke-in"),
                            UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-beta-unofficial-version"),
                            UnofficialUrl     = this.GetAttribute(node, "data-beta-unofficial-url"),
                            Summary           = this.GetInnerHtml(node, "mod-beta-summary")
                        };
                    }
                }

                // yield model
                yield return(new WikiModEntry
                {
                    ID = ids,
                    Name = names,
                    Author = authors,
                    NexusID = nexusID,
                    ChucklefishID = chucklefishID,
                    CurseForgeID = curseForgeID,
                    CurseForgeKey = curseForgeKey,
                    ModDropID = modDropID,
                    GitHubRepo = githubRepo,
                    CustomSourceUrl = customSourceUrl,
                    CustomUrl = customUrl,
                    ContentPackFor = contentPackFor,
                    Compatibility = compatibility,
                    BetaCompatibility = betaCompatibility,
                    Warnings = warnings,
                    PullRequestUrl = pullRequestUrl,
                    DevNote = devNote,
                    ChangeUpdateKeys = changeUpdateKeys,
                    MapLocalVersions = mapLocalVersions,
                    MapRemoteVersions = mapRemoteVersions,
                    Anchor = anchor
                });
            }
        }
Exemple #4
0
        /*********
        ** Private methods
        *********/
        /// <summary>Parse valid mod compatibility entries.</summary>
        /// <param name="nodes">The HTML compatibility entries.</param>
        private IEnumerable <WikiModEntry> ParseEntries(IEnumerable <HtmlNode> nodes)
        {
            foreach (HtmlNode node in nodes)
            {
                // extract fields
                string[] names           = this.GetAttributeAsCsv(node, "data-name");
                string[] authors         = this.GetAttributeAsCsv(node, "data-author");
                string[] ids             = this.GetAttributeAsCsv(node, "data-id");
                string[] warnings        = this.GetAttributeAsCsv(node, "data-warnings");
                int?     nexusID         = this.GetAttributeAsNullableInt(node, "data-nexus-id");
                int?     chucklefishID   = this.GetAttributeAsNullableInt(node, "data-cf-id");
                int?     modDropID       = this.GetAttributeAsNullableInt(node, "data-moddrop-id");
                string   githubRepo      = this.GetAttribute(node, "data-github");
                string   customSourceUrl = this.GetAttribute(node, "data-custom-source");
                string   customUrl       = this.GetAttribute(node, "data-url");
                string   anchor          = this.GetAttribute(node, "id");
                string   contentPackFor  = this.GetAttribute(node, "data-content-pack-for");
                string   devNote         = this.GetAttribute(node, "data-dev-note");

                // parse stable compatibility
                WikiCompatibilityInfo compatibility = new WikiCompatibilityInfo
                {
                    Status            = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-status") ?? WikiCompatibilityStatus.Ok,
                    BrokeIn           = this.GetAttribute(node, "data-broke-in"),
                    UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-unofficial-version"),
                    UnofficialUrl     = this.GetAttribute(node, "data-unofficial-url"),
                    Summary           = this.GetInnerHtml(node, "mod-summary")?.Trim()
                };

                // parse beta compatibility
                WikiCompatibilityInfo betaCompatibility = null;
                {
                    WikiCompatibilityStatus?betaStatus = this.GetAttributeAsEnum <WikiCompatibilityStatus>(node, "data-beta-status");
                    if (betaStatus.HasValue)
                    {
                        betaCompatibility = new WikiCompatibilityInfo
                        {
                            Status            = betaStatus.Value,
                            BrokeIn           = this.GetAttribute(node, "data-beta-broke-in"),
                            UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-beta-unofficial-version"),
                            UnofficialUrl     = this.GetAttribute(node, "data-beta-unofficial-url"),
                            Summary           = this.GetInnerHtml(node, "mod-beta-summary")
                        };
                    }
                }

                // parse links
                List <Tuple <Uri, string> > metadataLinks = new List <Tuple <Uri, string> >();
                foreach (HtmlNode linkElement in node.Descendants("td").Last().Descendants("a").Skip(1)) // skip anchor link
                {
                    string text = linkElement.InnerText.Trim();
                    Uri    url  = new Uri(linkElement.GetAttributeValue("href", ""));
                    metadataLinks.Add(Tuple.Create(url, text));
                }

                // yield model
                yield return(new WikiModEntry
                {
                    ID = ids,
                    Name = names,
                    Author = authors,
                    NexusID = nexusID,
                    ChucklefishID = chucklefishID,
                    ModDropID = modDropID,
                    GitHubRepo = githubRepo,
                    CustomSourceUrl = customSourceUrl,
                    CustomUrl = customUrl,
                    ContentPackFor = contentPackFor,
                    Compatibility = compatibility,
                    BetaCompatibility = betaCompatibility,
                    Warnings = warnings,
                    MetadataLinks = metadataLinks.ToArray(),
                    DevNote = devNote,
                    Anchor = anchor
                });
            }
        }