From 2ba7442ff6df860afc06da121c07e76665405d8f Mon Sep 17 00:00:00 2001 From: Abraham Hamidi Date: Sun, 17 Oct 2021 17:08:43 -0500 Subject: [PATCH] version 2.0.1 hotfix workaround to challonge api bug --- .../ChallongeApiWrapper.csproj | 70 +---- ChallongeApiWrapper/ChallongePortal.cs | 43 ++- ChallongeApiWrapper/Participant.cs | 7 + ChallongeApiWrapper/Tournament.cs | 15 ++ ChallongeApiWrapper/packages.config | 4 +- ChallongeMatchDisplay.sln | 32 ++- .../ChallongeVisualization.csproj | 246 ++---------------- 7 files changed, 110 insertions(+), 307 deletions(-) diff --git a/ChallongeApiWrapper/ChallongeApiWrapper.csproj b/ChallongeApiWrapper/ChallongeApiWrapper.csproj index 35b088b..d94b177 100644 --- a/ChallongeApiWrapper/ChallongeApiWrapper.csproj +++ b/ChallongeApiWrapper/ChallongeApiWrapper.csproj @@ -1,70 +1,20 @@ - - + - Debug - AnyCPU - 8.0.30703 - 2.0 - {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4} Library - Properties Fizzi.Libraries.ChallongeApiWrapper - ChallongeApiWrapper - v4.7.2 - 512 - + latest + 2.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false + + net5.0 + false - - ..\packages\RestSharp.104.4.0\lib\net4\RestSharp.dll - - - - - - - - - - - - - - - - - - + + - + + - - - \ No newline at end of file diff --git a/ChallongeApiWrapper/ChallongePortal.cs b/ChallongeApiWrapper/ChallongePortal.cs index 04b1675..198614f 100644 --- a/ChallongeApiWrapper/ChallongePortal.cs +++ b/ChallongeApiWrapper/ChallongePortal.cs @@ -4,6 +4,11 @@ using System.Text; using RestSharp; using System.Xml.Linq; +using RestSharp.Serialization.Json; +using RestSharp.Serializers.NewtonsoftJson; +using System.Text.Json; +using System.Runtime.Serialization.Json; +using System.Runtime.Serialization; namespace Fizzi.Libraries.ChallongeApiWrapper { @@ -31,16 +36,29 @@ private void throwOnError(IRestResponse response) } } + [DataContract(Name = "tournament")] + private class TournamentWrapper + { + [DataMember(Name = "tournament")] + public Tournament Tournament; + } + public IEnumerable GetTournaments() { - var request = new RestRequest("tournaments.xml", Method.GET); + var request = new RestRequest("tournaments.json", Method.GET); request.AddParameter("api_key", ApiKey); if (!string.IsNullOrWhiteSpace(Subdomain)) request.AddParameter("subdomain", Subdomain); - var response = client.Execute>(request); + // work around challonge api bug + var response = client.Execute(request); throwOnError(response); - return response.Data; + var ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(response.Content)); + var ser = new DataContractJsonSerializer(typeof(List)); + var tournaments = ser.ReadObject(ms) as List; + ms.Close(); + + return tournaments.Select(x => x.Tournament).Reverse(); } public Tournament ShowTournament(int tournamentId) @@ -65,15 +83,28 @@ public IEnumerable GetMatches(int tournamentId) return response.Data; } + [DataContract(Name ="participant")] + private class ParticipantWrapper + { + [DataMember(Name = "participant")] + public Participant Participant; + } + public IEnumerable GetParticipants(int tournamentId) { - var request = new RestRequest(string.Format("tournaments/{0}/participants.xml", tournamentId), Method.GET); + var request = new RestRequest(string.Format("tournaments/{0}/participants.json", tournamentId), Method.GET); request.AddParameter("api_key", ApiKey); - var response = client.Execute>(request); + // work around challonge api bug + var response = client.Execute(request); throwOnError(response); - return response.Data; + var ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(response.Content)); + var ser = new DataContractJsonSerializer(typeof(List)); + var participants = ser.ReadObject(ms) as List; + ms.Close(); + + return participants.Select(x => x.Participant); } public void SetParticipantMisc(int tournamentId, int participantId, string misc) diff --git a/ChallongeApiWrapper/Participant.cs b/ChallongeApiWrapper/Participant.cs index 8ae4532..1d4145c 100644 --- a/ChallongeApiWrapper/Participant.cs +++ b/ChallongeApiWrapper/Participant.cs @@ -1,18 +1,25 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; namespace Fizzi.Libraries.ChallongeApiWrapper { + [DataContract(Name="participant")] public class Participant { + [DataMember(Name="id")] public int Id { get; set; } + [DataMember(Name="name")] public string Name { get; set; } + [DataMember(Name="challongeUsername")] public string ChallongeUsername { get; set; } + [DataMember(Name="seed")] public int Seed { get; set; } + [DataMember(Name="misc")] public string Misc { get; set; } public string NameOrUsername { get { return string.IsNullOrEmpty(Name) ? ChallongeUsername : Name; } } diff --git a/ChallongeApiWrapper/Tournament.cs b/ChallongeApiWrapper/Tournament.cs index b57aec7..6892973 100644 --- a/ChallongeApiWrapper/Tournament.cs +++ b/ChallongeApiWrapper/Tournament.cs @@ -1,28 +1,43 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; +using Newtonsoft.Json; namespace Fizzi.Libraries.ChallongeApiWrapper { + [DataContract(Name = "tournament")] public class Tournament { + [DataMember(Name = "createdAt")] public DateTime? CreatedAt { get; set; } + [DataMember(Name = "startedAt")] public DateTime? StartedAt { get; set; } + [DataMember(Name = "completedAt")] public DateTime? CompletedAt { get; set; } + [DataMember(Name = "name")] public string Name { get; set; } public string Description { get; set; } + [DataMember(Name = "id")] public int Id { get; set; } + [DataMember(Name = "participantsCount")] public int ParticipantsCount { get; set; } + [DataMember(Name = "progressMeter")] public int ProgressMeter { get; set; } + [DataMember(Name = "state")] public string State { get; set; } + [DataMember(Name = "tournamentType")] public string TournamentType { get; set; } + [DataMember(Name = "url")] public string Url { get; set; } + [DataMember(Name = "fullChallongeUrl")] public string FullChallongeUrl { get; set; } + [DataMember(Name = "liveImageUrl")] public string LiveImageUrl { get; set; } } } diff --git a/ChallongeApiWrapper/packages.config b/ChallongeApiWrapper/packages.config index a6ed660..3779062 100644 --- a/ChallongeApiWrapper/packages.config +++ b/ChallongeApiWrapper/packages.config @@ -1,4 +1,6 @@  - + + + \ No newline at end of file diff --git a/ChallongeMatchDisplay.sln b/ChallongeMatchDisplay.sln index 2456c61..904db8f 100644 --- a/ChallongeMatchDisplay.sln +++ b/ChallongeMatchDisplay.sln @@ -1,13 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1525 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChallongeVisualization", "ChallongeMatchDisplay\ChallongeVisualization.csproj", "{CA5673AD-D9D2-4292-9921-6AD3FC041607}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChallongeVisualization", "ChallongeMatchDisplay\ChallongeVisualization.csproj", "{CA5673AD-D9D2-4292-9921-6AD3FC041607}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChallongeApiWrapper", "ChallongeApiWrapper\ChallongeApiWrapper.csproj", "{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChallongeApiWrapper", "ChallongeApiWrapper\ChallongeApiWrapper.csproj", "{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SandBox", "SandBox\SandBox.csproj", "{70FEB780-FDBF-460B-849D-1CA6213E7202}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SandBox", "SandBox\SandBox.csproj", "{70FEB780-FDBF-460B-849D-1CA6213E7202}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -22,17 +22,18 @@ Global EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Any CPU.ActiveCfg = Debug|x64 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.Build.0 = Debug|x64 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.ActiveCfg = Debug|x64 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.Build.0 = Debug|x64 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.ActiveCfg = Debug|x86 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.Build.0 = Debug|x86 + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Any CPU.Build.0 = Debug|x64 + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.ActiveCfg = Debug|Any CPU + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.Build.0 = Debug|Any CPU + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.ActiveCfg = Debug|Any CPU + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.Build.0 = Debug|Any CPU {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|Any CPU.ActiveCfg = Release|x64 {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|Mixed Platforms.ActiveCfg = Release|x64 {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|Mixed Platforms.Build.0 = Release|x64 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.ActiveCfg = Release|x64 - {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.Build.0 = Release|x64 + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.ActiveCfg = Release|Any CPU + {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.Build.0 = Release|Any CPU {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x86.ActiveCfg = Release|x86 {CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x86.Build.0 = Release|x86 {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -40,6 +41,7 @@ Global {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x64.ActiveCfg = Debug|Any CPU + {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x64.Build.0 = Debug|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x86.ActiveCfg = Debug|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x86.Build.0 = Debug|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -47,6 +49,7 @@ Global {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|Mixed Platforms.Build.0 = Release|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x64.ActiveCfg = Release|Any CPU + {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x64.Build.0 = Release|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x86.ActiveCfg = Release|Any CPU {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x86.Build.0 = Release|Any CPU {70FEB780-FDBF-460B-849D-1CA6213E7202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -69,4 +72,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C8047850-B82B-4321-99B0-1E4E6B6BE2B1} + EndGlobalSection EndGlobal diff --git a/ChallongeMatchDisplay/ChallongeVisualization.csproj b/ChallongeMatchDisplay/ChallongeVisualization.csproj index f21a12c..d92d486 100644 --- a/ChallongeMatchDisplay/ChallongeVisualization.csproj +++ b/ChallongeMatchDisplay/ChallongeVisualization.csproj @@ -1,21 +1,10 @@ - - + - Debug + net5.0-windows x86 - 8.0.30703 - 2.0 - {CA5673AD-D9D2-4292-9921-6AD3FC041607} WinExe - Properties Fizzi.Applications.ChallongeVisualization Challonge Match Display - v4.7.2 - - - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 publish\ true Disk @@ -31,243 +20,45 @@ false false true + false + true + true + true + 2.0 - - x86 - true - full - false - bin\Debug\ DEBUG;TRACE - prompt - 4 - false - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - true bin\x64\Debug\ - DEBUG;TRACE - full - x64 bin\Debug\PhaseviewAutomation.exe.CodeAnalysisLog.xml true GlobalSuppressions.cs - prompt MinimumRecommendedRules.ruleset ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets false ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules false - false bin\x64\Release\ - TRACE - true - pdbonly - x64 bin\Release\PhaseviewAutomation.exe.CodeAnalysisLog.xml true GlobalSuppressions.cs - prompt MinimumRecommendedRules.ruleset ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets false ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules false - false Graphicloads-Food-Drink-Icecream-2.ico + Fizzi.Applications.ChallongeVisualization.App - - ..\packages\RestSharp.105.0.1\lib\net4-client\RestSharp.dll - - - - - - ..\packages\Rx-Core.2.2.5\lib\net40\System.Reactive.Core.dll - - - ..\packages\Rx-Interfaces.2.2.5\lib\net40\System.Reactive.Interfaces.dll - - - ..\packages\Rx-Linq.2.2.5\lib\net40\System.Reactive.Linq.dll - - - ..\packages\Rx-PlatformServices.2.2.5\lib\net40\System.Reactive.PlatformServices.dll - - - ..\packages\Rx-XAML.2.2.5\lib\net40\System.Reactive.Windows.Threading.dll - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - - - - - - - - - Form - - - AboutView.cs - - - ApiWarning.xaml - - - - MatchDisplayView.xaml - - - - NewStation.xaml - - - - OrganizerWindow.xaml - - - - ReportScoreWindow.xaml - - - Settings.xaml - - - - - TournamentSelectionView.xaml - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - - - - - - - - - - - ApiKeyView.xaml - - - MainWindow.xaml - Code - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - AboutView.cs - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - {BEC62B0A-47BA-4018-9EF8-A6B159AA11E4} - ChallongeApiWrapper - - - {70feb780-fdbf-460b-849d-1ca6213e7202} - SandBox - + + @@ -289,12 +80,13 @@ true - - + + + + + + + + + \ No newline at end of file