diff --git a/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs b/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs index 4245b49..fa61f9e 100644 --- a/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,31 +1,33 @@ -using Stormtrooper.Drawnings; +using Stormtrooper.Exceptions; +using Stormtrooper.CollectionGenericObjects; using Stormtrooper.Exceptions; -using System.CodeDom; namespace Stormtrooper.CollectionGenericObjects; - /// /// Параметризованный набор объектов /// /// Параметр: ограничение - ссылочный тип public class MassiveGenericObjects : ICollectionGenericObjects -where T : class + where T : class { /// /// Массив объектов, которые храним /// private T?[] _collection; - public int Count => _collection.Length; - - public int MaxCount { + /// + /// Установка максимального кол-ва объектов + /// + public int MaxCount + { get { return _collection.Length; } set { - if (value > 0) { + if (value > 0) + { if (_collection.Length > 0) { Array.Resize(ref _collection, value); @@ -47,6 +49,11 @@ where T : class { _collection = Array.Empty(); } + /// + /// Получение объекта по позиции + /// + /// Позиция (индекс) + /// public T? Get(int position) { if (position < 0 || position >= _collection.Length) diff --git a/Stormtrooper/Stormtrooper/CollectionGenericObjects/StorageCollection.cs b/Stormtrooper/Stormtrooper/CollectionGenericObjects/StorageCollection.cs index e7db10d..797dbf2 100644 --- a/Stormtrooper/Stormtrooper/CollectionGenericObjects/StorageCollection.cs +++ b/Stormtrooper/Stormtrooper/CollectionGenericObjects/StorageCollection.cs @@ -52,22 +52,23 @@ where T : DrawningAircraft /// /// Название коллекции /// тип коллекции - public void AddCollection(string name, CollectionType collectionType) + public void AddCollection(string name, CollectionType collectionType) { - // TODO проверка, что name не пустой и нет в словаре записи с таким ключом - // TODO Прописать логику для добавления - if (!(collectionType == CollectionType.None) && !_storages.ContainsKey(name)) + if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name)) + return; + switch (collectionType) { - if (collectionType == CollectionType.List) - { + case CollectionType.List: _storages.Add(name, new ListGenericObjects()); - } - else if (collectionType == CollectionType.Massive) - { + break; + case CollectionType.Massive: _storages.Add(name, new MassiveGenericObjects()); - } + break; + default: + break; } } + /// /// Удаление коллекции /// @@ -82,15 +83,12 @@ where T : DrawningAircraft /// /// Название коллекции /// - public ICollectionGenericObjects? this[string name] + public ICollectionGenericObjects? this[string name] { get { - // TODO Продумать логику получения объекта - if (_storages.ContainsKey(name)) - { - return _storages[name]; - } + if (_storages.TryGetValue(name, out ICollectionGenericObjects? value)) + return value; return null; } } @@ -112,8 +110,6 @@ where T : DrawningAircraft File.Delete(filename); } - - using FileStream fs = new(filename, FileMode.Create); using StreamWriter streamWriter = new StreamWriter(fs); streamWriter.Write(_collectionKey); diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs index f17f11a..f9bc13c 100644 --- a/Stormtrooper/Stormtrooper/Program.cs +++ b/Stormtrooper/Stormtrooper/Program.cs @@ -4,43 +4,42 @@ using Microsoft.Extensions.Configuration; using Serilog; using Stormtrooper; -namespace Battleship +namespace Stormtrooper; + +internal static class Program { - internal static class Program + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = services.BuildServiceProvider()) { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - using (ServiceProvider serviceProvider = services.BuildServiceProvider()) - { - Application.Run(serviceProvider.GetRequiredService()); - } - } - private static void ConfigureServices(ServiceCollection services) - { - services.AddSingleton() - .AddLogging(option => - { - var configuration = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile(path: "C:\\Users\\User\\Desktop\\2sem\\Egovoop\\lab1\\Stormtrooper\\Stormtrooper\\appSetting.json", optional: false, reloadOnChange: true) - .Build(); - - var logger = new LoggerConfiguration() - .ReadFrom.Configuration(configuration) - .CreateLogger(); - - option.SetMinimumLevel(LogLevel.Information); - option.AddSerilog(logger); - }); + Application.Run(serviceProvider.GetRequiredService()); } } + private static void ConfigureServices(ServiceCollection services) + { + services.AddSingleton() + .AddLogging(option => + { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(path: "C:\\Users\\User\\Desktop\\2sem\\Egovoop\\lab1\\Stormtrooper\\Stormtrooper\\appSetting.json", optional: false, reloadOnChange: true) + .Build(); + + var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger); + }); + } } \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/Stormtrooper.csproj b/Stormtrooper/Stormtrooper/Stormtrooper.csproj index 7d4a893..ec6b790 100644 --- a/Stormtrooper/Stormtrooper/Stormtrooper.csproj +++ b/Stormtrooper/Stormtrooper/Stormtrooper.csproj @@ -9,9 +9,10 @@ + + + - -