diff --git a/Sailboat/Sailboat/BoatNotFoundException.cs b/Sailboat/Sailboat/BoatNotFoundException.cs index f5c2284..7e56ffe 100644 --- a/Sailboat/Sailboat/BoatNotFoundException.cs +++ b/Sailboat/Sailboat/BoatNotFoundException.cs @@ -7,6 +7,7 @@ using System.Runtime.Serialization; namespace Sailboat.Exceptions { + [Serializable] internal class BoatNotFoundException : ApplicationException { public BoatNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 0634074..ec32012 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -79,8 +79,8 @@ namespace Sailboat.Generics T? obj = collect._collection[pos]; if (obj != null) { - collect._collection.Remove(pos); } + collect._collection.Remove(pos); return false; } diff --git a/Sailboat/Sailboat/BoatsGenericStorage.cs b/Sailboat/Sailboat/BoatsGenericStorage.cs index 5dfbc1d..33f26c8 100644 --- a/Sailboat/Sailboat/BoatsGenericStorage.cs +++ b/Sailboat/Sailboat/BoatsGenericStorage.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; - using Sailboat.DrawingObjects; using Sailboat.MovementStrategy; @@ -110,7 +109,7 @@ namespace Sailboat.Generics foreach (DrawingBoat? elem in record.Value.GetBoats) { records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); - } + } data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); } if (data.Length == 0) @@ -119,7 +118,7 @@ namespace Sailboat.Generics } using (StreamWriter writer = new StreamWriter(filename)) { - writer.Write($"PlaneStorage{Environment.NewLine}{data}"); + writer.Write($"SailboatStorage{Environment.NewLine}{data}"); } return true; } @@ -164,23 +163,23 @@ namespace Sailboat.Generics if (record.Length != 2) { continue; - } - BoatsGenericCollection collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) - { - DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight); - if (boat != null) + } + BoatsGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) { - 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); - } - + } } } \ No newline at end of file diff --git a/Sailboat/Sailboat/Program.cs b/Sailboat/Sailboat/Program.cs index 0470d3a..b83fd3c 100644 --- a/Sailboat/Sailboat/Program.cs +++ b/Sailboat/Sailboat/Program.cs @@ -1,5 +1,9 @@ using System; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using Serilog; namespace Sailboat { @@ -25,7 +29,7 @@ namespace Sailboat private static void ConfigureServices(ServiceCollection services) { - object value = services.AddSingleton().AddLogging(option => + services.AddSingleton().AddLogging(option => { string[] path = Directory.GetCurrentDirectory().Split('\\'); string pathNeed = ""; @@ -38,6 +42,7 @@ namespace Sailboat option.SetMinimumLevel(LogLevel.Information); option.AddSerilog(logger); + option.AddNLog("nlog.config"); }); } diff --git a/Sailboat/Sailboat/Sailboat.csproj b/Sailboat/Sailboat/Sailboat.csproj index 55a5a2f..6800c47 100644 --- a/Sailboat/Sailboat/Sailboat.csproj +++ b/Sailboat/Sailboat/Sailboat.csproj @@ -9,8 +9,14 @@ + + + + + + @@ -27,5 +33,5 @@ Resources.Designer.cs - + \ No newline at end of file diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index c5bd178..b3d3f93 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -1,8 +1,10 @@ using System; +using Sailboat.Exceptions; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace Sailboat.Generics { @@ -11,7 +13,7 @@ namespace Sailboat.Generics /// /// Список объектов, которые храним /// - private readonly List _places; + private readonly List _places; /// /// Количество объектов в массиве /// @@ -36,9 +38,9 @@ namespace Sailboat.Generics /// public bool Insert(T boat) { - if (_places.Count == _maxCount) - { - return false; + if (_places.Count == _maxCount) + { + throw new StorageOverflowException(_maxCount); } Insert(boat, 0); return true; @@ -51,9 +53,12 @@ namespace Sailboat.Generics /// public bool Insert(T boat, int position) { - if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) { - return false; - } + if (_places.Count == _maxCount) + throw new StorageOverflowException(_maxCount); + if (!(position >= 0 && position <= Count)) + { + return false; + } _places.Insert(position, boat); return true; } @@ -66,7 +71,7 @@ namespace Sailboat.Generics { if (position < 0 || position >= Count) { - return false; + throw new BoatNotFoundException(position); } _places.RemoveAt(position); return true; @@ -80,15 +85,17 @@ namespace Sailboat.Generics { get { - if (position < 0 || position >= Count) { - return null; + if (position < 0 || position >= Count) + { + return null; } return _places[position]; } set { - if (!(position >= 0 && position < Count && _places.Count < _maxCount)) { - return; + if (!(position >= 0 && position < Count && _places.Count < _maxCount)) + { + return; } _places.Insert(position, value); return; @@ -110,4 +117,4 @@ namespace Sailboat.Generics } } } -} +} \ No newline at end of file diff --git a/Sailboat/Sailboat/Status.cs b/Sailboat/Sailboat/Status.cs index aec198e..e2464e2 100644 --- a/Sailboat/Sailboat/Status.cs +++ b/Sailboat/Sailboat/Status.cs @@ -1,113 +1,18 @@ -using Sailboat.Exceptions; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Sailboat.Generics +namespace Sailboat.MovementStrategy { - - internal class SetGeneric where T : class + /// + /// Статус выполнения операции перемещения + /// + public enum Status { - /// - /// Список объектов, которые храним - /// - private readonly List _places; - /// - /// Количество объектов в массиве - /// - public int Count => _places.Count; - /// - /// Максимальное количество объектов в списке - /// - private readonly int _maxCount; - /// - /// Конструктор - /// - /// - public SetGeneric(int count) - { - _maxCount = count; - _places = new List(count); - } - /// - /// Добавление объекта в набор - /// - /// Добавляемая лодка - /// - public bool Insert(T boat) - { - return Insert(boat, 0); - } - /// - /// Добавление объекта в набор на конкретную позицию - /// - /// Добавляемая лодка - /// Позиция - /// - 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; - } - /// - /// Удаление объекта из набора с конкретной позиции - /// - /// - /// - public bool Remove(int position) - { - if (position < 0 || position > _maxCount || position >= Count) - throw new BoatNotFoundException(position); - - _places.RemoveAt(position); - return true; - } - /// - /// Получение объекта из набора по позиции - /// - /// - /// - 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; - } - } - /// - /// Проход по списку - /// - /// - public IEnumerable GetBoats(int? maxBoats = null) - { - for (int i = 0; i < _places.Count; ++i) - { - yield return _places[i]; - if (maxBoats.HasValue && i == maxBoats.Value) - { - yield break; - } - } - } + NotInit, + InProgress, + Finish } } \ No newline at end of file