-
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
506 additions
and
8 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
28 changes: 28 additions & 0 deletions
28
NetStone/Definitions/Model/CWLS/CrossWorldLinkShellSearchDefinition.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,28 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace NetStone.Definitions.Model.CWLS; | ||
/// <summary> | ||
/// Definition container for one Cross World Link Shell search result entry | ||
/// </summary> | ||
public class CrossWorldLinkShellSearchEntryDefinition : PagedEntryDefinition | ||
{ | ||
/// <summary> | ||
/// ID | ||
/// </summary> | ||
[JsonProperty("ID")] public DefinitionsPack Id { get; set; } | ||
|
||
/// <summary> | ||
/// Name | ||
/// </summary> | ||
[JsonProperty("NAME")] public DefinitionsPack Name { get; set; } | ||
|
||
/// <summary> | ||
/// Rank | ||
/// </summary> | ||
[JsonProperty("DC")] public DefinitionsPack Dc { get; set; } | ||
|
||
/// <summary> | ||
/// Rank Icon | ||
/// </summary> | ||
[JsonProperty("ACTIVE_MEMBERS")] public DefinitionsPack ActiveMembers { 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
42 changes: 42 additions & 0 deletions
42
NetStone/Model/Parseables/Search/CWLS/CrossWorldLinkShellSearchEntry.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,42 @@ | ||
using System.Threading.Tasks; | ||
using HtmlAgilityPack; | ||
using NetStone.Definitions.Model.CWLS; | ||
using NetStone.Model.Parseables.Character; | ||
|
||
namespace NetStone.Model.Parseables.Search.CWLS; | ||
|
||
public class CrossWorldLinkShellSearchEntry : LodestoneParseable | ||
{ | ||
private readonly LodestoneClient client; | ||
private readonly CrossWorldLinkShellSearchEntryDefinition definition; | ||
|
||
/// | ||
public CrossWorldLinkShellSearchEntry(LodestoneClient client, HtmlNode rootNode, CrossWorldLinkShellSearchEntryDefinition definition) : | ||
base(rootNode) | ||
{ | ||
this.client = client; | ||
this.definition = definition; | ||
} | ||
|
||
/// <summary> | ||
/// Character name | ||
/// </summary> | ||
public string Name => Parse(this.definition.Name); | ||
|
||
/// <summary> | ||
/// Lodestone Id | ||
/// </summary> | ||
public string? Id => ParseHrefId(this.definition.Id); | ||
|
||
public int ActiveMembers => int.TryParse(Parse(this.definition.ActiveMembers), out var parsed) ? parsed : -1; | ||
|
||
/// <summary> | ||
/// Fetch character profile | ||
/// </summary> | ||
/// <returns>Task of retrieving character</returns> | ||
public async Task<LodestoneCharacter?> GetCharacter() => | ||
this.Id is null ? null : await this.client.GetCharacter(this.Id); | ||
|
||
///<inheritdoc /> | ||
public override string ToString() => this.Name; | ||
} |
125 changes: 125 additions & 0 deletions
125
NetStone/Model/Parseables/Search/CWLS/CrossWorldLinkShellSearchPage.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,125 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using HtmlAgilityPack; | ||
using NetStone.Definitions; | ||
using NetStone.Definitions.Model; | ||
using NetStone.Definitions.Model.CWLS; | ||
using NetStone.Search.CWLS; | ||
|
||
namespace NetStone.Model.Parseables.Search.CWLS; | ||
|
||
/// <summary> | ||
/// Models cross world link shell search results | ||
/// </summary> | ||
public class CrossWorldLinkShellSearchPage : LodestoneParseable, IPaginatedResult<CrossWorldLinkShellSearchPage> | ||
{ | ||
private readonly LodestoneClient client; | ||
private readonly CrossWorldLinkShellSearchQuery currentQuery; | ||
|
||
private readonly PagedDefinition<CrossWorldLinkShellSearchEntryDefinition> pageDefinition; | ||
|
||
/// <summary> | ||
/// Constructs character search results | ||
/// </summary> | ||
/// <param name="client"></param> | ||
/// <param name="rootNode"></param> | ||
/// <param name="pageDefinition"></param> | ||
/// <param name="currentQuery"></param> | ||
public CrossWorldLinkShellSearchPage(LodestoneClient client, HtmlNode rootNode, PagedDefinition<CrossWorldLinkShellSearchEntryDefinition> pageDefinition, | ||
CrossWorldLinkShellSearchQuery currentQuery) : base(rootNode) | ||
{ | ||
this.client = client; | ||
this.currentQuery = currentQuery; | ||
this.pageDefinition = pageDefinition; | ||
} | ||
|
||
/// <summary> | ||
/// Indicates if any results are present | ||
/// </summary> | ||
public bool HasResults => !HasNode(this.pageDefinition.NoResultsFound); | ||
|
||
private CrossWorldLinkShellSearchEntry[]? parsedResults; | ||
|
||
/// <summary> | ||
/// List all results | ||
/// </summary> | ||
public IEnumerable<CrossWorldLinkShellSearchEntry> Results | ||
{ | ||
get | ||
{ | ||
if (!this.HasResults) | ||
return Array.Empty<CrossWorldLinkShellSearchEntry>(); | ||
|
||
if (this.parsedResults == null) | ||
ParseSearchResults(); | ||
|
||
return this.parsedResults!; | ||
} | ||
} | ||
|
||
private void ParseSearchResults() | ||
{ | ||
var container = QueryContainer(this.pageDefinition); | ||
|
||
this.parsedResults = new CrossWorldLinkShellSearchEntry[container.Length]; | ||
for (var i = 0; i < this.parsedResults.Length; i++) | ||
{ | ||
this.parsedResults[i] = new CrossWorldLinkShellSearchEntry(this.client, container[i], this.pageDefinition.Entry); | ||
} | ||
} | ||
|
||
private int? currentPageVal; | ||
|
||
///<inheritdoc /> | ||
public int CurrentPage | ||
{ | ||
get | ||
{ | ||
if (!this.HasResults) | ||
return 0; | ||
|
||
if (!this.currentPageVal.HasValue) | ||
ParsePagesCount(); | ||
|
||
return this.currentPageVal!.Value; | ||
} | ||
} | ||
|
||
private int? numPagesVal; | ||
|
||
///<inheritdoc /> | ||
public int NumPages | ||
{ | ||
get | ||
{ | ||
if (!this.HasResults) | ||
return 0; | ||
|
||
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<CrossWorldLinkShellSearchPage?> GetNextPage() | ||
{ | ||
if (!this.HasResults) | ||
return null; | ||
|
||
if (this.CurrentPage == this.NumPages) | ||
return null; | ||
|
||
return await this.client.SearchCrossWorldLinkshell(this.currentQuery, this.CurrentPage + 1); | ||
} | ||
} |
Oops, something went wrong.