Compare commits
86 Commits
After Width: | Height: | Size: 76 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
<html><body>
|
||||
<p>
|
||||
<hr size="1"/><address style="text-align: right;"><small>Generated on $datetime with
|
||||
<img src="CodeFirst.png" alt="Code#0" align="middle" border="0" height="40px"/>
|
||||
by Doxygen version $doxygenversion</small></address>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
After Width: | Height: | Size: 4.6 KiB |
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
throwConfigExceptions="true">
|
||||
|
||||
<targets async="true">
|
||||
<target name="logfile" xsi:type="File" fileName="log.txt" />
|
||||
<target name="logdebug" xsi:type="Debug" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="logdebug"/>
|
||||
<logger name="*" minlevel="Warn" writeTo="logfile"/>
|
||||
</rules>
|
||||
|
||||
|
||||
</nlog>
|
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Model.Dice
|
||||
{
|
||||
public class DiceGroupManager : IManager<DiceGroup>
|
||||
{
|
||||
private readonly List<DiceGroup> diceGroups = new();
|
||||
|
||||
public Task<DiceGroup> Add(DiceGroup toAdd)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(toAdd.Name))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
|
||||
|
||||
}
|
||||
if (diceGroups.Contains(toAdd))
|
||||
{
|
||||
throw new ArgumentException("this dice group already exists", nameof(toAdd));
|
||||
}
|
||||
diceGroups.Add(new(toAdd.Name.Trim(), toAdd.Dice));
|
||||
return Task.FromResult(toAdd);
|
||||
}
|
||||
|
||||
public Task<ReadOnlyCollection<DiceGroup>> GetAll()
|
||||
{
|
||||
return Task.FromResult(new ReadOnlyCollection<DiceGroup>(diceGroups));
|
||||
}
|
||||
|
||||
public Task<DiceGroup> GetOneByID(Guid ID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<DiceGroup> GetOneByName(string name)
|
||||
{
|
||||
// les groupes de dés nommés :
|
||||
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name), "param should not be null or empty");
|
||||
}
|
||||
return Task.FromResult(diceGroups.First(diceGroup => diceGroup.Name.Equals(name.Trim())));
|
||||
}
|
||||
|
||||
public void Remove(DiceGroup toRemove)
|
||||
{
|
||||
if (toRemove.Name is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(toRemove), "param should not be null");
|
||||
}
|
||||
else
|
||||
{
|
||||
diceGroups.Remove(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// updates a (string, ReadOnlyCollection-of-Die) couple. only the name can be updated
|
||||
/// </summary>
|
||||
/// <param name="before">original couple</param>
|
||||
/// <param name="after">new couple</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public Task<DiceGroup> Update(DiceGroup before, DiceGroup after)
|
||||
{
|
||||
// pas autorisé de changer les dés, juste le nom
|
||||
if (!before.Dice.SequenceEqual(after.Dice))
|
||||
{
|
||||
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(before.Name) || string.IsNullOrWhiteSpace(after.Name))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
|
||||
}
|
||||
Remove(before);
|
||||
Add(after);
|
||||
return Task.FromResult(after);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Model.Dice
|
||||
{
|
||||
public class DieManager : IManager<KeyValuePair<string, IEnumerable<Die>>>
|
||||
{
|
||||
private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new();
|
||||
|
||||
public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd)
|
||||
{
|
||||
// on trim la clé d'abord
|
||||
if (string.IsNullOrWhiteSpace(toAdd.Key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
|
||||
|
||||
}
|
||||
if (diceGroups.Contains(toAdd))
|
||||
{
|
||||
throw new ArgumentException("this username is already taken", nameof(toAdd));
|
||||
}
|
||||
diceGroups.Add(toAdd.Key.Trim(), toAdd.Value);
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll()
|
||||
{
|
||||
return diceGroups.AsEnumerable();
|
||||
}
|
||||
|
||||
public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name)
|
||||
{
|
||||
// les groupes de dés nommés :
|
||||
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name), "param should not be null or empty");
|
||||
}
|
||||
else
|
||||
{
|
||||
return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove)
|
||||
{
|
||||
if (toRemove.Key is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(toRemove), "param should not be null");
|
||||
}
|
||||
else
|
||||
{
|
||||
diceGroups.Remove(toRemove.Key);
|
||||
}
|
||||
}
|
||||
|
||||
public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after)
|
||||
{
|
||||
// pas autorisé de changer les dés, juste le nom
|
||||
if (!before.Value.Equals(after.Value))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
|
||||
}
|
||||
|
||||
diceGroups.Remove(before.Key);
|
||||
diceGroups.Add(after.Key, after.Value);
|
||||
return after;
|
||||
}
|
||||
return before;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in new issue