From 3b16c5feaf6a8c6683d4b556fd75bda2f7189693 Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Tue, 12 Mar 2019 21:41:30 +0100 Subject: [PATCH] Player now resolve in UI --- .../Controllers/WordPressController.cs | 10 +- LaDOSE.Src/LaDOSE.DTO/WPEvent.cs | 14 - LaDOSE.Src/LaDOSE.DTO/WPUser.cs | 8 + LaDOSE.Src/LaDOSE.DTO/WpBooking.cs | 11 + LaDOSE.Src/LaDOSE.DesktopApp/App.xaml | 2 +- .../Behaviors/MultiSelectorBehaviours.cs | 418 ++++++++++++++++++ .../LaDOSE.DesktopApp.csproj | 25 +- .../Properties/Resources.Designer.cs | 44 +- .../Properties/Settings.Designer.cs | 22 +- .../LaDOSE.DesktopApp/Resources/64x64.png | Bin 0 -> 8296 bytes .../LaDOSE.DesktopApp/Services/RestService.cs | 38 +- .../ViewModels/GameViewModel.cs | 7 + .../ViewModels/ShellViewModel.cs | 18 +- .../ViewModels/WebNavigationViewModel.cs | 15 + .../ViewModels/WordPressViewModel.cs | 255 +++++++---- .../LaDOSE.DesktopApp/Views/ShellView.xaml | 16 +- .../Views/WebNavigationView.xaml | 17 + .../Views/WebNavigationView.xaml.cs | 34 ++ .../LaDOSE.DesktopApp/Views/WebView.xaml.cs | 29 ++ .../Views/{WpView.xaml => WordPressView.xaml} | 14 +- .../{WpView.xaml.cs => WordPressView.xaml.cs} | 1 + .../Interface/IWordPressService.cs | 2 +- .../Service/WordPressService.cs | 24 +- 23 files changed, 850 insertions(+), 174 deletions(-) create mode 100644 LaDOSE.Src/LaDOSE.DTO/WPUser.cs create mode 100644 LaDOSE.Src/LaDOSE.DTO/WpBooking.cs create mode 100644 LaDOSE.Src/LaDOSE.DesktopApp/Behaviors/MultiSelectorBehaviours.cs create mode 100644 LaDOSE.Src/LaDOSE.DesktopApp/Resources/64x64.png create mode 100644 LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WebNavigationViewModel.cs create mode 100644 LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml create mode 100644 LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml.cs create mode 100644 LaDOSE.Src/LaDOSE.DesktopApp/Views/WebView.xaml.cs rename LaDOSE.Src/LaDOSE.DesktopApp/Views/{WpView.xaml => WordPressView.xaml} (90%) rename LaDOSE.Src/LaDOSE.DesktopApp/Views/{WpView.xaml.cs => WordPressView.xaml.cs} (98%) diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs index 7fa07c4..b5be32b 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs @@ -64,9 +64,15 @@ namespace LaDOSE.Api.Controllers } [HttpGet("CreateChallonge/{gameId:int}/{wpEventId:int}")] - public bool CreateChallonge(int gameId, int wpEventId) + public string CreateChallonge(int gameId, int wpEventId) { - return _service.CreateChallonge(gameId, wpEventId); + return _service.CreateChallonge(gameId, wpEventId,null); + } + + [HttpPost("CreateChallonge/{gameId:int}/{wpEventId:int}")] + public string CreateChallonge(int gameId, int wpEventId, [FromBody]List additionalPlayer) + { + return _service.CreateChallonge(gameId, wpEventId, additionalPlayer); } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs b/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs index f5f547e..5b08cfe 100644 --- a/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs +++ b/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs @@ -14,18 +14,4 @@ namespace LaDOSE.DTO public DateTime? Date { get; set; } public List WpBookings { get; set; } } - - public class WPBooking - { - public WPUser WpUser { get; set; } - public string Message { get; set; } - - public string Meta { get; set; } - } - - public class WPUser - { - public string Name { get; set; } - } - } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DTO/WPUser.cs b/LaDOSE.Src/LaDOSE.DTO/WPUser.cs new file mode 100644 index 0000000..85b305f --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DTO/WPUser.cs @@ -0,0 +1,8 @@ +namespace LaDOSE.DTO +{ + public class WPUser + { + public string Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs b/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs new file mode 100644 index 0000000..c2ced85 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs @@ -0,0 +1,11 @@ +namespace LaDOSE.DTO +{ + public class WPBooking + { + public WPUser WpUser { get; set; } + public string Message { get; set; } + + public string Meta { get; set; } + } + +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml index 09ab519..5b6efc4 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/App.xaml @@ -8,7 +8,7 @@ - + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Behaviors/MultiSelectorBehaviours.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Behaviors/MultiSelectorBehaviours.cs new file mode 100644 index 0000000..fe81b4d --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Behaviors/MultiSelectorBehaviours.cs @@ -0,0 +1,418 @@ +using System; +using System.Collections; +using System.Collections.Specialized; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; + +namespace LaDOSE.DesktopApp.Behaviors +{ + /// + /// A sync behaviour for a multiselector. + /// + public static class MultiSelectorBehaviours + { + public static readonly DependencyProperty SynchronizedSelectedItems = DependencyProperty.RegisterAttached( + "SynchronizedSelectedItems", typeof(IList), typeof(MultiSelectorBehaviours), new PropertyMetadata(null, OnSynchronizedSelectedItemsChanged)); + + private static readonly DependencyProperty SynchronizationManagerProperty = DependencyProperty.RegisterAttached( + "SynchronizationManager", typeof(SynchronizationManager), typeof(MultiSelectorBehaviours), new PropertyMetadata(null)); + + /// + /// Gets the synchronized selected items. + /// + /// The dependency object. + /// The list that is acting as the sync list. + public static IList GetSynchronizedSelectedItems(DependencyObject dependencyObject) + { + return (IList)dependencyObject.GetValue(SynchronizedSelectedItems); + } + + /// + /// Sets the synchronized selected items. + /// + /// The dependency object. + /// The value to be set as synchronized items. + public static void SetSynchronizedSelectedItems(DependencyObject dependencyObject, IList value) + { + dependencyObject.SetValue(SynchronizedSelectedItems, value); + } + + private static SynchronizationManager GetSynchronizationManager(DependencyObject dependencyObject) + { + return (SynchronizationManager)dependencyObject.GetValue(SynchronizationManagerProperty); + } + + private static void SetSynchronizationManager(DependencyObject dependencyObject, SynchronizationManager value) + { + dependencyObject.SetValue(SynchronizationManagerProperty, value); + } + + private static void OnSynchronizedSelectedItemsChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + { + if (e.OldValue != null) + { + SynchronizationManager synchronizer = GetSynchronizationManager(dependencyObject); + synchronizer.StopSynchronizing(); + + SetSynchronizationManager(dependencyObject, null); + } + + IList list = e.NewValue as IList; + Selector selector = dependencyObject as Selector; + + // check that this property is an IList, and that it is being set on a ListBox + if (list != null && selector != null) + { + SynchronizationManager synchronizer = GetSynchronizationManager(dependencyObject); + if (synchronizer == null) + { + synchronizer = new SynchronizationManager(selector); + SetSynchronizationManager(dependencyObject, synchronizer); + } + + synchronizer.StartSynchronizingList(); + } + } + + /// + /// A synchronization manager. + /// + private class SynchronizationManager + { + private readonly Selector _multiSelector; + private TwoListSynchronizer _synchronizer; + + /// + /// Initializes a new instance of the class. + /// + /// The selector. + internal SynchronizationManager(Selector selector) + { + _multiSelector = selector; + } + + /// + /// Starts synchronizing the list. + /// + public void StartSynchronizingList() + { + IList list = GetSynchronizedSelectedItems(_multiSelector); + + if (list != null) + { + _synchronizer = new TwoListSynchronizer(GetSelectedItemsCollection(_multiSelector), list); + _synchronizer.StartSynchronizing(); + } + } + + /// + /// Stops synchronizing the list. + /// + public void StopSynchronizing() + { + _synchronizer.StopSynchronizing(); + } + + public static IList GetSelectedItemsCollection(Selector selector) + { + if (selector is MultiSelector) + { + return (selector as MultiSelector).SelectedItems; + } + else if (selector is ListBox) + { + return (selector as ListBox).SelectedItems; + } + else + { + throw new InvalidOperationException("Target object has no SelectedItems property to bind."); + } + } + + } + } + + + public class TwoListSynchronizer : IWeakEventListener + { + private static readonly IListItemConverter DefaultConverter = new DoNothingListItemConverter(); + private readonly IList _masterList; + private readonly IListItemConverter _masterTargetConverter; + private readonly IList _targetList; + + + /// + /// Initializes a new instance of the class. + /// + /// The master list. + /// The target list. + /// The master-target converter. + public TwoListSynchronizer(IList masterList, IList targetList, IListItemConverter masterTargetConverter) + { + _masterList = masterList; + _targetList = targetList; + _masterTargetConverter = masterTargetConverter; + } + + /// + /// Initializes a new instance of the class. + /// + /// The master list. + /// The target list. + public TwoListSynchronizer(IList masterList, IList targetList) + : this(masterList, targetList, DefaultConverter) + { + } + + private delegate void ChangeListAction(IList list, NotifyCollectionChangedEventArgs e, Converter converter); + + /// + /// Starts synchronizing the lists. + /// + public void StartSynchronizing() + { + ListenForChangeEvents(_masterList); + ListenForChangeEvents(_targetList); + + // Update the Target list from the Master list + SetListValuesFromSource(_masterList, _targetList, ConvertFromMasterToTarget); + + // In some cases the target list might have its own view on which items should included: + // so update the master list from the target list + // (This is the case with a ListBox SelectedItems collection: only items from the ItemsSource can be included in SelectedItems) + if (!TargetAndMasterCollectionsAreEqual()) + { + SetListValuesFromSource(_targetList, _masterList, ConvertFromTargetToMaster); + } + } + + /// + /// Stop synchronizing the lists. + /// + public void StopSynchronizing() + { + StopListeningForChangeEvents(_masterList); + StopListeningForChangeEvents(_targetList); + } + + /// + /// Receives events from the centralized event manager. + /// + /// The type of the calling this method. + /// Object that originated the event. + /// Event data. + /// + /// true if the listener handled the event. It is considered an error by the handling in WPF to register a listener for an event that the listener does not handle. Regardless, the method should return false if it receives an event that it does not recognize or handle. + /// + public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) + { + HandleCollectionChanged(sender as IList, e as NotifyCollectionChangedEventArgs); + + return true; + } + + /// + /// Listens for change events on a list. + /// + /// The list to listen to. + protected void ListenForChangeEvents(IList list) + { + if (list is INotifyCollectionChanged) + { + CollectionChangedEventManager.AddListener(list as INotifyCollectionChanged, this); + } + } + + /// + /// Stops listening for change events. + /// + /// The list to stop listening to. + protected void StopListeningForChangeEvents(IList list) + { + if (list is INotifyCollectionChanged) + { + CollectionChangedEventManager.RemoveListener(list as INotifyCollectionChanged, this); + } + } + + private void AddItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + int itemCount = e.NewItems.Count; + + for (int i = 0; i < itemCount; i++) + { + int insertionPoint = e.NewStartingIndex + i; + + if (insertionPoint > list.Count) + { + list.Add(converter(e.NewItems[i])); + } + else + { + list.Insert(insertionPoint, converter(e.NewItems[i])); + } + } + } + + private object ConvertFromMasterToTarget(object masterListItem) + { + return _masterTargetConverter == null ? masterListItem : _masterTargetConverter.Convert(masterListItem); + } + + private object ConvertFromTargetToMaster(object targetListItem) + { + return _masterTargetConverter == null ? targetListItem : _masterTargetConverter.ConvertBack(targetListItem); + } + + private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + IList sourceList = sender as IList; + + switch (e.Action) + { + case NotifyCollectionChangedAction.Add: + PerformActionOnAllLists(AddItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Move: + PerformActionOnAllLists(MoveItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Remove: + PerformActionOnAllLists(RemoveItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Replace: + PerformActionOnAllLists(ReplaceItems, sourceList, e); + break; + case NotifyCollectionChangedAction.Reset: + UpdateListsFromSource(sender as IList); + break; + default: + break; + } + } + + private void MoveItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + RemoveItems(list, e, converter); + AddItems(list, e, converter); + } + + private void PerformActionOnAllLists(ChangeListAction action, IList sourceList, NotifyCollectionChangedEventArgs collectionChangedArgs) + { + if (sourceList == _masterList) + { + PerformActionOnList(_targetList, action, collectionChangedArgs, ConvertFromMasterToTarget); + } + else + { + PerformActionOnList(_masterList, action, collectionChangedArgs, ConvertFromTargetToMaster); + } + } + + private void PerformActionOnList(IList list, ChangeListAction action, NotifyCollectionChangedEventArgs collectionChangedArgs, Converter converter) + { + StopListeningForChangeEvents(list); + action(list, collectionChangedArgs, converter); + ListenForChangeEvents(list); + } + + private void RemoveItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + int itemCount = e.OldItems.Count; + + // for the number of items being removed, remove the item from the Old Starting Index + // (this will cause following items to be shifted down to fill the hole). + for (int i = 0; i < itemCount; i++) + { + list.RemoveAt(e.OldStartingIndex); + } + } + + private void ReplaceItems(IList list, NotifyCollectionChangedEventArgs e, Converter converter) + { + RemoveItems(list, e, converter); + AddItems(list, e, converter); + } + + private void SetListValuesFromSource(IList sourceList, IList targetList, Converter converter) + { + StopListeningForChangeEvents(targetList); + + targetList.Clear(); + + foreach (object o in sourceList) + { + targetList.Add(converter(o)); + } + + ListenForChangeEvents(targetList); + } + + private bool TargetAndMasterCollectionsAreEqual() + { + return _masterList.Cast().SequenceEqual(_targetList.Cast().Select(item => ConvertFromTargetToMaster(item))); + } + + /// + /// Makes sure that all synchronized lists have the same values as the source list. + /// + /// The source list. + private void UpdateListsFromSource(IList sourceList) + { + if (sourceList == _masterList) + { + SetListValuesFromSource(_masterList, _targetList, ConvertFromMasterToTarget); + } + else + { + SetListValuesFromSource(_targetList, _masterList, ConvertFromTargetToMaster); + } + } + + + + + /// + /// An implementation that does nothing in the conversions. + /// + internal class DoNothingListItemConverter : IListItemConverter + { + /// + /// Converts the specified master list item. + /// + /// The master list item. + /// The result of the conversion. + public object Convert(object masterListItem) + { + return masterListItem; + } + + /// + /// Converts the specified target list item. + /// + /// The target list item. + /// The result of the conversion. + public object ConvertBack(object targetListItem) + { + return targetListItem; + } + } + public interface IListItemConverter + { + /// + /// Converts the specified master list item. + /// + /// The master list item. + /// The result of the conversion. + object Convert(object masterListItem); + + /// + /// Converts the specified target list item. + /// + /// The target list item. + /// The result of the conversion. + object ConvertBack(object targetListItem); + } + } +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj index d72efd6..0c7e86a 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj +++ b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj @@ -8,12 +8,13 @@ WinExe LaDOSE.DesktopApp LaDOSE.DesktopApp - v4.6.1 + v4.6.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true true + AnyCPU @@ -50,7 +51,11 @@ + + + + ..\packages\Caliburn.Micro.3.2.0\lib\net45\System.Windows.Interactivity.dll @@ -72,6 +77,7 @@ MSBuild:Compile Designer + @@ -82,15 +88,19 @@ + + + WebNavigationView.xaml + ShellView.xaml GameView.xaml - - WpView.xaml + + WordPressView.xaml App.xaml @@ -100,6 +110,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -108,7 +122,7 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile @@ -148,8 +162,9 @@ LaDOSE.DTO + - + \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs index 5e8e560..62258ed 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace LaDOSE.DesktopApp.Properties -{ - - +namespace LaDOSE.DesktopApp.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,51 +19,43 @@ namespace LaDOSE.DesktopApp.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LaDOSE.DesktopApp.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs index ba88adf..e05364f 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Properties/Settings.Designer.cs @@ -8,21 +8,17 @@ // //------------------------------------------------------------------------------ -namespace LaDOSE.DesktopApp.Properties -{ - - +namespace LaDOSE.DesktopApp.Properties { + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { + + public static Settings Default { + get { return defaultInstance; } } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Resources/64x64.png b/LaDOSE.Src/LaDOSE.DesktopApp/Resources/64x64.png new file mode 100644 index 0000000000000000000000000000000000000000..e4e114cd52328448a3e3ed00075af088e9fb8f7d GIT binary patch literal 8296 zcmeAS@N?(olHy`uVBq!ia0y~yU~m9o4mJh`hE{(JaZG%Q-e|yQz{EjrrIztFso&TM3hAM`dB6B=jtVb)aX^@7BGN-jeSKyVsdtB zi9%9pdS;%j()-=}l@u~lY?Z=IeGPmIoKrJ0J*tXQgRA^PlB=?lEmM^2?G$V(tSWK~ za#KqZ6)JLb@`|l0Y?Z*~TICg6frRyy6u?SKvTcwn`Gt*5rG%-~$ zx70HIbD3=a&{Grv{~_DTCZpVC7ttnpl!w6q28x0}I7~jQo=P;*9(P z1!reas97p#glFcZf0&U=z}5`DY9WgK`w3}COBP!(x{yRBJro@ zrPwMJDcRc{TvXY_z#wzO)5S5Q;?|yO&H|b1mC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*?Qip#W5#tF&pFIAPjos)mfuX*k9CYx3IXTDsgr&+!T<<9-} z#8&%2cV&B}RPBp|U*UD{8=uIVU$?yNva0y*) z?J0kHeT~9;p_gk{aIAZFZ%5XYuDw?y7YgKiEMal0yw!0m(e05+jjd+eEWyS^wH0hD z*`pPA_)oszXS-v?W$Ab9tKX>!sX4r_6q;j``0vx1r=D-6{pGsx;dQ^} z3NFs_7S85O5_NkLHaRA&Ab0h|Q`e#wn9H?X`yuG587%TW{NF?^qeX{KUbH+kWBL3) zo^Rgw^|SeHziJ^d$H2fK@8Pw1I%a$LSz|u?ryqUa)uOPTho$b%ucN=N=ii=Y`(xwY zneFfH?JSBnIb_ZmaN*?Fqy2|Iaq;ij9PBk;FI1<>rQPl9f?LttR}OKQI`nUKTE2Oz zl|SqAaE}TlH{tb%PbMT3Fx{{H=JRKMyq$PWw&CK1X3rE-KAGB2{N4JeY{v}7LyYev zzqW2ZxVU-pvy1y{HMjko{(U)re!lLV%eTXBOkYtL?IbqyLfC;7dz6+NwRzWX`NNgk z%*3n4t6R-_?apku&Lv9Pk5vq>nYSgIoq2Cxsq-ny=7_$1u~N^m9m<vhy!-0K z74Ppp;hZzM-r^^#R^syMmn7^hlj15;4eF+4uBlgC>sxZgG9vC`N0#-KJK5VRet!JV aD#4KCC&R+I_oXUm?%&hZ&t;ucLK6T%kau(string resource, P entity) + { + var json = new RestSharp.Serialization.Json.JsonSerializer(); + var jsonD = new RestSharp.Serialization.Json.JsonDeserializer(); + var request = new RestRequest(); + request.Method = Method.POST; + request.Resource = resource; + request.AddHeader("Accept", "application/json"); + request.AddHeader("Content-type", "application/json"); + request.Parameters.Clear(); + request.AddParameter("application/json; charset=utf-8", json.Serialize(entity), ParameterType.RequestBody); + //request.AddObject(entity); + var response = Client.Execute(request); + //var content = response.Content; // raw content as string + try + { + return jsonD.Deserialize(response); + } + catch (Exception) + { + return default(R); + } + + } #endregion @@ -77,11 +103,17 @@ namespace LaDOSE.DesktopApp.Services } - public bool CreateChallonge(int gameId, int eventId) + public string CreateChallonge(int gameId, int eventId) { var restRequest = new RestRequest($"/api/wordpress/CreateChallonge/{gameId}/{eventId}", Method.GET); - var restResponse = Client.Get(restRequest); - return restResponse.Data; + var restResponse = Client.Get(restRequest); + return restResponse.Content; + } + public string CreateChallonge2(int gameId, int eventId, List optionalPlayers) + { + + var restResponse = Post,string>($"/api/wordpress/CreateChallonge/{gameId}/{eventId}",optionalPlayers); + return restResponse; } public bool RefreshDb() { diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs index 7cfdfc9..75ac9d6 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs @@ -16,6 +16,13 @@ namespace LaDOSE.DesktopApp.ViewModels { this.RestService = restService; this.Games=new List(); + + } + + protected override void OnInitialize() + { + LoadGames(); + base.OnInitialize(); } public void LoadGames() diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs index ae1f107..4b020cc 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/ShellViewModel.cs @@ -1,19 +1,29 @@ -using Caliburn.Micro; +using System; +using System.Windows; +using System.Windows.Media.Imaging; +using Caliburn.Micro; using LaDOSE.DesktopApp.Services; namespace LaDOSE.DesktopApp.ViewModels { public class ShellViewModel : Conductor.Collection.AllActive { + + protected override void OnInitialize() { + this.DisplayName = "LaDOSE"; + this.AppIcon = BitmapFrame.Create(Application.GetResourceStream(new Uri("/LaDOSE.DesktopApp;component/Resources/64x64.png", + UriKind.RelativeOrAbsolute)).Stream); var wordPressViewModel = new WordPressViewModel(IoC.Get()); ActivateItem(wordPressViewModel); base.OnInitialize(); - + } + public BitmapFrame AppIcon { get; set; } + public void LoadEvent() { ActivateItem(new WordPressViewModel(IoC.Get())); @@ -23,5 +33,9 @@ namespace LaDOSE.DesktopApp.ViewModels ActivateItem(new GameViewModel(IoC.Get())); } + public void OpenWeb() + { + ActivateItem(new WebNavigationViewModel("www.google.com")); + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WebNavigationViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WebNavigationViewModel.cs new file mode 100644 index 0000000..bc5767c --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WebNavigationViewModel.cs @@ -0,0 +1,15 @@ +using Caliburn.Micro; + +namespace LaDOSE.DesktopApp.ViewModels +{ + public class WebNavigationViewModel : Screen + { + public WebNavigationViewModel(string uri) + { + Uri = uri; + this.DisplayName = Uri; + } + + public string Uri { get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs index b75491e..3137fc6 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs @@ -22,7 +22,8 @@ namespace LaDOSE.DesktopApp.ViewModels private Game _selectedGame; private ObservableCollection _players; private ObservableCollection _playersOptions; - + private ObservableCollection _optionalPlayers; + private RestService RestService { get; set; } public WordPressViewModel(RestService restService) @@ -30,6 +31,121 @@ namespace LaDOSE.DesktopApp.ViewModels this.RestService = restService; Players = new ObservableCollection(); PlayersOptions = new ObservableCollection(); + OptionalPlayers = new ObservableCollection(); + } + + #region Auto Property + + protected override void OnInitialize() + { + base.OnInitialize(); + Task.Factory.StartNew(new Action(this.Load), TaskCreationOptions.LongRunning).ContinueWith(t => { }, + CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, + TaskScheduler.FromCurrentSynchronizationContext()); + } + + public bool CanGenerate + { + get { return SelectedWpEvent != null && SelectedGame != null && Players?.Count() > 0; } + } + + public List Events { get; set; } + + public WPEvent SelectedWpEvent + { + get => _selectedWpEvent; + set + { + _selectedWpEvent = value; + SelectedGame = null; + ParseGame(_selectedWpEvent); + } + } + + public Game SelectedGame + { + get => _selectedGame; + set + { + _selectedGame = value; + + Players.Clear(); + PlayersOptions.Clear(); + + Task.Factory.StartNew(LoadPlayers, TaskCreationOptions.LongRunning).ContinueWith(t => { }, + CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, + TaskScheduler.FromCurrentSynchronizationContext()); + NotifyOfPropertyChange(() => SelectedGame); + NotifyOfPropertyChange(() => this.CanGenerate); + NotifyOfPropertyChange(() => Players); + NotifyOfPropertyChange(() => PlayersOptions); + } + } + + public ObservableCollection Players + { + get => _players; + set + { + _players = value; + NotifyOfPropertyChange(() => Players); + } + } + + public ObservableCollection PlayersOptions + { + get => _playersOptions; + set + { + _playersOptions = value; + NotifyOfPropertyChange(() => PlayersOptions); + } + } + + public ObservableCollection OptionalPlayers + { + get => _optionalPlayers; + set + { + _optionalPlayers = value; + NotifyOfPropertyChange(() => OptionalPlayers); + } + } + + public ObservableCollection GamesFound { get; set; } + public List Games { get; set; } + + #endregion + + #region Commands + + public void UpdateDb() + { + Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; + var tsk = Task.Factory.StartNew(new Action(()=>this.RestService.RefreshDb())); + tsk.ContinueWith(t => + { + MessageBox.Show(t.Exception.InnerException.Message); + }, + CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, + TaskScheduler.FromCurrentSynchronizationContext()); + + MessageBox.Show("Database updated"); + + } + + public void Generate() + { + List test = new List(); + test = OptionalPlayers.ToList(); + var messageBoxText = this.RestService.CreateChallonge2(SelectedGame.Id, SelectedWpEvent.Id, test); + + if (messageBoxText != null && messageBoxText.Length > 0 && !messageBoxText.Contains("error")) + { + System.Diagnostics.Process.Start($"https://challonge.com/{messageBoxText}"); + } + else + MessageBox.Show("Didn't work :("); } public void LoadEvents() @@ -45,86 +161,7 @@ namespace LaDOSE.DesktopApp.ViewModels TaskScheduler.FromCurrentSynchronizationContext()); } - private void Load() - { - GamesFound = new ObservableCollection(); - this.Games = this.RestService.GetGames(); - this.Events = this.RestService.GetEvents(); - - NotifyOfPropertyChange("Events"); - Application.Current.Dispatcher.Invoke(() => - System.Windows.Input.Mouse.OverrideCursor = null); - } - - - public bool CanGenerate - { - get { return SelectedWpEvent != null && SelectedGame != null; } - } - - - public List Events { get; set; } - - public WPEvent SelectedWpEvent - { - get => _selectedWpEvent; - set - { - _selectedWpEvent = value; - SelectedGame = null; - ParseGame(_selectedWpEvent); - - } - } - - public Game SelectedGame - { - get => _selectedGame; - set - { - _selectedGame = value; - - Players.Clear(); - PlayersOptions.Clear(); - - Task.Factory.StartNew(LoadPlayers,TaskCreationOptions.LongRunning).ContinueWith(t => - { - - }, - CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, - TaskScheduler.FromCurrentSynchronizationContext()); - NotifyOfPropertyChange(() => SelectedGame); - NotifyOfPropertyChange(() => this.CanGenerate); - NotifyOfPropertyChange(() => Players); - NotifyOfPropertyChange(() => PlayersOptions); - } - } - - - - public ObservableCollection Players - { - get => _players; - set - { - _players = value; - NotifyOfPropertyChange(()=>Players); - } - } - - public ObservableCollection PlayersOptions - { - get => _playersOptions; - set - { - _playersOptions = value; - NotifyOfPropertyChange(() => PlayersOptions); - } - } - - - public ObservableCollection GamesFound { get; set; } - public List Games { get; set; } + #endregion private void ParseGame(WPEvent selectedWpEvent) { @@ -153,32 +190,58 @@ namespace LaDOSE.DesktopApp.ViewModels private void LoadPlayers() { - if (SelectedWpEvent != null) if (SelectedGame != null) { - this.RestService.GetUsers(SelectedWpEvent.Id, SelectedGame.Id).ForEach((e) => this.Players.AddUI(e)); - this.RestService.GetUsersOptions(SelectedWpEvent.Id, SelectedGame.Id).ForEach((e) => this.PlayersOptions.AddUI(e)); + var findUser = FindUser(SelectedWpEvent.Id, SelectedGame); + var findUser2 = FindUser(SelectedWpEvent.Id, SelectedGame,true); + findUser.ForEach((e) => this.Players.AddUI(e)); + findUser2.ForEach((e) => this.PlayersOptions.AddUI(e)); + //this.RestService.GetUsers(SelectedWpEvent.Id, SelectedGame.Id) + // .ForEach((e) => this.Players.AddUI(e)); + //this.RestService.GetUsersOptions(SelectedWpEvent.Id, SelectedGame.Id) + // .ForEach((e) => this.PlayersOptions.AddUI(e)); + NotifyOfPropertyChange(() => this.CanGenerate); } - } - public void UpdateDb() + private void Load() { - if (this.RestService.RefreshDb()) - MessageBox.Show("DataBaseUpdated"); - else - MessageBox.Show("Update Failed"); + Application.Current.Dispatcher.Invoke(() => + System.Windows.Input.Mouse.OverrideCursor = Cursors.Wait); + GamesFound = new ObservableCollection(); + this.Games = this.RestService.GetGames(); + this.Events = this.RestService.GetEvents(); + + NotifyOfPropertyChange("Events"); + Application.Current.Dispatcher.Invoke(() => + System.Windows.Input.Mouse.OverrideCursor = null); } - public void Generate() + public List FindUser(int wpEventId, Game game,bool optional = false) { - if (this.RestService.CreateChallonge(SelectedGame.Id, SelectedWpEvent.Id)) - MessageBox.Show("Challonge Created"); - else - MessageBox.Show("Didn't worl :("); - } + string[] selectedGameWpId; + selectedGameWpId = !optional ? game.WordPressTag.Split(';') : game.WordPressTagOs.Split(';'); + + var currentWpEvent = this.Events.Where(e => e.Id == wpEventId).ToList(); + List bookings = currentWpEvent.SelectMany(e => e.WpBookings).ToList(); + List users = new List(); + foreach (var booking in bookings) + { + var reservations = WpEventDeserialize.Parse(booking.Meta); + if (reservations != null) + { + var gamesReservation = reservations.Where(e => e.Valid).Select(e => e.Name); + if (selectedGameWpId.Any(e => gamesReservation.Contains(e))) + { + users.Add(booking.WpUser); + } + } + } + + return users; + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml index 47290be..b24e19e 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/ShellView.xaml @@ -4,10 +4,16 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:LaDOSE.DesktopApp.Views" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:cal="http://www.caliburnproject.org" + Icon="{Binding Path=AppIcon}" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> + + + + @@ -32,10 +38,18 @@ + + + + + + + + - + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml new file mode 100644 index 0000000..61fd2b3 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml.cs new file mode 100644 index 0000000..e107967 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebNavigationView.xaml.cs @@ -0,0 +1,34 @@ +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; +using LaDOSE.DesktopApp.ViewModels; + +namespace LaDOSE.DesktopApp.Views +{ + /// + /// Interaction logic for ShellView.xaml + /// + public partial class WebNavigationView : UserControl + { + public WebNavigationView() + { + + InitializeComponent(); + + + } + + + } +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebView.xaml.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebView.xaml.cs new file mode 100644 index 0000000..267a933 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WebView.xaml.cs @@ -0,0 +1,29 @@ +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 WebNavigationView : UserControl + { + public WebNavigationView() + { + + InitializeComponent(); + } + } +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml similarity index 90% rename from LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml rename to LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml index 0cab5f7..8a3dbba 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml @@ -6,13 +6,16 @@ xmlns:local="clr-namespace:LaDOSE.DesktopApp.Views" xmlns:userControls="clr-namespace:LaDOSE.DesktopApp.UserControls" xmlns:cal="http://www.caliburnproject.org" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:behaviors="clr-namespace:LaDOSE.DesktopApp.Behaviors" mc:Ignorable="d" + d:DesignHeight="450" d:DesignWidth="800"> - + @@ -43,7 +46,7 @@ + x:Name="BookingList" IsTextSearchEnabled="True" TextSearch.TextPath="WpUser.Name"> @@ -76,7 +79,7 @@ + SelectedItem="{Binding SelectedGame,UpdateSourceTrigger=PropertyChanged}" IsTextSearchEnabled="True" TextSearch.TextPath="Name"> @@ -99,7 +102,7 @@ - + @@ -113,7 +116,8 @@ - + + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml.cs similarity index 98% rename from LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml.cs rename to LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml.cs index 31063f6..d775dbf 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WpView.xaml.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml.cs @@ -22,6 +22,7 @@ namespace LaDOSE.DesktopApp.Views { public WordPressView() { + InitializeComponent(); } diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs index e5af5eb..252fee3 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs @@ -10,6 +10,6 @@ namespace LaDOSE.Business.Interface List GetBooking(int wpEventId, Game game); List GetBookingOptions(int wpEventId, Game game); bool UpdateBooking(); - bool CreateChallonge(int gameId, int wpEventId); + string CreateChallonge(int gameId, int wpEventId, IList additionPlayers); } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs b/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs index 8537326..b743485 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs @@ -9,6 +9,7 @@ using LaDOSE.Entity.Context; using LaDOSE.Entity.Wordpress; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; namespace LaDOSE.Business.Service { @@ -78,14 +79,14 @@ namespace LaDOSE.Business.Service } return users; } - public bool CreateChallonge(int gameId, int wpEventId) + public string CreateChallonge(int gameId, int wpEventId, IList additionalPlayers) { var selectedGame = _context.Game.FirstOrDefault(e => e.Id == gameId); var selectedGameWpId = selectedGame.WordPressTag.Split(';'); var currentWpEvent = _context.WPEvent.Include(e => e.WPBookings).ThenInclude(e => e.WPUser) .Where(e => e.Id == wpEventId); var users = currentWpEvent.SelectMany(e => e.WPBookings.Select(u => u.WPUser)); - + var useradded = new List(); if (selectedGame != null) @@ -110,6 +111,7 @@ namespace LaDOSE.Business.Service { try { + useradded.Add(booking.WPUser); _challongeProvider.AddPlayer(tournament.id, booking.WPUser.Name); } catch @@ -124,13 +126,25 @@ namespace LaDOSE.Business.Service } - - return true; + if (additionalPlayers != null && additionalPlayers.Count > 0) + { + foreach (var additionalPlayer in additionalPlayers) + { + if (useradded.All(e => e.Name != additionalPlayer.Name)) + { + _challongeProvider.AddPlayer(tournament.id, additionalPlayer.Name); + } + } + + } + + + return tournament.url; } - return false; + return "error while creating challonge"; } } } \ No newline at end of file