-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ProfileCreator interface, validator, some services and all …
…that
- Loading branch information
Showing
12 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace SightKeeper.Application; | ||
|
||
public interface NewProfileData : ProfileData | ||
{ | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
SightKeeper.Application/Profile/Creating/NewProfileDataDTO.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Immutable; | ||
using SightKeeper.Domain.Model; | ||
using SightKeeper.Domain.Model.Common; | ||
|
||
namespace SightKeeper.Application; | ||
|
||
public sealed class NewProfileDataDTO : NewProfileData | ||
{ | ||
public string Name { get; } | ||
public string Description { get; } | ||
public float DetectionThreshold { get; } | ||
public float MouseSensitivity { get; } | ||
public Weights Weights { get; } | ||
public IReadOnlyList<ItemClass> ItemClasses { get; } | ||
|
||
public NewProfileDataDTO(string name, string description, float detectionThreshold, float mouseSensitivity, Weights weights, IEnumerable<ItemClass> itemClasses) | ||
{ | ||
Name = name; | ||
Description = description; | ||
DetectionThreshold = detectionThreshold; | ||
MouseSensitivity = mouseSensitivity; | ||
Weights = weights; | ||
ItemClasses = itemClasses.ToImmutableList(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
SightKeeper.Application/Profile/Creating/NewProfileDataValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using FluentValidation; | ||
using SightKeeper.Domain.Services; | ||
|
||
namespace SightKeeper.Application; | ||
|
||
public sealed class NewProfileDataValidator : AbstractValidator<NewProfileData> | ||
{ | ||
private readonly ProfilesDataAccess _profilesDataAccess; | ||
|
||
public NewProfileDataValidator(IValidator<ProfileData> profileDataValidator, ProfilesDataAccess profilesDataAccess) | ||
{ | ||
_profilesDataAccess = profilesDataAccess; | ||
Include(profileDataValidator); | ||
RuleFor(data => data.Name) | ||
.MustAsync(NameIsUnique); | ||
} | ||
|
||
private async Task<bool> NameIsUnique(string name, CancellationToken cancellationToken) | ||
{ | ||
var profiles = await _profilesDataAccess.LoadAllProfiles(cancellationToken); | ||
return profiles.All(profile => profile.Name != name); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
SightKeeper.Application/Profile/Creating/ProfileCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using FluentValidation; | ||
using SightKeeper.Domain.Model; | ||
using SightKeeper.Domain.Services; | ||
|
||
namespace SightKeeper.Application; | ||
|
||
public sealed class ProfileCreator | ||
{ | ||
public ProfileCreator(IValidator<NewProfileData> validator, ProfilesDataAccess profilesDataAccess) | ||
{ | ||
_validator = validator; | ||
_profilesDataAccess = profilesDataAccess; | ||
} | ||
|
||
public async Task<Profile> CreateProfile(NewProfileDataDTO data) | ||
{ | ||
await _validator.ValidateAndThrowAsync(data); | ||
Profile profile = new(data.Name, data.Description, data.DetectionThreshold, data.MouseSensitivity, data.Weights); | ||
foreach (var itemClass in data.ItemClasses) | ||
profile.AddItemClass(itemClass); | ||
await _profilesDataAccess.AddProfile(profile); | ||
return profile; | ||
} | ||
|
||
private readonly IValidator<NewProfileData> _validator; | ||
private readonly ProfilesDataAccess _profilesDataAccess; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using SightKeeper.Domain.Model; | ||
using SightKeeper.Domain.Model.Common; | ||
|
||
namespace SightKeeper.Application; | ||
|
||
public interface ProfileData | ||
{ | ||
string Name { get; } | ||
string Description { get; } | ||
float DetectionThreshold { get; } | ||
float MouseSensitivity { get; } | ||
Weights? Weights { get; } | ||
IReadOnlyList<ItemClass> ItemClasses { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using FluentValidation; | ||
using SightKeeper.Commons.Validation; | ||
|
||
namespace SightKeeper.Application; | ||
|
||
public sealed class ProfileDataValidator : AbstractValidator<ProfileData> | ||
{ | ||
public ProfileDataValidator() | ||
{ | ||
RuleFor(data => data.Name) | ||
.NotEmpty(); | ||
RuleFor(data => data.DetectionThreshold) | ||
.ExclusiveBetween(0, 1); | ||
RuleFor(data => data.MouseSensitivity) | ||
.GreaterThan(0); | ||
RuleFor(data => data.Weights) | ||
.NotNull(); | ||
RuleForEach(data => data.ItemClasses) | ||
.Must((data, profileItemClass) => profileItemClass.DataSet == data.Weights!.Library.DataSet) | ||
.When(data => data.Weights != null); | ||
RuleFor(data => data.ItemClasses).NoDuplicates(); | ||
} | ||
} |
7 changes: 6 additions & 1 deletion
7
SightKeeper.Application/SightKeeper.Application.csproj.DotSettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:s="clr-namespace:System;assembly=mscorlib" | ||
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=profile/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=profile_005Ccreating/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=profile_005Cediting/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=training_005Cclassifier/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=training_005Cdetector/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:s="clr-namespace:System;assembly=mscorlib" | ||
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cprofile/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters