Skip to content

Commit 2624d96

Browse files
committed
Fixed issue with bad json casting, switched to object
1 parent 1767f81 commit 2624d96

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// <auto-generated />
2+
//
3+
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
4+
//
5+
// using Heroesprofile.Uploader.Common;
6+
//
7+
// var uploadResult = UploadResult.FromJson(jsonString);
8+
9+
namespace Heroesprofile.Uploader.Common
10+
{
11+
using System;
12+
using System.Collections.Generic;
13+
14+
using System.Globalization;
15+
using Newtonsoft.Json;
16+
using Newtonsoft.Json.Converters;
17+
18+
public partial class UploadResult
19+
{
20+
[JsonProperty("fingerprint")]
21+
public Guid Fingerprint { get; set; }
22+
23+
[JsonProperty("replayID")]
24+
public int ReplayId { get; set; }
25+
26+
[JsonProperty("status")]
27+
public string Status { get; set; }
28+
}
29+
30+
public partial class UploadResult
31+
{
32+
public static UploadResult FromJson(string json) => JsonConvert.DeserializeObject<UploadResult>(json, Heroesprofile.Uploader.Common.Converter.Settings);
33+
}
34+
35+
public static class Serialize
36+
{
37+
public static string ToJson(this UploadResult self) => JsonConvert.SerializeObject(self, Heroesprofile.Uploader.Common.Converter.Settings);
38+
}
39+
40+
internal static class Converter
41+
{
42+
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings {
43+
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
44+
DateParseHandling = DateParseHandling.None,
45+
Converters =
46+
{
47+
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
48+
},
49+
};
50+
}
51+
}

Heroesprofile.Uploader.Common/Uploader.cs

+5-10
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,10 @@ public async Task<UploadStatus> Upload(Replay replay_results, string fingerprint
6565
response = Encoding.UTF8.GetString(bytes);
6666
}
6767

68-
dynamic json = JObject.Parse(response);
68+
UploadResult result = UploadResult.FromJson(response);
6969

7070
try {
71-
int replayID = 0;
72-
73-
if (json.replayID != null) {
74-
replayID = json.replayID;
75-
}
76-
71+
int replayID = result.ReplayId;
7772
if (File.GetLastWriteTime(file) >= DateTime.Now.Subtract(TimeSpan.FromMinutes(60)) && PostMatchPage && replayID != 0) {
7873
await postMatchAnalysis(replayID);
7974
}
@@ -83,12 +78,12 @@ public async Task<UploadStatus> Upload(Replay replay_results, string fingerprint
8378
}
8479

8580

86-
if ((bool)json.success) {
87-
if (Enum.TryParse<UploadStatus>((string)json.status, out UploadStatus status)) {
81+
if (!string.IsNullOrEmpty(result.Status)) {
82+
if (Enum.TryParse<UploadStatus>((string)result.Status, out UploadStatus status)) {
8883
_log.Debug($"Uploaded file '{file}': {status}");
8984
return status;
9085
} else {
91-
_log.Error($"Unknown upload status '{file}': {json.status}");
86+
_log.Error($"Unknown upload status '{file}': {result.Status}");
9287
return UploadStatus.UploadError;
9388
}
9489
} else {

Heroesprofile.Uploader.Windows/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@
5252
// You can specify all the values or you can default the Build and Revision Numbers
5353
// by using the '*' as shown below:
5454
// [assembly: AssemblyVersion("1.0.*")]
55-
[assembly: AssemblyVersion("2.3.0")]
56-
[assembly: AssemblyFileVersion("2.3.0")]
55+
[assembly: AssemblyVersion("2.3.1")]
56+
[assembly: AssemblyFileVersion("2.3.1")]
5757
[assembly: AssemblyInformationalVersion("1.0.0")]

Heroesprofile.Uploader.Windows/SquirrelRelease.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
5: CD to Installer directory
1010

11-
6: Squirrel --releasify=Heroesprofile.Uploader.2.3.0.nupkg --no-msi --setupIcon=uploader_icon_light.ico
11+
6: Squirrel --releasify=Heroesprofile.Uploader.2.3.1.nupkg --no-msi --setupIcon=uploader_icon_light.ico

0 commit comments

Comments
 (0)