Skip to content

Commit

Permalink
Fixed issue with bad json casting, switched to object
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemill committed Jan 4, 2023
1 parent 1767f81 commit 2624d96
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
51 changes: 51 additions & 0 deletions Heroesprofile.Uploader.Common/UploadResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using Heroesprofile.Uploader.Common;
//
// var uploadResult = UploadResult.FromJson(jsonString);

namespace Heroesprofile.Uploader.Common
{
using System;
using System.Collections.Generic;

using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

public partial class UploadResult
{
[JsonProperty("fingerprint")]
public Guid Fingerprint { get; set; }

[JsonProperty("replayID")]
public int ReplayId { get; set; }

[JsonProperty("status")]
public string Status { get; set; }
}

public partial class UploadResult
{
public static UploadResult FromJson(string json) => JsonConvert.DeserializeObject<UploadResult>(json, Heroesprofile.Uploader.Common.Converter.Settings);
}

public static class Serialize
{
public static string ToJson(this UploadResult self) => JsonConvert.SerializeObject(self, Heroesprofile.Uploader.Common.Converter.Settings);
}

internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings {
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}
15 changes: 5 additions & 10 deletions Heroesprofile.Uploader.Common/Uploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,10 @@ public async Task<UploadStatus> Upload(Replay replay_results, string fingerprint
response = Encoding.UTF8.GetString(bytes);
}

dynamic json = JObject.Parse(response);
UploadResult result = UploadResult.FromJson(response);

try {
int replayID = 0;

if (json.replayID != null) {
replayID = json.replayID;
}

int replayID = result.ReplayId;
if (File.GetLastWriteTime(file) >= DateTime.Now.Subtract(TimeSpan.FromMinutes(60)) && PostMatchPage && replayID != 0) {
await postMatchAnalysis(replayID);
}
Expand All @@ -83,12 +78,12 @@ public async Task<UploadStatus> Upload(Replay replay_results, string fingerprint
}


if ((bool)json.success) {
if (Enum.TryParse<UploadStatus>((string)json.status, out UploadStatus status)) {
if (!string.IsNullOrEmpty(result.Status)) {
if (Enum.TryParse<UploadStatus>((string)result.Status, out UploadStatus status)) {
_log.Debug($"Uploaded file '{file}': {status}");
return status;
} else {
_log.Error($"Unknown upload status '{file}': {json.status}");
_log.Error($"Unknown upload status '{file}': {result.Status}");
return UploadStatus.UploadError;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions Heroesprofile.Uploader.Windows/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.0")]
[assembly: AssemblyFileVersion("2.3.0")]
[assembly: AssemblyVersion("2.3.1")]
[assembly: AssemblyFileVersion("2.3.1")]
[assembly: AssemblyInformationalVersion("1.0.0")]
2 changes: 1 addition & 1 deletion Heroesprofile.Uploader.Windows/SquirrelRelease.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

5: CD to Installer directory

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

0 comments on commit 2624d96

Please sign in to comment.