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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,8 +9,11 @@
</PropertyGroup>
<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="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>

View File

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