REST to a .Net Standard Library
Test REST in discord bot and WPF Small improvements
This commit is contained in:
@@ -14,6 +14,7 @@ namespace LaDOSE.Api.Controllers
|
||||
public class WordPressController : Controller
|
||||
{
|
||||
public IGameService GameService { get; }
|
||||
|
||||
private IWordPressService _service;
|
||||
// GET
|
||||
|
||||
@@ -24,37 +25,50 @@ namespace LaDOSE.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet("WPEvent")]
|
||||
public List<WPEventDTO> Event()
|
||||
{
|
||||
var wpEvents = _service.GetWpEvent();
|
||||
foreach (var wpEvent in wpEvents)
|
||||
{
|
||||
|
||||
foreach (var wpEventWpBooking in wpEvent.WPBookings)
|
||||
{
|
||||
wpEventWpBooking.WPEvent = null;
|
||||
wpEventWpBooking.WPUser.WPBookings = null;
|
||||
}
|
||||
}
|
||||
|
||||
return Mapper.Map<List<WPEventDTO>>(wpEvents);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("NextEvent")]
|
||||
public WPEventDTO NextEvent()
|
||||
{
|
||||
var wpEvents = _service.GetNextWpEvent();
|
||||
|
||||
|
||||
foreach (var wpEventWpBooking in wpEvents.WPBookings)
|
||||
{
|
||||
wpEventWpBooking.WPEvent = null;
|
||||
wpEventWpBooking.WPUser.WPBookings = null;
|
||||
}
|
||||
|
||||
return Mapper.Map<WPEventDTO>(wpEvents);
|
||||
}
|
||||
|
||||
[HttpGet("GetUsers/{wpEventId}/{gameId}")]
|
||||
public List<WPUserDTO> GetUsers(int wpEventId, int gameId)
|
||||
{
|
||||
var game = GameService.GetById(gameId);
|
||||
return Mapper.Map<List<WPUserDTO>>(_service.GetBooking(wpEventId, game));
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("GetUsersOptions/{wpEventId}/{gameId}")]
|
||||
public List<WPUserDTO> GetUsersOptions(int wpEventId, int gameId)
|
||||
{
|
||||
var game = GameService.GetById(gameId);
|
||||
return Mapper.Map<List<WPUserDTO>>(_service.GetBookingOptions(wpEventId, game));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +76,6 @@ namespace LaDOSE.Api.Controllers
|
||||
public bool UpdateDb()
|
||||
{
|
||||
return _service.UpdateBooking();
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("CreateChallonge/{gameId:int}/{wpEventId:int}")]
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string ImgUrl { get; set; }
|
||||
public string WordPressTag { get; set; }
|
||||
public string WordPressTagOs { get; set; }
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interactivity;
|
||||
|
||||
namespace LaDOSE.DesktopApp.Behaviors
|
||||
{
|
||||
public class TextBoxInputRegExBehaviour : Behavior<TextBox>
|
||||
{
|
||||
#region DependencyProperties
|
||||
public static readonly DependencyProperty RegularExpressionProperty =
|
||||
DependencyProperty.Register("RegularExpression", typeof(string), typeof(TextBoxInputRegExBehaviour), new FrameworkPropertyMetadata(".*"));
|
||||
|
||||
public string RegularExpression
|
||||
{
|
||||
get { return (string)GetValue(RegularExpressionProperty); }
|
||||
set { SetValue(RegularExpressionProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MaxLengthProperty =
|
||||
DependencyProperty.Register("MaxLength", typeof(int), typeof(TextBoxInputRegExBehaviour),
|
||||
new FrameworkPropertyMetadata(int.MinValue));
|
||||
|
||||
public int MaxLength
|
||||
{
|
||||
get { return (int)GetValue(MaxLengthProperty); }
|
||||
set { SetValue(MaxLengthProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EmptyValueProperty =
|
||||
DependencyProperty.Register("EmptyValue", typeof(string), typeof(TextBoxInputRegExBehaviour), null);
|
||||
|
||||
public string EmptyValue
|
||||
{
|
||||
get { return (string)GetValue(EmptyValueProperty); }
|
||||
set { SetValue(EmptyValueProperty, value); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Attach our behaviour. Add event handlers
|
||||
/// </summary>
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
|
||||
AssociatedObject.PreviewTextInput += PreviewTextInputHandler;
|
||||
AssociatedObject.PreviewKeyDown += PreviewKeyDownHandler;
|
||||
DataObject.AddPastingHandler(AssociatedObject, PastingHandler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deattach our behaviour. remove event handlers
|
||||
/// </summary>
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
base.OnDetaching();
|
||||
|
||||
AssociatedObject.PreviewTextInput -= PreviewTextInputHandler;
|
||||
AssociatedObject.PreviewKeyDown -= PreviewKeyDownHandler;
|
||||
DataObject.RemovePastingHandler(AssociatedObject, PastingHandler);
|
||||
}
|
||||
|
||||
#region Event handlers [PRIVATE] --------------------------------------
|
||||
|
||||
void PreviewTextInputHandler(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
string text;
|
||||
if (this.AssociatedObject.Text.Length < this.AssociatedObject.CaretIndex)
|
||||
text = this.AssociatedObject.Text;
|
||||
else
|
||||
{
|
||||
// Remaining text after removing selected text.
|
||||
string remainingTextAfterRemoveSelection;
|
||||
|
||||
text = TreatSelectedText(out remainingTextAfterRemoveSelection)
|
||||
? remainingTextAfterRemoveSelection.Insert(AssociatedObject.SelectionStart, e.Text)
|
||||
: AssociatedObject.Text.Insert(this.AssociatedObject.CaretIndex, e.Text);
|
||||
}
|
||||
|
||||
e.Handled = !ValidateText(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PreviewKeyDown event handler
|
||||
/// </summary>
|
||||
void PreviewKeyDownHandler(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(this.EmptyValue))
|
||||
return;
|
||||
|
||||
string text = null;
|
||||
|
||||
// Handle the Backspace key
|
||||
if (e.Key == Key.Back)
|
||||
{
|
||||
if (!this.TreatSelectedText(out text))
|
||||
{
|
||||
if (AssociatedObject.SelectionStart > 0)
|
||||
text = this.AssociatedObject.Text.Remove(AssociatedObject.SelectionStart - 1, 1);
|
||||
}
|
||||
}
|
||||
// Handle the Delete key
|
||||
else if (e.Key == Key.Delete)
|
||||
{
|
||||
// If text was selected, delete it
|
||||
if (!this.TreatSelectedText(out text) && this.AssociatedObject.Text.Length > AssociatedObject.SelectionStart)
|
||||
{
|
||||
// Otherwise delete next symbol
|
||||
text = this.AssociatedObject.Text.Remove(AssociatedObject.SelectionStart, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (text == string.Empty)
|
||||
{
|
||||
this.AssociatedObject.Text = this.EmptyValue;
|
||||
if (e.Key == Key.Back)
|
||||
AssociatedObject.SelectionStart++;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void PastingHandler(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
if (e.DataObject.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
string text = Convert.ToString(e.DataObject.GetData(DataFormats.Text));
|
||||
|
||||
if (!ValidateText(text))
|
||||
e.CancelCommand();
|
||||
}
|
||||
else
|
||||
e.CancelCommand();
|
||||
}
|
||||
#endregion Event handlers [PRIVATE] -----------------------------------
|
||||
|
||||
#region Auxiliary methods [PRIVATE] -----------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Validate certain text by our regular expression and text length conditions
|
||||
/// </summary>
|
||||
/// <param name="text"> Text for validation </param>
|
||||
/// <returns> True - valid, False - invalid </returns>
|
||||
private bool ValidateText(string text)
|
||||
{
|
||||
return (new Regex(this.RegularExpression, RegexOptions.IgnoreCase)).IsMatch(text) && (MaxLength == int.MinValue || text.Length <= MaxLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle text selection
|
||||
/// </summary>
|
||||
/// <returns>true if the character was successfully removed; otherwise, false. </returns>
|
||||
private bool TreatSelectedText(out string text)
|
||||
{
|
||||
text = null;
|
||||
if (AssociatedObject.SelectionLength <= 0)
|
||||
return false;
|
||||
|
||||
var length = this.AssociatedObject.Text.Length;
|
||||
if (AssociatedObject.SelectionStart >= length)
|
||||
return true;
|
||||
|
||||
if (AssociatedObject.SelectionStart + AssociatedObject.SelectionLength >= length)
|
||||
AssociatedObject.SelectionLength = length - AssociatedObject.SelectionStart;
|
||||
|
||||
text = this.AssociatedObject.Text.Remove(AssociatedObject.SelectionStart, AssociatedObject.SelectionLength);
|
||||
return true;
|
||||
}
|
||||
#endregion Auxiliary methods [PRIVATE] --------------------------------
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Windows;
|
||||
using Caliburn.Micro;
|
||||
using LaDOSE.DesktopApp.Services;
|
||||
|
||||
using LaDOSE.DesktopApp.ViewModels;
|
||||
using LaDOSE.REST;
|
||||
|
||||
namespace LaDOSE.DesktopApp
|
||||
{
|
||||
@@ -18,14 +20,19 @@ namespace LaDOSE.DesktopApp
|
||||
|
||||
protected override void Configure()
|
||||
{
|
||||
|
||||
container = new SimpleContainer();
|
||||
|
||||
container.Singleton<IWindowManager, WindowManager>();
|
||||
container.Singleton<RestService>();
|
||||
|
||||
container.PerRequest<ShellViewModel>();
|
||||
container.Singleton<RestService>();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
DisplayRootViewFor<ShellViewModel>();
|
||||
@@ -44,6 +51,7 @@ namespace LaDOSE.DesktopApp
|
||||
protected override void BuildUp(object instance)
|
||||
{
|
||||
container.BuildUp(instance);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,8 @@
|
||||
<Reference Include="Caliburn.Micro.Platform.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RestSharp, Version=106.6.5.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\RestSharp.106.6.5\lib\net452\RestSharp.dll</HintPath>
|
||||
<Reference Include="RestSharp, Version=106.6.9.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\RestSharp.106.6.9\lib\net452\RestSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
@@ -99,12 +99,12 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Behaviors\TextBoxInputRegExBehaviour.cs" />
|
||||
<Compile Include="Behaviors\MultiSelectorBehaviours.cs" />
|
||||
<Compile Include="Bootstrapper.cs" />
|
||||
<Compile Include="Themes\LeftMarginMultiplierConverter.cs" />
|
||||
<Compile Include="Themes\TreeViewItemExtensions.cs" />
|
||||
<Compile Include="Utils\PhpSerialize.cs" />
|
||||
<Compile Include="Services\RestService.cs" />
|
||||
<Compile Include="UserControls\BookingUserControl.xaml.cs">
|
||||
<DependentUpon>BookingUserControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -189,6 +189,10 @@
|
||||
<Project>{61201da6-1bc9-4ba1-ac45-70104d391ecd}</Project>
|
||||
<Name>LaDOSE.DTO</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\LaDOSE.REST\LaDOSE.REST.csproj">
|
||||
<Project>{692c2a72-ab7e-4502-bed8-aa2afa1761cb}</Project>
|
||||
<Name>LaDOSE.REST</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="64x64.ico" />
|
||||
@@ -208,5 +212,8 @@
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,7 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Caliburn.Micro;
|
||||
using LaDOSE.DesktopApp.Services;
|
||||
using LaDOSE.DTO;
|
||||
using LaDOSE.REST;
|
||||
|
||||
namespace LaDOSE.DesktopApp.ViewModels
|
||||
{
|
||||
@@ -22,13 +23,14 @@ namespace LaDOSE.DesktopApp.ViewModels
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
LoadGames();
|
||||
this.CurrentGame = Games.First();
|
||||
base.OnInitialize();
|
||||
}
|
||||
|
||||
public void LoadGames()
|
||||
{
|
||||
this.Games.Clear();
|
||||
this.Games = this.RestService.GetGames();
|
||||
var gameDtos = this.RestService.GetGames().OrderBy(e=>e.Order).ToList();
|
||||
this.Games = gameDtos;
|
||||
NotifyOfPropertyChange("Games");
|
||||
}
|
||||
|
||||
@@ -56,7 +58,8 @@ namespace LaDOSE.DesktopApp.ViewModels
|
||||
public void Update()
|
||||
{
|
||||
this.RestService.UpdateGame(this.CurrentGame);
|
||||
this.Games = RestService.GetGames();
|
||||
LoadGames();
|
||||
|
||||
}
|
||||
public void AddGame()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Caliburn.Micro;
|
||||
using LaDOSE.DesktopApp.Services;
|
||||
using LaDOSE.REST;
|
||||
|
||||
namespace LaDOSE.DesktopApp.ViewModels
|
||||
{
|
||||
@@ -15,6 +16,16 @@ namespace LaDOSE.DesktopApp.ViewModels
|
||||
this.DisplayName = "LaDOSE";
|
||||
this.AppIcon = BitmapFrame.Create(Application.GetResourceStream(new Uri("/LaDOSE.DesktopApp;component/Resources/64x64.png",
|
||||
UriKind.RelativeOrAbsolute)).Stream);
|
||||
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
string url = (string)appSettings["ApiUri"];
|
||||
string user = (string)appSettings["ApiUser"];
|
||||
string password = (string)appSettings["ApiPassword"];
|
||||
Uri uri = new Uri(url);
|
||||
var restService = IoC.Get<RestService>();
|
||||
|
||||
restService.Connect(uri, user, password);
|
||||
|
||||
var wordPressViewModel = new WordPressViewModel(IoC.Get<RestService>());
|
||||
ActivateItem(wordPressViewModel);
|
||||
base.OnInitialize();
|
||||
|
||||
@@ -8,9 +8,9 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using Caliburn.Micro;
|
||||
using LaDOSE.DesktopApp.Services;
|
||||
using LaDOSE.DesktopApp.Utils;
|
||||
using LaDOSE.DTO;
|
||||
using LaDOSE.REST;
|
||||
using Action = System.Action;
|
||||
|
||||
namespace LaDOSE.DesktopApp.ViewModels
|
||||
@@ -169,7 +169,7 @@ namespace LaDOSE.DesktopApp.ViewModels
|
||||
var reservation = SelectedWpEvent.WpBookings.FirstOrDefault();
|
||||
var games = WpEventDeserialize.Parse(reservation.Meta);
|
||||
GamesFound.Clear();
|
||||
|
||||
var foundGames = new List<GameDTO>();
|
||||
if (games != null)
|
||||
{
|
||||
foreach (string wpTag in games.Select(e => e.Name))
|
||||
@@ -178,14 +178,20 @@ namespace LaDOSE.DesktopApp.ViewModels
|
||||
e.WordPressTag != null && e.WordPressTag.Split(';').Contains(wpTag));
|
||||
if (foundGame != null)
|
||||
{
|
||||
if (!GamesFound.Contains(foundGame))
|
||||
if (!foundGames.Contains(foundGame))
|
||||
{
|
||||
GamesFound.Add(foundGame);
|
||||
foundGames.Add(foundGame);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var orderedEnumerable = foundGames.OrderBy(e => e.Order);
|
||||
foreach (var gameDto in orderedEnumerable)
|
||||
{
|
||||
GamesFound.Add(gameDto);
|
||||
}
|
||||
|
||||
NotifyOfPropertyChange(() => GamesFound);
|
||||
}
|
||||
|
||||
@@ -209,8 +215,9 @@ namespace LaDOSE.DesktopApp.ViewModels
|
||||
System.Windows.Input.Mouse.OverrideCursor = Cursors.Wait);
|
||||
GamesFound = new ObservableCollection<GameDTO>();
|
||||
this.Games = this.RestService.GetGames();
|
||||
this.Events = this.RestService.GetEvents();
|
||||
|
||||
var events = this.RestService.GetEvents();
|
||||
events.ForEach(e => e.WpBookings = e.WpBookings.OrderBy(x => x.WpUser.Name).ToList());
|
||||
this.Events = events;
|
||||
NotifyOfPropertyChange("Events");
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
System.Windows.Input.Mouse.OverrideCursor = null);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
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:behaviors="clr-namespace:LaDOSE.DesktopApp.Behaviors"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid Row="4" Column="1">
|
||||
@@ -19,7 +21,7 @@
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="{Binding Id}"></Label>
|
||||
<Label Content="{Binding Order}"></Label>
|
||||
<Label> - </Label>
|
||||
<Label Content="{Binding Name}"></Label>
|
||||
</StackPanel>
|
||||
@@ -37,6 +39,7 @@
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
@@ -51,11 +54,20 @@
|
||||
<Label Grid.Row="2" Grid.Column="0">Name</Label>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=CurrentGame.Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ></TextBox>
|
||||
|
||||
<Label Grid.Row="3" Grid.Column="0">WpTag</Label>
|
||||
<TextBox Grid.Row="4" Grid.ColumnSpan="2" Text="{Binding Path=CurrentGame.WordPressTag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ></TextBox>
|
||||
<Label Grid.Row="5" Grid.Column="0">WpTagOs</Label>
|
||||
<TextBox Grid.Row="6" Grid.ColumnSpan="2" Text="{Binding Path=CurrentGame.WordPressTagOs,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ></TextBox>
|
||||
<Button Grid.Row="7" Grid.ColumnSpan="2" x:Name="Update">Update</Button>
|
||||
<Label Grid.Row="3" Grid.Column="0">Order</Label>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=CurrentGame.Order,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
|
||||
<i:Interaction.Behaviors>
|
||||
<behaviors:TextBoxInputRegExBehaviour RegularExpression="^\d+$" MaxLength="9" EmptyValue="0">
|
||||
|
||||
</behaviors:TextBoxInputRegExBehaviour>
|
||||
</i:Interaction.Behaviors>
|
||||
</TextBox>
|
||||
|
||||
<Label Grid.Row="4" Grid.Column="0">WpTag</Label>
|
||||
<TextBox Grid.Row="5" Grid.ColumnSpan="2" Text="{Binding Path=CurrentGame.WordPressTag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ></TextBox>
|
||||
<Label Grid.Row="6" Grid.Column="0">WpTagOs</Label>
|
||||
<TextBox Grid.Row="7" Grid.ColumnSpan="2" Text="{Binding Path=CurrentGame.WordPressTagOs,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ></TextBox>
|
||||
<Button Grid.Row="8" Grid.ColumnSpan="2" x:Name="Update">Update</Button>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
<packages>
|
||||
<package id="Caliburn.Micro" version="3.2.0" targetFramework="net461" />
|
||||
<package id="Caliburn.Micro.Core" version="3.2.0" targetFramework="net461" />
|
||||
<package id="RestSharp" version="106.6.5" targetFramework="net461" />
|
||||
<package id="RestSharp" version="106.6.9" targetFramework="net461" />
|
||||
<package id="WPFThemes.DarkBlend" version="1.0.8" targetFramework="net461" />
|
||||
</packages>
|
||||
@@ -4,10 +4,10 @@ using DSharpPlus.CommandsNext.Attributes;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
|
||||
internal class Result
|
||||
{
|
||||
Dependencies dep;
|
||||
|
||||
public Result(Dependencies d)
|
||||
{
|
||||
this.dep = d;
|
||||
@@ -20,7 +20,6 @@ namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
var tournament = await dep.ChallongeService.GetLastTournament();
|
||||
await ctx.RespondAsync($"Mise à jour effectuée");
|
||||
|
||||
}
|
||||
|
||||
[Command("last")]
|
||||
@@ -28,8 +27,27 @@ namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
var lastTournamentMessage = dep.ChallongeService.GetLastTournamentMessage();
|
||||
await ctx.RespondAsync(lastTournamentMessage);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[RequireRolesAttribute("Staff")]
|
||||
[Command("inscriptions")]
|
||||
public async Task InscriptionsAsync(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
var inscrits = dep.WebService.GetInscrits();
|
||||
await ctx.RespondAsync(inscrits);
|
||||
}
|
||||
|
||||
[RequireRolesAttribute("Staff")]
|
||||
[Command("UpdateDb")]
|
||||
public async Task UpdateDbAsync(CommandContext ctx)
|
||||
{
|
||||
await ctx.RespondAsync("Mise à jour des inscriptions en cours...");
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
var status = dep.WebService.RefreshDb() ? "Ok" : "erreur";
|
||||
|
||||
await ctx.RespondAsync($"Status: {status}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,6 @@ namespace LaDOSE.DiscordBot
|
||||
internal CancellationTokenSource Cts { get; set; }
|
||||
public ChallongeService ChallongeService { get; set; }
|
||||
public TodoService TodoService { get; set; }
|
||||
|
||||
public WebService WebService { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,10 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LaDOSE.REST\LaDOSE.REST.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="ChallongeCSharpDriver">
|
||||
<HintPath>..\..\Library\ChallongeCSharpDriver.dll</HintPath>
|
||||
|
||||
@@ -31,7 +31,9 @@ namespace LaDOSE.DiscordBot
|
||||
|
||||
var discordToken = builder["Discord:Token"].ToString();
|
||||
var challongeToken = builder["Challonge:Token"].ToString();
|
||||
|
||||
var restUrl = builder["REST:Url"].ToString();
|
||||
var restUser = builder["REST:User"].ToString();
|
||||
var restPassword = builder["REST:Password"].ToString();
|
||||
|
||||
Console.WriteLine($"LaDOSE.Net Discord Bot");
|
||||
|
||||
@@ -42,7 +44,7 @@ namespace LaDOSE.DiscordBot
|
||||
TokenType = TokenType.Bot
|
||||
});
|
||||
|
||||
|
||||
var webService = new WebService(new Uri(restUrl),restUser,restPassword);
|
||||
var challongeService = new ChallongeService(challongeToken);
|
||||
var todoService = new TodoService();
|
||||
var cts = new CancellationTokenSource();
|
||||
@@ -56,6 +58,7 @@ namespace LaDOSE.DiscordBot
|
||||
Cts = cts,
|
||||
ChallongeService = challongeService,
|
||||
TodoService = todoService,
|
||||
WebService = webService
|
||||
});
|
||||
dep = d.Build();
|
||||
}
|
||||
|
||||
41
LaDOSE.Src/LaDOSE.DiscordBot/Service/WebService.cs
Normal file
41
LaDOSE.Src/LaDOSE.DiscordBot/Service/WebService.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ChallongeCSharpDriver;
|
||||
using ChallongeCSharpDriver.Caller;
|
||||
using ChallongeCSharpDriver.Core.Queries;
|
||||
using ChallongeCSharpDriver.Core.Results;
|
||||
using ChallongeCSharpDriver.Main;
|
||||
using ChallongeCSharpDriver.Main.Objects;
|
||||
using LaDOSE.DTO;
|
||||
using LaDOSE.REST;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Service
|
||||
{
|
||||
public class WebService
|
||||
{
|
||||
private RestService restService;
|
||||
|
||||
public WebService(Uri uri,string user,string password)
|
||||
{
|
||||
restService = new RestService();
|
||||
restService.Connect(uri,user,password);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String GetInscrits()
|
||||
{
|
||||
var wpEventDto = restService.GetNextEvent();
|
||||
var wpBookingDtos = wpEventDto.WpBookings;
|
||||
List<String> player= new List<string>();
|
||||
wpBookingDtos.OrderBy(e=>e.WpUser.Name).ToList().ForEach(e=> player.Add(e.WpUser.Name));
|
||||
return $"Les Joueurs inscrits pour {wpEventDto.Name} {string.Join(", ", player)}";
|
||||
}
|
||||
public bool RefreshDb()
|
||||
{
|
||||
return restService.RefreshDb();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace LaDOSE.Entity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string ImgUrl { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string WordPressTag { get; set; }
|
||||
public string WordPressTagOs { get; set; }
|
||||
public virtual IEnumerable<SeasonGame> Seasons { get; set; }
|
||||
|
||||
15
LaDOSE.Src/LaDOSE.REST/LaDOSE.REST.csproj
Normal file
15
LaDOSE.Src/LaDOSE.REST/LaDOSE.REST.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RestSharp" Version="106.6.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LaDOSE.DTO\LaDOSE.DTO.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,29 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Configuration;
|
||||
using System.Windows;
|
||||
using LaDOSE.DTO;
|
||||
using RestSharp;
|
||||
using RestSharp.Authenticators;
|
||||
using RestSharp.Serialization.Json;
|
||||
using DataFormat = RestSharp.DataFormat;
|
||||
|
||||
namespace LaDOSE.DesktopApp.Services
|
||||
namespace LaDOSE.REST
|
||||
{
|
||||
public class RestService
|
||||
{
|
||||
|
||||
public RestClient Client { get; set; }
|
||||
|
||||
public RestService()
|
||||
public RestService() { }
|
||||
|
||||
|
||||
public void Connect(Uri url, string user, string password)
|
||||
{
|
||||
#if DEBUG
|
||||
MessageBox.Show("WAIT");
|
||||
#endif
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
string url = (string) appSettings["ApiUri"];
|
||||
string user = (string)appSettings["ApiUser"];
|
||||
string password = (string) appSettings["ApiPassword"];
|
||||
Client = new RestClient(url);
|
||||
var restRequest = new RestRequest("users/auth", Method.POST);
|
||||
restRequest.AddJsonBody(new {username = user, password = password});
|
||||
@@ -36,8 +29,7 @@ namespace LaDOSE.DesktopApp.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Unable to contact services, i m useless, BYEKTHX","Error",MessageBoxButton.OK,MessageBoxImage.Error);
|
||||
Application.Current.Shutdown(-1);
|
||||
throw new Exception("unable to contact services");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +95,12 @@ namespace LaDOSE.DesktopApp.Services
|
||||
var restResponse = Client.Get<List<WPEventDTO>>(restRequest);
|
||||
return restResponse.Data;
|
||||
}
|
||||
public WPEventDTO GetNextEvent()
|
||||
{
|
||||
var restRequest = new RestRequest("/api/wordpress/NextEvent", Method.GET);
|
||||
var restResponse = Client.Get<WPEventDTO>(restRequest);
|
||||
return restResponse.Data;
|
||||
}
|
||||
|
||||
|
||||
public string CreateChallonge(int gameId, int eventId)
|
||||
@@ -6,6 +6,7 @@ namespace LaDOSE.Business.Interface
|
||||
{
|
||||
public interface IWordPressService
|
||||
{
|
||||
WPEvent GetNextWpEvent();
|
||||
List<WPEvent> GetWpEvent();
|
||||
List<WPUser> GetBooking(int wpEventId, Game game);
|
||||
List<WPUser> GetBookingOptions(int wpEventId, Game game);
|
||||
|
||||
@@ -15,11 +15,25 @@ namespace LaDOSE.Business.Service
|
||||
{
|
||||
}
|
||||
|
||||
public override Game AddOrUpdate(Game entity)
|
||||
{
|
||||
if (entity.Order == 0)
|
||||
{
|
||||
entity.Order = GetNextFreeOrder();
|
||||
}
|
||||
|
||||
return base.AddOrUpdate(entity);
|
||||
}
|
||||
|
||||
public override IEnumerable<Game> GetAll()
|
||||
{
|
||||
return _context.Game.Include(e => e.Seasons).ThenInclude(e=>e.Season).ToList();
|
||||
}
|
||||
|
||||
|
||||
public int GetNextFreeOrder()
|
||||
{
|
||||
int nextFreeOrder = _context.Game.Max(e => e.Order);
|
||||
return ++nextFreeOrder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,12 @@ namespace LaDOSE.Business.Service
|
||||
.ThenInclude(e => e.WPUser).Where(e => e.WPBookings.Count() != 0).Take(10).ToList();
|
||||
return wpEvents;
|
||||
}
|
||||
public WPEvent GetNextWpEvent()
|
||||
{
|
||||
var wpEvents = _context.Set<WPEvent>().OrderByDescending(e=>e.Date).ThenByDescending(e => e.Id)
|
||||
.Include(e => e.WPBookings).ThenInclude(e => e.WPUser).FirstOrDefault(e => Enumerable.Count<WPBooking>(e.WPBookings) != 0);
|
||||
return wpEvents;
|
||||
}
|
||||
|
||||
public bool UpdateBooking()
|
||||
{
|
||||
|
||||
@@ -23,6 +23,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bot", "Bot", "{8B9C38FB-2A8
|
||||
EndProject
|
||||
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup", "Setup\Setup.vdproj", "{6825F5F4-EBB5-469F-B935-5B916EA37ACC}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utils", "Utils", "{2A0E1491-8E15-4062-ABE7-C04AE9655515}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaDOSE.REST", "LaDOSE.REST\LaDOSE.REST.csproj", "{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -55,6 +59,10 @@ Global
|
||||
{61201DA6-1BC9-4BA1-AC45-70104D391ECD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6825F5F4-EBB5-469F-B935-5B916EA37ACC}.Debug|Any CPU.ActiveCfg = Debug
|
||||
{6825F5F4-EBB5-469F-B935-5B916EA37ACC}.Release|Any CPU.ActiveCfg = Release
|
||||
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -67,6 +75,7 @@ Global
|
||||
{A76AC851-4D43-4BF9-9034-F496888ADAFD} = {DD52FE00-B822-4DE3-B369-2BFB5F808130}
|
||||
{61201DA6-1BC9-4BA1-AC45-70104D391ECD} = {6FC9438E-D93E-4E63-9342-F8A966EE2D06}
|
||||
{6825F5F4-EBB5-469F-B935-5B916EA37ACC} = {DD52FE00-B822-4DE3-B369-2BFB5F808130}
|
||||
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB} = {2A0E1491-8E15-4062-ABE7-C04AE9655515}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D47DEDD0-C906-439D-81E4-D86BBE723B8C}
|
||||
|
||||
Reference in New Issue
Block a user