Третий этап
This commit is contained in:
parent
1dda5914de
commit
8b8c908d41
@ -7,6 +7,7 @@ using System.Runtime.Serialization;
|
|||||||
|
|
||||||
namespace Sailboat.Exceptions
|
namespace Sailboat.Exceptions
|
||||||
{
|
{
|
||||||
|
[Serializable]
|
||||||
internal class BoatNotFoundException : ApplicationException
|
internal class BoatNotFoundException : ApplicationException
|
||||||
{
|
{
|
||||||
public BoatNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
public BoatNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
@ -79,8 +79,8 @@ namespace Sailboat.Generics
|
|||||||
T? obj = collect._collection[pos];
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
collect._collection.Remove(pos);
|
|
||||||
}
|
}
|
||||||
|
collect._collection.Remove(pos);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Sailboat.DrawingObjects;
|
using Sailboat.DrawingObjects;
|
||||||
using Sailboat.MovementStrategy;
|
using Sailboat.MovementStrategy;
|
||||||
|
|
||||||
@ -119,7 +118,7 @@ namespace Sailboat.Generics
|
|||||||
}
|
}
|
||||||
using (StreamWriter writer = new StreamWriter(filename))
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
{
|
{
|
||||||
writer.Write($"PlaneStorage{Environment.NewLine}{data}");
|
writer.Write($"SailboatStorage{Environment.NewLine}{data}");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -165,20 +164,20 @@ namespace Sailboat.Generics
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
||||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string elem in set)
|
foreach (string elem in set)
|
||||||
{
|
|
||||||
DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
|
||||||
if (boat != null)
|
|
||||||
{
|
{
|
||||||
if (!(collection + boat))
|
DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (boat != null)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка добавления в коллекцию");
|
if (!(collection + boat))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка добавления в коллекцию");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
_boatStorages.Add(record[0], collection);
|
||||||
_boatStorages.Add(record[0], collection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Sailboat
|
namespace Sailboat
|
||||||
{
|
{
|
||||||
@ -25,7 +29,7 @@ namespace Sailboat
|
|||||||
|
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
{
|
{
|
||||||
object value = services.AddSingleton<FormBoatCollection>().AddLogging(option =>
|
services.AddSingleton<FormBoatCollection>().AddLogging(option =>
|
||||||
{
|
{
|
||||||
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||||
string pathNeed = "";
|
string pathNeed = "";
|
||||||
@ -38,6 +42,7 @@ namespace Sailboat
|
|||||||
|
|
||||||
option.SetMinimumLevel(LogLevel.Information);
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
option.AddSerilog(logger);
|
option.AddSerilog(logger);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Sailboat.Exceptions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Sailboat.Generics
|
namespace Sailboat.Generics
|
||||||
{
|
{
|
||||||
@ -11,7 +13,7 @@ namespace Sailboat.Generics
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список объектов, которые храним
|
/// Список объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List <T?> _places;
|
private readonly List<T?> _places;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в массиве
|
/// Количество объектов в массиве
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -38,7 +40,7 @@ namespace Sailboat.Generics
|
|||||||
{
|
{
|
||||||
if (_places.Count == _maxCount)
|
if (_places.Count == _maxCount)
|
||||||
{
|
{
|
||||||
return false;
|
throw new StorageOverflowException(_maxCount);
|
||||||
}
|
}
|
||||||
Insert(boat, 0);
|
Insert(boat, 0);
|
||||||
return true;
|
return true;
|
||||||
@ -51,7 +53,10 @@ namespace Sailboat.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T boat, int position)
|
public bool Insert(T boat, int position)
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) {
|
if (_places.Count == _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
if (!(position >= 0 && position <= Count))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_places.Insert(position, boat);
|
_places.Insert(position, boat);
|
||||||
@ -66,7 +71,7 @@ namespace Sailboat.Generics
|
|||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
return false;
|
throw new BoatNotFoundException(position);
|
||||||
}
|
}
|
||||||
_places.RemoveAt(position);
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
@ -80,14 +85,16 @@ namespace Sailboat.Generics
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count) {
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount)) {
|
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_places.Insert(position, value);
|
_places.Insert(position, value);
|
||||||
|
@ -1,113 +1,18 @@
|
|||||||
using Sailboat.Exceptions;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Sailboat.Generics
|
namespace Sailboat.MovementStrategy
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
internal class SetGeneric<T> where T : class
|
/// Статус выполнения операции перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum Status
|
||||||
{
|
{
|
||||||
/// <summary>
|
NotInit,
|
||||||
/// Список объектов, которые храним
|
InProgress,
|
||||||
/// </summary>
|
Finish
|
||||||
private readonly List<T?> _places;
|
|
||||||
/// <summary>
|
|
||||||
/// Количество объектов в массиве
|
|
||||||
/// </summary>
|
|
||||||
public int Count => _places.Count;
|
|
||||||
/// <summary>
|
|
||||||
/// Максимальное количество объектов в списке
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _maxCount;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="count"></param>
|
|
||||||
public SetGeneric(int count)
|
|
||||||
{
|
|
||||||
_maxCount = count;
|
|
||||||
_places = new List<T?>(count);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление объекта в набор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boat">Добавляемая лодка</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Insert(T boat)
|
|
||||||
{
|
|
||||||
return Insert(boat, 0);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boat">Добавляемая лодка</param>
|
|
||||||
/// <param name="position">Позиция</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Insert(T boat, int position)
|
|
||||||
{
|
|
||||||
if (position < 0 || position >= _maxCount)
|
|
||||||
throw new BoatNotFoundException(position);
|
|
||||||
|
|
||||||
if (Count >= _maxCount)
|
|
||||||
throw new StorageOverflowException(_maxCount);
|
|
||||||
_places.Insert(0, boat);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Remove(int position)
|
|
||||||
{
|
|
||||||
if (position < 0 || position > _maxCount || position >= Count)
|
|
||||||
throw new BoatNotFoundException(position);
|
|
||||||
|
|
||||||
_places.RemoveAt(position);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Получение объекта из набора по позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public T? this[int position]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (position < 0 || position >= Count)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return _places[position];
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_places.Insert(position, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Проход по списку
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public IEnumerable<T?> GetBoats(int? maxBoats = null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _places.Count; ++i)
|
|
||||||
{
|
|
||||||
yield return _places[i];
|
|
||||||
if (maxBoats.HasValue && i == maxBoats.Value)
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user