-
Notifications
You must be signed in to change notification settings - Fork 13
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
10 changed files
with
491 additions
and
24 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
21 changes: 21 additions & 0 deletions
21
NetStone/Definitions/Model/CWLS/CrossWorldLinkShellDefinition.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,21 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace NetStone.Definitions.Model.CWLS; | ||
|
||
/// <summary> | ||
/// Definitions for cross world link shell | ||
/// </summary> | ||
public class CrossWorldLinkShellDefinition : IDefinition | ||
{ | ||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
[JsonProperty("NAME")] | ||
public DefinitionsPack Name { get; set; } | ||
|
||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
[JsonProperty("DC")] | ||
public DefinitionsPack DataCenter { get; set; } | ||
} |
56 changes: 56 additions & 0 deletions
56
NetStone/Definitions/Model/CWLS/CrossWorldLinkShellMemberDefinition.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,56 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace NetStone.Definitions.Model.CWLS; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class CrossWorldLinkShellMemberDefinition : PagedDefinition<CrossWorldLinkShellMemberEntryDefinition> | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class CrossWorldLinkShellMemberEntryDefinition : 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
119 changes: 119 additions & 0 deletions
119
NetStone/Model/Parseables/CWLS/LodestoneCrossWorldLinkShell.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,119 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using HtmlAgilityPack; | ||
using NetStone.Definitions; | ||
using NetStone.Definitions.Model.CWLS; | ||
using NetStone.Model.Parseables.CWLS.Members; | ||
|
||
namespace NetStone.Model.Parseables.CWLS; | ||
|
||
/// <summary> | ||
/// Container class holding information about a cross world linkshell and it's members. | ||
/// </summary> | ||
public class LodestoneCrossWorldLinkShell : LodestoneParseable, IPaginatedResult<LodestoneCrossWorldLinkShell> | ||
{ | ||
private readonly LodestoneClient client; | ||
|
||
private readonly string cwlsId; | ||
|
||
private readonly CrossWorldLinkShellDefinition cwlsDefinition; | ||
private readonly CrossWorldLinkShellMemberDefinition pageDefinition; | ||
|
||
/// <summary> | ||
/// Container class for a parseable corss world 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 LodestoneCrossWorldLinkShell(LodestoneClient client, HtmlNode rootNode, DefinitionsContainer container, string id) : base(rootNode) | ||
{ | ||
this.client = client; | ||
this.cwlsId = id; | ||
this.cwlsDefinition = container.CrossWorldLinkShell; | ||
this.pageDefinition = container.CrossWorldLinkShellMember; | ||
} | ||
|
||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
public string Name => Parse(this.cwlsDefinition.Name); | ||
|
||
/// <summary> | ||
/// Datacenter | ||
/// </summary> | ||
public string DataCenter => Parse(this.cwlsDefinition.DataCenter); | ||
|
||
|
||
private CrossWorldLinkShellMemberEntry[]? parsedResults; | ||
|
||
/// <summary> | ||
/// Unlocked achievements for character | ||
/// </summary> | ||
public IEnumerable<CrossWorldLinkShellMemberEntry> Members | ||
{ | ||
get | ||
{ | ||
if (this.parsedResults == null) | ||
ParseSearchResults(); | ||
|
||
return this.parsedResults!; | ||
} | ||
} | ||
|
||
private void ParseSearchResults() | ||
{ | ||
var nodes = QueryContainer(this.pageDefinition); | ||
|
||
this.parsedResults = new CrossWorldLinkShellMemberEntry[nodes.Length]; | ||
for (var i = 0; i < this.parsedResults.Length; i++) | ||
{ | ||
this.parsedResults[i] = new CrossWorldLinkShellMemberEntry(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<LodestoneCrossWorldLinkShell?> GetNextPage() | ||
{ | ||
if (this.CurrentPage == this.NumPages) | ||
return null; | ||
|
||
return await this.client.GetCrossworldLinkshell(this.cwlsId, this.CurrentPage + 1); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
NetStone/Model/Parseables/CWLS/Members/CrossWorldLinkShellMemberEntry.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,61 @@ | ||
using HtmlAgilityPack; | ||
using NetStone.Definitions.Model.CWLS; | ||
|
||
namespace NetStone.Model.Parseables.CWLS.Members; | ||
|
||
/// <summary> | ||
/// Container class holding information about a cross-world linkshelll member. | ||
/// </summary> | ||
public class CrossWorldLinkShellMemberEntry : LodestoneParseable | ||
{ | ||
private readonly CrossWorldLinkShellMemberEntryDefinition definition; | ||
/// <summary> | ||
/// Create instance of member entry for a given node | ||
/// </summary> | ||
/// <param name="rootNode">Root html node of this entry</param> | ||
/// <param name="definition">Css and regex definition</param> | ||
public CrossWorldLinkShellMemberEntry(HtmlNode rootNode, CrossWorldLinkShellMemberEntryDefinition definition) : base(rootNode) | ||
{ | ||
this.definition = definition; | ||
} | ||
|
||
/// <summary> | ||
/// Avatar | ||
/// </summary> | ||
public string Avatar => Parse(this.definition.Avatar); | ||
|
||
/// <summary> | ||
/// ID | ||
/// </summary> | ||
public string? Id => ParseHrefId(this.definition.Id); | ||
|
||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
public string Name => Parse(this.definition.Name); | ||
|
||
/// <summary> | ||
/// Rank | ||
/// </summary> | ||
public string Rank => Parse(this.definition.Rank); | ||
|
||
/// <summary> | ||
/// Rank Icon | ||
/// </summary> | ||
public string RankIcon => Parse(this.definition.RankIcon); | ||
|
||
/// <summary> | ||
/// Linkshell rank | ||
/// </summary> | ||
public string LinkshellRank => Parse(this.definition.LinkshellRank); | ||
|
||
/// <summary> | ||
/// Linkshell rank Icon | ||
/// </summary> | ||
public string LinkshellRankIcon => Parse(this.definition.LinkshellRankIcon); | ||
|
||
/// <summary> | ||
/// Server | ||
/// </summary> | ||
public string Server => Parse(this.definition.Server); | ||
} |
Oops, something went wrong.