2
This commit is contained in:
parent
92f5da95a6
commit
44f7ef01e8
@ -1,31 +1,33 @@
|
|||||||
using Stormtrooper.Drawnings;
|
using Stormtrooper.Exceptions;
|
||||||
|
using Stormtrooper.CollectionGenericObjects;
|
||||||
using Stormtrooper.Exceptions;
|
using Stormtrooper.Exceptions;
|
||||||
using System.CodeDom;
|
|
||||||
|
|
||||||
namespace Stormtrooper.CollectionGenericObjects;
|
namespace Stormtrooper.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметризованный набор объектов
|
/// Параметризованный набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Массив объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private T?[] _collection;
|
private T?[] _collection;
|
||||||
|
|
||||||
public int Count => _collection.Length;
|
public int Count => _collection.Length;
|
||||||
|
/// <summary>
|
||||||
public int MaxCount {
|
/// Установка максимального кол-ва объектов
|
||||||
|
/// </summary>
|
||||||
|
public int MaxCount
|
||||||
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _collection.Length;
|
return _collection.Length;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value > 0) {
|
if (value > 0)
|
||||||
|
{
|
||||||
if (_collection.Length > 0)
|
if (_collection.Length > 0)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _collection, value);
|
Array.Resize(ref _collection, value);
|
||||||
@ -47,6 +49,11 @@ where T : class
|
|||||||
{
|
{
|
||||||
_collection = Array.Empty<T?>();
|
_collection = Array.Empty<T?>();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция (индекс)</param>
|
||||||
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _collection.Length)
|
if (position < 0 || position >= _collection.Length)
|
||||||
|
@ -52,22 +52,23 @@ where T : DrawningAircraft
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
/// <param name="collectionType">тип коллекции</param>
|
/// <param name="collectionType">тип коллекции</param>
|
||||||
public void AddCollection(string name, CollectionType collectionType)
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
{
|
{
|
||||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
|
||||||
// TODO Прописать логику для добавления
|
return;
|
||||||
if (!(collectionType == CollectionType.None) && !_storages.ContainsKey(name))
|
switch (collectionType)
|
||||||
{
|
{
|
||||||
if (collectionType == CollectionType.List)
|
case CollectionType.List:
|
||||||
{
|
|
||||||
_storages.Add(name, new ListGenericObjects<T>());
|
_storages.Add(name, new ListGenericObjects<T>());
|
||||||
}
|
break;
|
||||||
else if (collectionType == CollectionType.Massive)
|
case CollectionType.Massive:
|
||||||
{
|
|
||||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление коллекции
|
/// Удаление коллекции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -82,15 +83,12 @@ where T : DrawningAircraft
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ICollectionGenericObjects<T>? this[string name]
|
public ICollectionGenericObjects<T>? this[string name]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO Продумать логику получения объекта
|
if (_storages.TryGetValue(name, out ICollectionGenericObjects<T>? value))
|
||||||
if (_storages.ContainsKey(name))
|
return value;
|
||||||
{
|
|
||||||
return _storages[name];
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,8 +110,6 @@ where T : DrawningAircraft
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using FileStream fs = new(filename, FileMode.Create);
|
using FileStream fs = new(filename, FileMode.Create);
|
||||||
using StreamWriter streamWriter = new StreamWriter(fs);
|
using StreamWriter streamWriter = new StreamWriter(fs);
|
||||||
streamWriter.Write(_collectionKey);
|
streamWriter.Write(_collectionKey);
|
||||||
|
@ -4,43 +4,42 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Serilog;
|
using Serilog;
|
||||||
using Stormtrooper;
|
using Stormtrooper;
|
||||||
|
|
||||||
namespace Battleship
|
namespace Stormtrooper;
|
||||||
|
|
||||||
|
internal static class Program
|
||||||
{
|
{
|
||||||
internal static class Program
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
{
|
{
|
||||||
/// <summary>
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
/// The main entry point for the application.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
/// </summary>
|
ApplicationConfiguration.Initialize();
|
||||||
[STAThread]
|
var services = new ServiceCollection();
|
||||||
static void Main()
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
Application.Run(serviceProvider.GetRequiredService<FormAircraftCollection>());
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
var services = new ServiceCollection();
|
|
||||||
ConfigureServices(services);
|
|
||||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
|
||||||
{
|
|
||||||
Application.Run(serviceProvider.GetRequiredService<FormAircraftCollection>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddSingleton<FormAircraftCollection>()
|
|
||||||
.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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormAircraftCollection>()
|
||||||
|
.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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,9 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<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="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.10" />
|
|
||||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
|
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user