diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs index 38ae090..c4840c4 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs @@ -80,6 +80,21 @@ namespace LaDOSE.Api.Controllers return false; } + [AllowAnonymous] + [HttpGet("GetPlayers/{slug}")] + public async Task> GetPlayer(string slug) + { + if (!string.IsNullOrEmpty(slug)) + { + var player = await _service.GetPlayer(slug); + return player; + } + + throw new Exception("Erreur"); + + } + + } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj index 27b38c2..40cea3f 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj +++ b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj @@ -127,11 +127,15 @@ + + + EventPlayerView.xaml + WebNavigationView.xaml @@ -159,6 +163,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/EventPlayerViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/EventPlayerViewModel.cs new file mode 100644 index 0000000..a05f103 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/EventPlayerViewModel.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using Caliburn.Micro; +using LaDOSE.DesktopApp.Utils; +using LaDOSE.DTO; +using LaDOSE.REST; +using Microsoft.Win32; +using RestSharp.Serialization.Json; + +namespace LaDOSE.DesktopApp.ViewModels +{ + public class EventPlayerViewModel : Screen + { + public override string DisplayName => "EventPlayers"; + + + public class KiouzeFile + { + public String player { get; set; } + public String character { get; set; } + } + + public ObservableCollection Data { get; set; } + + private List _playersList; + private List _charList; + private string _chars { get; set; } + public string Slug { get; set; } + + private RestService RestService { get; set; } + public EventPlayerViewModel(RestService restService) + { + this.RestService = restService; + Data = new ObservableCollection(); + this.Slug = "tag-team-tuesdays-umvc3-team-tournament-2"; + this.Chars = "akuma;blanka;boxer;cammy;chunli;claw;deejay;dhalsim;dictator;feilong;guile;honda;ken;ryu;sagat;thawk;zangief"; + + } + + protected override void OnInitialize() + { + + base.OnInitialize(); + } + + public void GetPlayers() + { + WpfUtil.Await(() => + { + + var resultsDto = this.RestService.GetPlayers(this.Slug); + Players = resultsDto; + Players.ForEach(p=> Data.AddUI(new KiouzeFile(){player = p})); + }); + } + + public void Export() + { + + SaveFileDialog saveFileDialog = new SaveFileDialog(); + if (saveFileDialog.ShowDialog() == true) + { + JsonSerializer p = new JsonDeserializer(); + var json = p.Serialize(Data.ToList()); + File.WriteAllText(saveFileDialog.FileName, json); + } + } + public List Players + { + get => _playersList; + set + { + _playersList = value; + NotifyOfPropertyChange(() => this.Players); + } + } + public List CharList + { + get => _charList; + set + { + _charList = value; + NotifyOfPropertyChange(() => this.CharList); + } + } + + + public String Chars + { + get => _chars; + set + { + _chars = value; + _charList = _chars.Split(';').ToList(); + NotifyOfPropertyChange(()=>this.Players); + NotifyOfPropertyChange(()=>this.CharList); + } + } + + + + + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs index efd11c9..a57dd2b 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs @@ -68,5 +68,9 @@ namespace LaDOSE.DesktopApp.ViewModels { ActivateItem(new TournamentResultViewModel(IoC.Get())); } + public void EventPlayers() + { + ActivateItem(new EventPlayerViewModel(IoC.Get())); + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/EventPlayerView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/EventPlayerView.xaml new file mode 100644 index 0000000..c1037dc --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/EventPlayerView.xaml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/EventPlayerView.xaml.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Views/EventPlayerView.xaml.cs new file mode 100644 index 0000000..ad51a0c --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/EventPlayerView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace LaDOSE.DesktopApp.Views +{ + /// + /// Interaction logic for ShellView.xaml + /// + public partial class EventPlayerView : UserControl + { + public EventPlayerView() + { + InitializeComponent(); + } + } +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml index 40609ba..27141d6 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml @@ -47,6 +47,14 @@ + + + + + + + + diff --git a/LaDOSE.Src/LaDOSE.REST/RestService.cs b/LaDOSE.Src/LaDOSE.REST/RestService.cs index f1ca01f..1030d9d 100644 --- a/LaDOSE.Src/LaDOSE.REST/RestService.cs +++ b/LaDOSE.Src/LaDOSE.REST/RestService.cs @@ -305,5 +305,13 @@ namespace LaDOSE.REST var restResponse = Client.Get>(restRequest); return restResponse.Data; } + + public List GetPlayers(string slug) + { + CheckToken(); + var restRequest = new RestRequest($"/api/Tournament/GetPLayers/{slug}", Method.GET); + var restResponse = Client.Get>(restRequest); + return restResponse.Data; + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs index 016a269..986a0c4 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs @@ -18,5 +18,6 @@ namespace LaDOSE.Business.Interface Task> GetChallongeEvents(List ids); Task GetEventsResult(List ids); + Task> GetPlayer(string slug); } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/ISmashProvider.cs b/LaDOSE.Src/LaDOSE.Service/Interface/ISmashProvider.cs index 497dd7c..2863f2b 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/ISmashProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/ISmashProvider.cs @@ -16,7 +16,8 @@ namespace LaDOSE.Business.Interface Task ParseEvent(string slug); Task GetTournament(string sludge); + Task GetNames(string slug); + - } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs index cc4c194..2465792 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs @@ -47,8 +47,6 @@ namespace LaDOSE.Business.Provider.ChallongProvider { var result = await new CreateTournamentQuery(name, startAt, TournamentType.Double_Elimination, url).call(ApiCaller); return result; - - } public async Task AddPlayer(int tournamentId, string userName) @@ -56,7 +54,6 @@ namespace LaDOSE.Business.Provider.ChallongProvider var p = new ParticipantEntry(userName); var result = await new AddParticipantQuery(tournamentId, p).call(ApiCaller); return result; - } public async Task> GetTournaments(DateTime? start, DateTime? end) @@ -119,6 +116,7 @@ namespace LaDOSE.Business.Provider.ChallongProvider }; } + public async Task GetTournament(string urlTournament) { diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs index 4e7dd58..fc2420b 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs @@ -307,6 +307,74 @@ namespace LaDOSE.Business.Provider.SmashProvider } + + + public async Task GetNames(string slug) + { + + var graphQLClient = new GraphQLHttpClient("https://api.smash.gg/gql/alpha", new NewtonsoftJsonSerializer()); + graphQLClient.HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}"); + var Event = new GraphQLRequest + { + Query = @"query TournamentQuery($slug: String) { + tournament(slug: $slug){ + id + + name + + events { + id + + name, + state, + videogame { + id, + name, + displayName + }, + entrants{ + nodes{ + id + name, + participants{ + id, + gamerTag + player{ + gamerTag + } + } + } + }, + } + + } + }" + , + OperationName = "TournamentQuery", + Variables = new + { + slug = slug, + } + }; + + //GraphQLHttpRequest preprocessedRequest = await graphQLClient.Options.PreprocessRequest(EventType, graphQLClient); + //var x = preprocessedRequest.ToHttpRequestMessage(graphQLClient.Options, new NewtonsoftJsonSerializer()); + //System.Diagnostics.Trace.WriteLine(x.Content.ReadAsStringAsync().Result); + //var sendAsync = await graphQLClient.HttpClient.SendAsync(x); + //System.Diagnostics.Trace.WriteLine(sendAsync.Content.ReadAsStringAsync().Result); + + var graphQLResponse = await graphQLClient.SendQueryAsync(Event); + if (graphQLResponse.Errors != null) + { + //EventType not done ? + //throw new Exception("Error"); + } + System.Diagnostics.Trace.Write(graphQLResponse.Data.Tournament.Name); + + return graphQLResponse.Data; + } + + public async Task GetTournament(string slug) { diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs index 8feccce..a438799 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs @@ -80,6 +80,8 @@ namespace LaDOSE.Business.Provider.SmashProvider public VideoGameType videogame { get; set; } public Node standings { get; set; } public Node sets { get; set; } + + public Node entrants { get; set; } } public class EntrantType diff --git a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs index 6643bf1..eb33aa5 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs @@ -6,6 +6,7 @@ using System.Reactive.Subjects; using System.Threading.Tasks; using LaDOSE.Business.Helper; using LaDOSE.Business.Interface; +using LaDOSE.Business.Provider.SmashProvider; using LaDOSE.Entity; using LaDOSE.Entity.Challonge; using LaDOSE.Entity.Context; @@ -206,7 +207,7 @@ namespace LaDOSE.Business.Service // var parse = await this.ParseSmash(tournamentSlug); // var test = await GetEventResult(parse.Id); // return test; - + //} //public async Task GetEventsResult(List events) @@ -279,7 +280,7 @@ namespace LaDOSE.Business.Service players = players.Concat(e.Tournaments.SelectMany(e => e.Results.Select(e => e.Player)).Distinct().ToList()).ToList(); cevent.Tournaments = cevent.Tournaments.Concat(e.Tournaments).ToList(); } - + var games = _context.Game.ToList(); TournamentsResult result = new TournamentsResult(); @@ -360,6 +361,15 @@ namespace LaDOSE.Business.Service return await Task.FromResult(result); } + + public async Task> GetPlayer(string slug) + { + var tournament = await _smashProvider.GetNames(slug); + var players = tournament.Tournament.Events.SelectMany(e => e.entrants.nodes.SelectMany(x => x.participants.Select(e => e.gamerTag))).ToList(); + return players; + + } + /// /// Get Result For one Event /// @@ -367,8 +377,8 @@ namespace LaDOSE.Business.Service /// public async Task GetEventResult(int id) { - - Event cevent = _context.Event.Include(e=>e.Tournaments).ThenInclude(t=>t.Results).ThenInclude(e=>e.Player).FirstOrDefault(e => e.Id == id); + + Event cevent = _context.Event.Include(e => e.Tournaments).ThenInclude(t => t.Results).ThenInclude(e => e.Player).FirstOrDefault(e => e.Id == id); var players = cevent.Tournaments.SelectMany(e => e.Results.Select(e => e.Player)).Distinct().ToList(); var games = _context.Game.ToList(); @@ -407,18 +417,18 @@ namespace LaDOSE.Business.Service var Top8 = tournament.Results.Where(p => p.Rank > 4 && p.Rank < 9).ToList(); var Top16 = tournament.Results.Where(p => p.Rank > 8 && p.Rank <= 16).ToList(); - result.Results.Add(new Result(first.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, currentRule.FirstPoint, first.Rank)); + result.Results.Add(new Result(first.Player.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, currentRule.FirstPoint, first.Rank)); lesSacs.Remove(first.Player); result.Results.Add(new Result(second.Player.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, currentRule.SecondPoint, second.Rank)); lesSacs.Remove(second.Player); thirdFourth.ForEach(r => - result.Results.Add(new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, + result.Results.Add(new Result(r.Player.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, currentRule.ThirdFourthPoint, r.Rank))); thirdFourth.ForEach(p => lesSacs.Remove(p.Player)); if (currentRule.Top8Point != 0) { Top8.ForEach(r => - result.Results.Add(new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, + result.Results.Add(new Result(r.Player.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, currentRule.Top8Point, r.Rank))); Top8.ForEach(p => lesSacs.Remove(p.Player)); } @@ -427,20 +437,20 @@ namespace LaDOSE.Business.Service { Top16.ForEach(r => result.Results.Add( - new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, + new Result(r.Player.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, currentRule.Top16Point, r.Rank))); Top16.ForEach(p => lesSacs.Remove(p.Player)); } lesSacs.ForEach(r => - result.Results.Add(new Result(r.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, - currentRule.Participation, tournament.Results.FirstOrDefault(e=>e.Player == r)?.Rank??999))); + result.Results.Add(new Result(r.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, + currentRule.Participation, tournament.Results.FirstOrDefault(e => e.Player == r)?.Rank ?? 999))); } if (result.Results.Any(e => e.GameId == 0)) { - result.Games.Add(new Game(){Id = 0,Name = "GAME NOT FOUND",LongName = "GAME NOT FOUND",Order = 999}); + result.Games.Add(new Game() { Id = 0, Name = "GAME NOT FOUND", LongName = "GAME NOT FOUND", Order = 999 }); } var enumerable = result.Results.Select(e => e.GameId).Distinct();