корректировка

This commit is contained in:
Алёна Фролова 2024-05-16 04:12:06 +04:00
parent 39ef9a866f
commit 43d87b33f5
7 changed files with 133 additions and 141 deletions

View File

@ -1,4 +1,5 @@
using ProjectCatamaran.Drawnings; using ProjectCatamaran.Drawnings;
using ProjectCatamaran.Exceptions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -32,7 +33,8 @@ public abstract class AbstractCompany
/// <summary> /// <summary>
/// Вычисление максимального количества элементов, который можно разместить в окне /// Вычисление максимального количества элементов, который можно разместить в окне
/// </summary> /// </summary>
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -87,10 +89,17 @@ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
try
{ {
DrawningBoat? obj = _collection?.Get(i); DrawningBoat? obj = _collection?.Get(i);
obj?.DrawTransport(graphics); obj?.DrawTransport(graphics);
} }
catch (ObjectNotFoundException e)
{ }
catch (PositionOutOfCollectionException e)
{ }
}
return bitmap; return bitmap;
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using ProjectCatamaran.Drawnings; using ProjectCatamaran.Drawnings;
using ProjectCatamaran.Exceptions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -27,14 +28,14 @@ public class BoatHarborService : AbstractCompany
{ {
int width = _pictureWidth / _placeSizeWidth; int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight; int height = _pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 4); Pen pen = new(Color.Black, 2);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) for (int i = 0; i < width + 1; i++)
{ {
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) for (int j = 0; j < height + 1; ++j)
{ {
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 5, i * _placeSizeWidth + _placeSizeWidth - 90, j * _placeSizeHeight + 5); g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth - _placeSizeWidth + 8, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth - _placeSizeWidth + 8, j * _placeSizeHeight, i * _placeSizeWidth - _placeSizeWidth + 8, j * _placeSizeHeight - _placeSizeHeight);
} }
g.DrawLine(pen, i * _placeSizeWidth,0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight + 5);
} }
} }
@ -48,12 +49,15 @@ public class BoatHarborService : AbstractCompany
for (int i = 0; i < (_collection?.Count ?? 0); i++) for (int i = 0; i < (_collection?.Count ?? 0); i++)
{ {
if (_collection.Get(i) != null) try
{ {
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 5); _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 5);
} }
catch (ObjectNotFoundException) { }
catch (PositionOutOfCollectionException e) { }
if (curWidth < width - 1) if (curWidth < width - 1)
curWidth++; curWidth++;
else else
@ -65,6 +69,7 @@ public class BoatHarborService : AbstractCompany
{ {
return; return;
} }
} }
} }
} }

View File

@ -32,23 +32,12 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
} }
public T? Get(int position) public T? Get(int position)
{ {
//TODO: выброс ошибки, если выход за границы массива if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
if (position >= 0 && position < Count)
{
throw new PositionOutOfCollectionException(position);
}
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj)
{ {
//TODO: выброс ошибки, если переполнение if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (Count <= _maxCount)
{
throw new CollectionOverflowException(Count);
}
_collection.Add(obj); _collection.Add(obj);
return Count; return Count;
@ -56,26 +45,17 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
//TODO: выброс ошибки, если переполнение if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
if (Count < _maxCount && position >= 0 && position < _maxCount)
{
throw new CollectionOverflowException(Count);
}
_collection.Insert(position, obj); _collection.Insert(position, obj);
return position; return position;
} }
public T Remove(int position) public T Remove(int position)
{ {
//TODO: выброс ошибки, если выход за границы массива if (position >= _collection.Count || position < 0) throw new PositionOutOfCollectionException(position);
T obj = _collection[position];
T temp = _collection[position];
if (position >= 0 && position < _maxCount)
{
throw new CollectionOverflowException(Count);
}
_collection.RemoveAt(position); _collection.RemoveAt(position);
return temp; return obj;
} }
public IEnumerable<T?> GetItems() public IEnumerable<T?> GetItems()

View File

@ -54,84 +54,77 @@ namespace ProjectCatamaran.CollectiongGenericObjects;
} }
public T? Get(int position) public T? Get(int position)
{ {
//TODO: выброс ошибки, если выход за границы массива if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
if (_collection[position] == null) throw new ObjectNotFoundException(position);
// проверка позиции
if (position >= _collection.Length || position < 0)
{
throw new PositionOutOfCollectionException(position);
}
if (_collection[position] == null)
{
throw new ObjectNotFoundException(position);
}
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj)
{ {
//TODO: выброс ошибки, если переполнение
// вставка в свободное место набора // вставка в свободное место набора
int index = 0; for (int i = 0; i < Count; i++)
while (index < _collection.Length - 1)
{ {
if (_collection[index] == null) if (_collection[i] == null)
{ {
_collection[index] = obj; _collection[i] = obj;
return index; return i;
} }
index++;
} }
throw new CollectionOverflowException(Count); throw new CollectionOverflowException(Count);
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
//TODO: выброс ошибки, если переполнение // проверка позиции
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
if (_collection[position] != null)
if (position >= _collection.Length || position < 0)
{ {
throw new PositionOutOfCollectionException(position);
}
if (_collection[position] == null) bool pushed = false;
{
_collection[position] = obj;
return position;
}
int index; int index;
for (index = position + 1; index < _collection.Length; ++index) for (index = position + 1; index < _collection.Length; index++)
{ {
if (_collection[index] == null) if (_collection[index] == null)
{ {
_collection[position] = obj; position = index;
return position; pushed = true;
break;
} }
} }
for (index = position - 1; index >= 0; --index) if (!pushed)
{
for (index = position - 1; index >= 0; index--)
{ {
if (_collection[index] == null) if (_collection[index] == null)
{ {
position = index;
pushed = true;
break;
}
}
}
if (!pushed)
{
throw new CollectionOverflowException(Count);
}
}
_collection[position] = obj; _collection[position] = obj;
return position; return position;
} }
}
throw new CollectionOverflowException(Count);
}
public T? Remove(int position) public T? Remove(int position)
{ {
//TODO: выброс ошибки, если выход за границы массива // проверка позиции
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
if (position >= _collection.Length || position < 0) if (_collection[position] == null) throw new ObjectNotFoundException(position);
{ T temp = _collection[position];
throw new ObjectNotFoundException(position);
}
T DrawningBoat = _collection[position];
_collection[position] = null; _collection[position] = null;
return DrawningBoat; return temp;
} }
public IEnumerable<T?> GetItems() public IEnumerable<T?> GetItems()

View File

@ -1,34 +1,32 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using Serilog;
namespace ProjectCatamaran;
namespace ProjectCatamaran
{
internal static class Program internal static class Program
{ {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ServiceCollection services = new();
ConfigureServices(services); ConfigureServices(services);
using ServiceProvider serviceProvider = services.BuildServiceProvider(); using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormBoatCollection>()); Application.Run(serviceProvider.GetRequiredService<FormBoatCollection>());
} }
}
/// <summary>
/// Êîíôèãóðàöèÿ ñåðâèñà 01
/// </summary>
/// <param name="services"></param>
private static void ConfigureServices(ServiceCollection services) private static void ConfigureServices(ServiceCollection services)
{ {
services.AddSingleton<FormBoatCollection>().AddLogging(option =>
{
string[] path = Directory.GetCurrentDirectory().Split('\\'); string[] path = Directory.GetCurrentDirectory().Split('\\');
string pathNeed = ""; string pathNeed = "";
for (int i = 0; i < path.Length - 3; i++) for (int i = 0; i < path.Length - 3; i++)
@ -36,13 +34,12 @@ namespace ProjectCatamaran
pathNeed += path[i] + "\\"; pathNeed += path[i] + "\\";
} }
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
services.AddSingleton<FormBoatCollection>() .AddJsonFile(path: $"{pathNeed}serilogConfig.json", optional: false, reloadOnChange: true)
.AddLogging(option => .Build();
{ var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information); option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config"); option.AddSerilog(logger);
}); });
} }
} }
}

View File

@ -9,8 +9,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" 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="NLog.Extensions.Logging" Version="5.3.8" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
<PackageReference Include="Serilog" Version="3.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,15 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?> {
<configuration> "Serilog": {
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" "Using": [ "Serilog.Sinks.File" ],
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" "MinimumLevel": "Information",
autoReload="true" internalLogLevel="Info"> "WriteTo": [
{
<targets> "Name": "File",
<target xsi:type="File" name="tofile" fileName="carlog-${shortdate}.log" /> "Args": {
</targets> "path": "Logs/log_.log",
"rollingInterval": "Day",
<rules> "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
<logger name="*" minlevel="Debug" writeTo="tofile" /> }
</rules> }
</nlog> ],
</configuration> "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "Catamaran"
}
}
}