Skip to content

Commit

Permalink
v0.9.1 match upload fix
Browse files Browse the repository at this point in the history
  • Loading branch information
epix37 committed Feb 9, 2015
1 parent fcea76e commit 70b9eae
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
11 changes: 7 additions & 4 deletions Hearthstone Deck Tracker/FlyoutControls/DeckStatsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,13 @@ private async void BtnAddNewGame_Click(object sender, RoutedEventArgs e)
if(game != null)
{
_deck.DeckStats.AddGameResult(game);
if(game.GameMode == GameMode.Arena)
HearthStatsManager.UploadArenaMatchAsync(game, _deck, true, true);
else
HearthStatsManager.UploadMatchAsync(game, _deck.GetSelectedDeckVersion(), true, true);
if(Config.Instance.HearthStatsAutoUploadNewGames)
{
if(game.GameMode == GameMode.Arena)
HearthStatsManager.UploadArenaMatchAsync(game, _deck, true, true);
else
HearthStatsManager.UploadMatchAsync(game, _deck.GetSelectedDeckVersion(), true, true);
}
Refresh();
}
Helper.MainWindow.DeckPickerList.UpdateDecks();
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/HearthStats/API/HearthStatsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static async Task<PostResult> PostVersionAsync(Deck deck, string hearthSt
if(json.status.ToString() == "success")
{
deck.HearthStatsDeckVersionId = json.data.id;
//deck.HearthStatsId = hearthStatsId;
deck.HearthStatsIdForUploading = hearthStatsId;
Logger.WriteLine("assigned id to version: " + deck.HearthStatsDeckVersionId, "HearthStatsAPI");
return PostResult.WasSuccess;
}
Expand Down
26 changes: 24 additions & 2 deletions Hearthstone Deck Tracker/HearthStats/API/HearthStatsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public static async Task<PostResult> UploadDeckAsync(Deck deck, bool saveFilesAf
await Task.Delay(VersionDelay);
await UploadVersionAsync(v, first.HearthStatsIdForUploading, false);
}
deck.HearthStatsId = first.HearthStatsId;
first.HearthStatsId = "";
first.HearthStatsIdForUploading = deck.HearthStatsId;
}
if(saveFilesAfter)
DeckList.Save();
Expand Down Expand Up @@ -484,7 +487,7 @@ public static async void SyncAsync(bool forceFullSync = false, bool background =
.SelectMany(
x =>
x.Versions.Where(v => !v.HasHearthStatsDeckVersionId)
.Select(v => new {version = v, hearthStatsId = x.HearthStatsId}))
.Select(v => new {version = v, hearthStatsId = x.HearthStatsIdForUploading}))
.ToList();
if(localNewVersions.Any())
{
Expand Down Expand Up @@ -516,7 +519,26 @@ public static async void SyncAsync(bool forceFullSync = false, bool background =
if(!background)
controller.SetMessage("Uploading " + newMatches.Count + " new matches...");
Logger.WriteLine("Uploading " + newMatches.Count + " new matches...", "HearthStatsManager");
await Task.Run(() => { Parallel.ForEach(newMatches, match => UploadMatch(match.game, match.deck, false)); });
await Task.Run(() => { Parallel.ForEach(newMatches, match =>
{
Deck deck;
if(match.game.HasHearthStatsDeckVersionId)

{
var version =
match.deck.VersionsIncludingSelf.Where(v => v != null).Select(match.deck.GetVersion).Where(v => v != null)
.FirstOrDefault(
d =>
d.HasHearthStatsDeckVersionId && d.HasHearthStatsDeckVersionId == match.game.HasHearthStatsDeckVersionId);
deck = version ?? match.deck.GetVersion(match.game.PlayerDeckVersion);
}
else if(match.game.PlayerDeckVersion != null)
deck = match.deck.GetVersion(match.game.PlayerDeckVersion);
else
deck = match.deck;

UploadMatch(match.game, deck, false);
}); });
DeckStatsList.Save();
}
Config.Instance.LastHearthStatsDecksSync = DateTime.Now.ToUnixTime() - 600; //10 minute overlap
Expand Down
2 changes: 2 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/Deck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ public Deck GetVersion(int major, int minor)

public Deck GetVersion(SerializableVersion version)
{
if(version == null)
return null;
return GetVersion(version.Major, version.Minor);
}

Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/MainWindow/MainWindow_NewDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private async void SaveDeck(bool overwrite, SerializableVersion newVersion)
if(EditingDeck)
{
if(previousVersion != newVersion)
HearthStatsManager.UploadVersionAsync(newDeckClone, _originalDeck.HearthStatsId, background: true);
HearthStatsManager.UploadVersionAsync(newDeckClone, _originalDeck.HearthStatsIdForUploading, background: true);
else
HearthStatsManager.UpdateDeckAsync(newDeckClone, background: true);
}
Expand Down
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/Version.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<Version>
<Major>0</Major>
<Minor>8</Minor>
<Revision>0</Revision>
<Minor>9</Minor>
<Revision>1</Revision>
<Build>0</Build>
</Version>

0 comments on commit 70b9eae

Please sign in to comment.