-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
478 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
NetStone/Definitions/Model/Linkshell/LinkShellDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace NetStone.Definitions.Model.Linkshell; | ||
|
||
/// <summary> | ||
/// Definitions for link shell | ||
/// </summary> | ||
public class LinkShellDefinition : IDefinition | ||
{ | ||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
[JsonProperty("NAME")] | ||
public DefinitionsPack Name { get; set; } | ||
} |
57 changes: 57 additions & 0 deletions
57
NetStone/Definitions/Model/Linkshell/LinkShellMemberDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace NetStone.Definitions.Model.Linkshell; | ||
|
||
/// <summary> | ||
/// Definition for the list of linkshell members | ||
/// </summary> | ||
public class LinkShellMemberDefinition : PagedDefinition<LinkShellMemberEntryDefinition> | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Definition for one entry of the linkshell memebr list | ||
/// </summary> | ||
public class LinkShellMemberEntryDefinition : PagedEntryDefinition | ||
{ | ||
/// <summary> | ||
/// Avatar | ||
/// </summary> | ||
[JsonProperty("AVATAR")] public DefinitionsPack Avatar { get; set; } | ||
|
||
/// <summary> | ||
/// ID | ||
/// </summary> | ||
[JsonProperty("ID")] public DefinitionsPack Id { get; set; } | ||
|
||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
[JsonProperty("NAME")] public DefinitionsPack Name { get; set; } | ||
|
||
/// <summary> | ||
/// Rank | ||
/// </summary> | ||
[JsonProperty("RANK")] public DefinitionsPack Rank { get; set; } | ||
|
||
/// <summary> | ||
/// Rank Icon | ||
/// </summary> | ||
[JsonProperty("RANK_ICON")] public DefinitionsPack RankIcon { get; set; } | ||
|
||
/// <summary> | ||
/// Linkshell rank | ||
/// </summary> | ||
[JsonProperty("LINKSHELL_RANK")] public DefinitionsPack LinkshellRank { get; set; } | ||
|
||
/// <summary> | ||
/// Linkshell rank Icon | ||
/// </summary> | ||
[JsonProperty("LINKSHELL_RANK_ICON")] public DefinitionsPack LinkshellRankIcon { get; set; } | ||
|
||
/// <summary> | ||
/// Server | ||
/// </summary> | ||
[JsonProperty("SERVER")] public DefinitionsPack Server { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
NetStone/Model/Parseables/Linkshell/LodestoneLinkShell.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using HtmlAgilityPack; | ||
using NetStone.Definitions; | ||
using NetStone.Definitions.Model.Linkshell; | ||
using NetStone.Model.Parseables.Linkshell.Members; | ||
|
||
namespace NetStone.Model.Parseables.Linkshell; | ||
|
||
/// <summary> | ||
/// Container class holding information about a linkshell and it's members. | ||
/// </summary> | ||
public class LodestoneLinkShell : LodestoneParseable, IPaginatedResult<LodestoneLinkShell> | ||
{ | ||
private readonly LodestoneClient client; | ||
|
||
private readonly string lsId; | ||
|
||
private readonly LinkShellDefinition lsDefinition; | ||
private readonly LinkShellMemberDefinition pageDefinition; | ||
|
||
/// <summary> | ||
/// Container class for a parseable linkshell page. | ||
/// </summary> | ||
/// <param name="client">The <see cref="LodestoneClient"/> to be used to fetch further information.</param> | ||
/// <param name="rootNode">The root document node of the page.</param> | ||
/// <param name="container">The <see cref="DefinitionsContainer"/> holding definitions to be used to access data.</param> | ||
/// <param name="id">The ID of the cross world linkshell.</param> | ||
public LodestoneLinkShell(LodestoneClient client, HtmlNode rootNode, DefinitionsContainer container, string id) : base(rootNode) | ||
{ | ||
this.client = client; | ||
this.lsId = id; | ||
this.lsDefinition = container.LinkShell; | ||
this.pageDefinition = container.LinkShellMember; | ||
} | ||
|
||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
public string Name => Parse(this.lsDefinition.Name); | ||
|
||
|
||
private LinkShellMemberEntry[]? parsedResults; | ||
|
||
/// <summary> | ||
/// List of members | ||
/// </summary> | ||
public IEnumerable<LinkShellMemberEntry> Members | ||
{ | ||
get | ||
{ | ||
if (this.parsedResults == null) | ||
ParseSearchResults(); | ||
|
||
return this.parsedResults!; | ||
} | ||
} | ||
|
||
private void ParseSearchResults() | ||
{ | ||
var nodes = QueryContainer(this.pageDefinition); | ||
|
||
this.parsedResults = new LinkShellMemberEntry[nodes.Length]; | ||
for (var i = 0; i < this.parsedResults.Length; i++) | ||
{ | ||
this.parsedResults[i] = new LinkShellMemberEntry(nodes[i], this.pageDefinition.Entry); | ||
} | ||
} | ||
|
||
private int? currentPageVal; | ||
|
||
///<inheritdoc /> | ||
public int CurrentPage | ||
{ | ||
get | ||
{ | ||
if (!this.currentPageVal.HasValue) | ||
ParsePagesCount(); | ||
|
||
return this.currentPageVal!.Value; | ||
} | ||
} | ||
|
||
private int? numPagesVal; | ||
|
||
/// <inheritdoc/> | ||
public int NumPages | ||
{ | ||
get | ||
{ | ||
if (!this.numPagesVal.HasValue) | ||
ParsePagesCount(); | ||
|
||
return this.numPagesVal!.Value; | ||
} | ||
} | ||
private void ParsePagesCount() | ||
{ | ||
var results = ParseRegex(this.pageDefinition.PageInfo); | ||
|
||
this.currentPageVal = int.Parse(results["CurrentPage"].Value); | ||
this.numPagesVal = int.Parse(results["NumPages"].Value); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<LodestoneLinkShell?> GetNextPage() | ||
{ | ||
if (this.CurrentPage == this.NumPages) | ||
return null; | ||
|
||
return await this.client.GetLinkshell(this.lsId, this.CurrentPage + 1); | ||
} | ||
} |
Oops, something went wrong.