This commit is contained in:
Baryshev Dmitry 2024-05-11 15:12:11 +04:00
parent 1b618a28f6
commit 13547998c5
5 changed files with 58 additions and 9 deletions

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectDumpTruck.Drawnings;
using ProjectDumpTruck.Exceptions;
namespace ProjectDumpTruck.CollectionGenericObject;
@ -13,26 +14,32 @@ public abstract class AbstractCompany
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 310;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 125;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция грузовиков
/// </summary>
protected ICollectionGenericObject<DrawningTruck>? _collection = null;
/// <summary>
/// Вычисление максимального количества элементов, который можно разместить в окне
/// </summary>
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
/// <summary>
/// Конструктор
/// </summary>
@ -55,7 +62,7 @@ public abstract class AbstractCompany
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningTruck truck)
{
return company._collection.Insert(truck);
return company._collection.Insert(truck,0);
}
/// <summary>
@ -66,7 +73,7 @@ public abstract class AbstractCompany
/// <returns></returns>
public static DrawningTruck? operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position-1);
return company._collection?.Remove(position);
}
/// <summary>
@ -76,7 +83,14 @@ public abstract class AbstractCompany
public DrawningTruck? GetRandomObject()
{
Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount));
try
{
return _collection?.Get(rnd.Next(GetMaxCount));
}
catch (ObjectNotFoundException)
{
return null;
}
}
/// <summary>
@ -92,8 +106,15 @@ public abstract class AbstractCompany
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningTruck? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
try
{
DrawningTruck? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
catch (ObjectNotFoundException)
{
continue;
}
}
return bitmap;
}

View File

@ -97,7 +97,7 @@ public class ListGenericObjects<T> : ICollectionGenericObject<T>
return obj;
}
public IEnumerable<T> GetItems()
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < Count; i++) yield return _collection[i];
}

View File

@ -35,4 +35,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="serilogConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,3 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

View File

@ -0,0 +1,25 @@
{
"AllowedHosts": "*",
"Serilog": {
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "C:\\Users\\dimoo\\OneDrive\\Рабочий стол\\Лабы\\log.txt",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.ffff} | {Level:u} | {SourceContext} | {Message:1j}{NewLine}{Exception}"
}
}
]
}
}