Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NetStone.Test/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -210,7 +210,7 @@ public async Task CheckFreeCompanyRecruiting()

//Focus
Assert.AreEqual("Always", fc.ActiveState);
Assert.AreEqual("Open", fc.Recruitment);
Assert.AreEqual("Closed", fc.Recruitment);

Assert.IsNotNull(fc.Focus);
Assert.AreEqual("Role-playing", fc.Focus.RolePlay.Name);
Expand Down
6 changes: 4 additions & 2 deletions NetStone/Definitions/DefinitionsContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;
using NetStone.Definitions.Model;
using NetStone.Definitions.Model.Character;
Expand Down Expand Up @@ -131,8 +132,9 @@ public abstract class DefinitionsContainer : IDisposable
/// <summary>
/// Loads the definitions from repo
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation</param>
/// <returns>Reload task</returns>
public abstract Task Reload();
public abstract Task Reload(CancellationToken cancellationToken = default);

/// <inheritdoc />
public abstract void Dispose();
Expand Down
56 changes: 30 additions & 26 deletions NetStone/Definitions/XivApiDefinitionsContainer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using NetStone.Definitions.Model;
using NetStone.Definitions.Model.Character;
Expand Down Expand Up @@ -33,47 +34,50 @@ public XivApiDefinitionsContainer()
/// <summary>
/// Fetches current CSS selector definitions from xivapi/lodestone-css-selectors github repository.
/// </summary>
/// <param name="cancellationToken">The cancellation token to cancel operation</param>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="FormatException"></exception>
/// <returns>Task for this operation</returns>
public override async Task Reload()
public override async Task Reload(CancellationToken cancellationToken = default)
{
this.Meta = await GetDefinition<MetaDefinition>("meta.json");
this.Meta = await GetDefinition<MetaDefinition>("meta.json", cancellationToken);

this.Character = await GetDefinition<CharacterDefinition>("profile/character.json");
this.ClassJob = await GetDefinition<CharacterClassJobDefinition>("profile/classjob.json");
this.Gear = await GetDefinition<CharacterGearDefinition>("profile/gearset.json");
this.GearEntry = await GetDefinition<GearEntryDefinition>("profile/gearentry.json");
this.SoulCrystalEntry = await GetDefinition<SoulcrystalEntryDefinition>("profile/soulcrystal.json");
this.Attributes = await GetDefinition<CharacterAttributesDefinition>("profile/attributes.json");
this.Achievement = await GetDefinition<CharacterAchievementDefinition>("profile/achievements.json");
this.Mount = await GetDefinition<CharacterMountDefinition>("profile/mount.json");
this.Minion = await GetDefinition<CharacterMinionDefinition>("profile/minion.json");
this.Character = await GetDefinition<CharacterDefinition>("profile/character.json", cancellationToken);
this.ClassJob = await GetDefinition<CharacterClassJobDefinition>("profile/classjob.json", cancellationToken);
this.Gear = await GetDefinition<CharacterGearDefinition>("profile/gearset.json", cancellationToken);
this.GearEntry = await GetDefinition<GearEntryDefinition>("profile/gearentry.json", cancellationToken);
this.SoulCrystalEntry = await GetDefinition<SoulcrystalEntryDefinition>("profile/soulcrystal.json", cancellationToken);
this.Attributes = await GetDefinition<CharacterAttributesDefinition>("profile/attributes.json", cancellationToken);
this.Achievement = await GetDefinition<CharacterAchievementDefinition>("profile/achievements.json", cancellationToken);
this.Mount = await GetDefinition<CharacterMountDefinition>("profile/mount.json", cancellationToken);
this.Minion = await GetDefinition<CharacterMinionDefinition>("profile/minion.json", cancellationToken);

this.FreeCompany = await GetDefinition<FreeCompanyDefinition>("freecompany/freecompany.json");
this.FreeCompanyFocus = await GetDefinition<FreeCompanyFocusDefinition>("freecompany/focus.json");
this.FreeCompany = await GetDefinition<FreeCompanyDefinition>("freecompany/freecompany.json", cancellationToken);
this.FreeCompanyFocus = await GetDefinition<FreeCompanyFocusDefinition>("freecompany/focus.json", cancellationToken);
this.FreeCompanyReputation =
await GetDefinition<FreeCompanyReputationDefinition>("freecompany/reputation.json");
await GetDefinition<FreeCompanyReputationDefinition>("freecompany/reputation.json", cancellationToken);

this.FreeCompanyMembers = await GetDefinition<PagedDefinition<FreeCompanyMembersEntryDefinition>>("freecompany/members.json");
this.FreeCompanyMembers = await GetDefinition<PagedDefinition<FreeCompanyMembersEntryDefinition>>("freecompany/members.json", cancellationToken);

this.CharacterSearch = await GetDefinition<PagedDefinition<CharacterSearchEntryDefinition>>("search/character.json");
this.FreeCompanySearch = await GetDefinition<PagedDefinition<FreeCompanySearchEntryDefinition>>("search/freecompany.json");
this.CharacterSearch = await GetDefinition<PagedDefinition<CharacterSearchEntryDefinition>>("search/character.json", cancellationToken);
this.FreeCompanySearch = await GetDefinition<PagedDefinition<FreeCompanySearchEntryDefinition>>("search/freecompany.json", cancellationToken);

this.CrossworldLinkshell = await GetDefinition<CrossworldLinkshellDefinition>("cwls/cwls.json");
this.CrossworldLinkshellMember = await GetDefinition<PagedDefinition<CrossworldLinkshellMemberEntryDefinition>>("cwls/members.json");
this.CrossworldLinkshellSearch = await GetDefinition<PagedDefinition<CrossworldLinkshellSearchEntryDefinition>>("search/cwls.json");
this.CrossworldLinkshell = await GetDefinition<CrossworldLinkshellDefinition>("cwls/cwls.json", cancellationToken);
this.CrossworldLinkshellMember = await GetDefinition<PagedDefinition<CrossworldLinkshellMemberEntryDefinition>>("cwls/members.json", cancellationToken);
this.CrossworldLinkshellSearch = await GetDefinition<PagedDefinition<CrossworldLinkshellSearchEntryDefinition>>("search/cwls.json", cancellationToken);

this.Linkshell = await GetDefinition<LinkshellDefinition>("linkshell/ls.json");
this.LinkshellMember = await GetDefinition<PagedDefinition<LinkshellMemberEntryDefinition>>("linkshell/members.json");
this.LinkshellSearch = await GetDefinition<PagedDefinition<LinkshellSearchEntryDefinition>>("search/linkshell.json");
this.Linkshell = await GetDefinition<LinkshellDefinition>("linkshell/ls.json", cancellationToken);
this.LinkshellMember = await GetDefinition<PagedDefinition<LinkshellMemberEntryDefinition>>("linkshell/members.json", cancellationToken);
this.LinkshellSearch = await GetDefinition<PagedDefinition<LinkshellSearchEntryDefinition>>("search/linkshell.json", cancellationToken);
}



private async Task<T> GetDefinition<T>(string path) where T : IDefinition
private async Task<T> GetDefinition<T>(string path, CancellationToken cancellationToken) where T : IDefinition
{
var json = await this.client.GetStringAsync(path);
var response = await this.client.GetAsync(path, cancellationToken);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<T>(json);
return result == null ? throw new FormatException($"Could not parse definitions in {path}.") : result;
}
Expand Down
Loading