Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Table layout #72

Merged
merged 33 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b9f26a8
refactor: removed completion date from AssignmentProgress.cs
ronimizy Nov 27, 2021
988576d
feat: indices
ronimizy Nov 27, 2021
8f3e7da
chore: table models
ronimizy Nov 27, 2021
812e5fe
feat: table layout components base
ronimizy Nov 27, 2021
53c5108
feat: table layout
ronimizy Nov 27, 2021
4bfaae0
chore: misc
ronimizy Nov 27, 2021
664d384
chore: added stylecop to SeaInk.Application.csproj
ronimizy Nov 27, 2021
bdce64a
chore: table layout sample
ronimizy Nov 27, 2021
3ae12db
refactor: resolver exception code smells
ronimizy Nov 27, 2021
e533d96
refactor: resolver ITableEditor smell
ronimizy Nov 27, 2021
f84146e
resolved: LockedTableIndex smells
ronimizy Nov 27, 2021
0c36d99
refactor: resolved naming smell
ronimizy Nov 27, 2021
db4ce67
refactor: removed visitors
ronimizy Nov 28, 2021
1487de5
refactor: components
ronimizy Nov 28, 2021
56c6d80
feat: commands
ronimizy Nov 28, 2021
3d52140
refactor: indices
ronimizy Nov 28, 2021
586e4ca
refactor: TableLayoutComponent
ronimizy Nov 28, 2021
29eca2d
refactor: misc
ronimizy Nov 28, 2021
b30901f
refactor: sample
ronimizy Nov 28, 2021
b8c8d1f
fix: object.Equals bug
ronimizy Nov 28, 2021
c60ac80
fix: exception serialization smell
ronimizy Nov 28, 2021
5f3bd61
fix: object.Equals bugs
ronimizy Nov 28, 2021
d924542
refactor: made all equals overloads adjacent
ronimizy Nov 28, 2021
a62a7a0
refactor: composite component command execution order
ronimizy Nov 29, 2021
4ad0081
refactor: drawing commands
ronimizy Nov 29, 2021
c101e75
Update Source/SeaInk.Application/TableLayout/Components/PlainAssignme…
ronimizy Dec 1, 2021
35fd1b1
fix: MergeScanningIndex.ToString
ronimizy Dec 1, 2021
6a7dac7
refactor: returning IReadOnlyCollections with .AsReadOnly
ronimizy Dec 1, 2021
d9ec6cf
refactor: updated sample
ronimizy Dec 1, 2021
9013ef9
refactor: renamed ITableIndex Move methods parameter
ronimizy Dec 1, 2021
3099970
refactor: removed redundant variance in command interfaces
ronimizy Dec 1, 2021
233a761
feat: added fluent results
ronimizy Dec 3, 2021
b10cd30
removed: redundant sample project
ronimizy Dec 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Source/SeaInk.Application/Exceptions/CrossedFrameException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Runtime.Serialization;
using SeaInk.Application.TableLayout.Indices;
using SeaInk.Application.TableLayout.Models;
using SeaInk.Core.Exceptions;

namespace SeaInk.Application.Exceptions
{
[Serializable]
ronimizy marked this conversation as resolved.
Show resolved Hide resolved
public class CrossedFrameException : SeaInkException
{
public CrossedFrameException(ITableIndex begin, ITableIndex current, Frame frame)
: base($"Index {current} should be in frame {frame} starting at {begin}") { }

protected CrossedFrameException(SerializationInfo info, StreamingContext context)
ronimizy marked this conversation as resolved.
Show resolved Hide resolved
: base(info, context) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Runtime.Serialization;
using SeaInk.Core.Exceptions;

namespace SeaInk.Application.Exceptions
{
[Serializable]
ronimizy marked this conversation as resolved.
Show resolved Hide resolved
public class InvalidScaleComponentException : SeaInkException
{
public InvalidScaleComponentException(string argName, int value)
: base($"{argName} must be positive. Value {value}") { }

protected InvalidScaleComponentException(SerializationInfo info, StreamingContext context)
ronimizy marked this conversation as resolved.
Show resolved Hide resolved
: base(info, context) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Runtime.Serialization;
using SeaInk.Application.TableLayout.Models;
using SeaInk.Core.Exceptions;

namespace SeaInk.Application.Exceptions
{
[Serializable]
ronimizy marked this conversation as resolved.
Show resolved Hide resolved
public class MissingAssignmentComponentException : SeaInkException
{
public MissingAssignmentComponentException(AssignmentModel model)
: base($"There is no component in the table that represents an assignment {model}") { }

protected MissingAssignmentComponentException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Runtime.Serialization;
using SeaInk.Core.Exceptions;

namespace SeaInk.Application.Exceptions
{
[Serializable]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не резолвь этот комент пока не поменяешь кофиг сонара

Copy link
Contributor Author

@ronimizy ronimizy Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я так понимаю, что здесь должен быть пункт Administration чтобы я смог это сделать @FrediKats

Снимок экрана 2021-12-01 в 20 57 57

public class MissingStudentComponentException : SeaInkException
{
public MissingStudentComponentException()
: base("Table does not contain a component that represents student") { }

protected MissingStudentComponentException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
}
14 changes: 0 additions & 14 deletions Source/SeaInk.Application/Results/Failure.cs

This file was deleted.

4 changes: 0 additions & 4 deletions Source/SeaInk.Application/Results/IResult.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Source/SeaInk.Application/Results/Success.cs

This file was deleted.

21 changes: 20 additions & 1 deletion Source/SeaInk.Application/SeaInk.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningLevel>5</WarningLevel>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<EditorConfigFiles Remove="..\.editorconfig" />
</ItemGroup>
ronimizy marked this conversation as resolved.
Show resolved Hide resolved

<ItemGroup>
<PackageReference Include="FluentResults" Version="3.1.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Content Include="..\..\.editorconfig">
<Link>.editorconfig</Link>
</Content>
</ItemGroup>
ronimizy marked this conversation as resolved.
Show resolved Hide resolved

<ItemGroup>
<ProjectReference Include="..\SeaInk.Core\SeaInk.Core.csproj" />
<ProjectReference Include="..\SeaInk.Utility\SeaInk.Utility.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SeaInk.Application.TableLayout.Indices;

namespace SeaInk.Application.TableLayout.CommandInterfaces
{
public interface IDrawableLayoutComponent
{
void Draw(ITableIndex begin, ITableEditor editor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using FluentResults;
using SeaInk.Application.TableLayout.ComponentsBase;
using SeaInk.Application.TableLayout.Indices;

namespace SeaInk.Application.TableLayout.CommandInterfaces
{
public interface IExpandableLayoutComponent<in TComponent>
where TComponent : LayoutComponent
{
Result AddComponent(TComponent component, IScaledTableIndex begin, ITableEditor editor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using FluentResults;
using SeaInk.Application.TableLayout.ComponentsBase;
using SeaInk.Application.TableLayout.Indices;

namespace SeaInk.Application.TableLayout.CommandInterfaces
{
public interface IReducibleLayoutComponent<in TComponent>
where TComponent : LayoutComponent
{
Result RemoveComponent(TComponent component, IScaledTableIndex begin, ITableEditor editor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SeaInk.Application.TableLayout.Indices;

namespace SeaInk.Application.TableLayout.CommandInterfaces
{
public interface IRemovableComponent
{
void Remove(ITableIndex begin, ITableEditor editor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SeaInk.Application.TableLayout.Indices;

namespace SeaInk.Application.TableLayout.CommandInterfaces
{
public interface IValueGettingLayoutComponent<T>
{
T GetValue(ITableIndex begin, ITableDataProvider provider);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SeaInk.Application.TableLayout.CommandInterfaces
{
public interface IValueRepresentingLayoutComponent<T>
{
T Value { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SeaInk.Application.TableLayout.Indices;

namespace SeaInk.Application.TableLayout.CommandInterfaces
{
public interface IValueSettingLayoutComponent<T>
{
void SetValue(T value, ITableIndex begin, ITableEditor editor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Linq;
using FluentResults;
using SeaInk.Application.TableLayout.CommandsBase;
using SeaInk.Application.TableLayout.ComponentsBase;
using SeaInk.Application.TableLayout.Indices;
using SeaInk.Application.TableLayout.Successes;
using SeaInk.Utility.Extensions;

namespace SeaInk.Application.TableLayout.Commands
{
public class AggregateValuesCommand<T> : ILayoutCommand
{
private readonly List<T> _values = new List<T>();
private readonly ITableDataProvider _provider;
private readonly List<LayoutComponent> _visitedComponents = new List<LayoutComponent>();

public AggregateValuesCommand(ITableDataProvider provider)
{
_provider = provider;
}

public IReadOnlyCollection<T> Values => _values.AsReadOnly();

public Result Execute(LayoutComponent target, ITableIndex begin, ITableEditor? editor)
{
var command = new GetValueCommand<T>(_provider);
Result result = target.ExecuteCommand(new ComponentIgnoringCommand(command, _visitedComponents), begin, editor);

while (result.IsSuccess)
{
_values.Add(command.Value.ThrowIfNull(nameof(command.Value)));
var success = (SuccessComponent)result.Successes.Single();
_visitedComponents.Add(success.Component);

result = target.ExecuteCommand(new ComponentIgnoringCommand(command, _visitedComponents), begin, editor);
}

return Result.Ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Linq;
using FluentResults;
using SeaInk.Application.TableLayout.CommandsBase;
using SeaInk.Application.TableLayout.ComponentsBase;
using SeaInk.Application.TableLayout.Errors;
using SeaInk.Application.TableLayout.Indices;
using SeaInk.Application.TableLayout.Successes;

namespace SeaInk.Application.TableLayout.Commands
{
public class ComponentIgnoringCommand : ILayoutCommand
{
private readonly ILayoutCommand _command;
private readonly IReadOnlyCollection<LayoutComponent> _ignored;

public ComponentIgnoringCommand(ILayoutCommand command, IReadOnlyCollection<LayoutComponent> ignored)
{
_command = command;
_ignored = ignored.ToList();
}

public Result Execute(LayoutComponent target, ITableIndex begin, ITableEditor? editor)
{
if (_ignored.Contains(target))
return Result.Fail(new ComponentShouldBeIgnoredError(target));

Result result = target.ExecuteCommand(_command, begin, editor);

return result.IsSuccess ? result.WithSuccess(new SuccessComponent(target)) : result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FluentResults;
using SeaInk.Application.TableLayout.CommandInterfaces;
using SeaInk.Application.TableLayout.CommandsBase;
using SeaInk.Application.TableLayout.Errors;
using SeaInk.Application.TableLayout.Indices;
using SeaInk.Utility.Extensions;

namespace SeaInk.Application.TableLayout.Commands
{
public class ComponentRemoveCommand : GenericLayoutCommand<IRemovableComponent>
{
private readonly IRemovableComponent _component;

public ComponentRemoveCommand(IRemovableComponent component)
{
_component = component.ThrowIfNull(nameof(component));
}

protected override Result Execute(IRemovableComponent target, ITableIndex begin, ITableEditor? editor)
{
if (!target.Equals(_component))
return Result.Fail(new InvalidComponentError<IRemovableComponent>(_component, target));

target.Remove(begin, editor.ThrowIfNull(nameof(editor)));
return Result.Ok();
}
}
}
30 changes: 30 additions & 0 deletions Source/SeaInk.Application/TableLayout/Commands/DrawAllCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Linq;
using FluentResults;
using SeaInk.Application.TableLayout.CommandsBase;
using SeaInk.Application.TableLayout.ComponentsBase;
using SeaInk.Application.TableLayout.Indices;
using SeaInk.Application.TableLayout.Successes;

namespace SeaInk.Application.TableLayout.Commands
{
public class DrawAllCommand : ILayoutCommand
{
private readonly List<LayoutComponent> _visitedComponents = new List<LayoutComponent>();

public Result Execute(LayoutComponent target, ITableIndex begin, ITableEditor? editor)
{
var command = new DrawComponentCommand();
Result result = target.ExecuteCommand(new ComponentIgnoringCommand(command, _visitedComponents), begin, editor);

while (result.IsSuccess)
{
var success = (SuccessComponent)result.Successes.Single();
_visitedComponents.Add(success.Component);
result = target.ExecuteCommand(new ComponentIgnoringCommand(command, _visitedComponents), begin, editor);
}

return Result.Ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentResults;
using SeaInk.Application.TableLayout.CommandInterfaces;
using SeaInk.Application.TableLayout.CommandsBase;
using SeaInk.Application.TableLayout.Indices;
using SeaInk.Utility.Extensions;

namespace SeaInk.Application.TableLayout.Commands
{
public class DrawComponentCommand : GenericLayoutCommand<IDrawableLayoutComponent>
{
protected override Result Execute(IDrawableLayoutComponent target, ITableIndex begin, ITableEditor? editor)
{
var index = new MergeScanningIndex(begin.Copy(), editor.ThrowIfNull(nameof(editor)));
target.Draw(index, editor!);
return Result.Ok();
}
}
}
Loading