diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs
index 0bdeb11..b290193 100644
--- a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs
@@ -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
///
/// Вычисление максимального количества элементов, который можно разместить в окне
///
-private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+ private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
+
///
/// Конструктор
///
@@ -88,8 +90,15 @@ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
- DrawningBoat? obj = _collection?.Get(i);
- obj?.DrawTransport(graphics);
+ try
+ {
+ DrawningBoat? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ catch (ObjectNotFoundException e)
+ { }
+ catch (PositionOutOfCollectionException e)
+ { }
}
return bitmap;
}
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs
index bddbc58..288b017 100644
--- a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs
@@ -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,23 +49,27 @@ 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
- {
- curWidth = 0;
- curHeight--;
- }
- if (curHeight < 0)
- {
- return;
- }
- }
+ curWidth++;
+ else
+ {
+ curWidth = 0;
+ curHeight--;
+ }
+ if (curHeight < 0)
+ {
+ return;
+ }
+
+ }
}
}
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ListGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ListGenericObjects.cs
index 7b8f605..7e700ea 100644
--- a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ListGenericObjects.cs
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ListGenericObjects.cs
@@ -32,23 +32,12 @@ public class ListGenericObjects : ICollectionGenericObjects
}
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 : ICollectionGenericObjects
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 GetItems()
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs
index 153e49f..2666ad8 100644
--- a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs
@@ -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)
- {
- if (_collection[index] == null)
+ int index;
+ for (index = position + 1; index < _collection.Length; index++)
{
- _collection[position] = obj;
- return position;
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
}
- }
- for (index = position - 1; index >= 0; --index)
- {
- if (_collection[index] == null)
+ if (!pushed)
{
- _collection[position] = obj;
- return position;
+
+ for (index = position - 1; index >= 0; index--)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
}
+ if (!pushed)
+ {
+ throw new CollectionOverflowException(Count);
+ }
+
}
- throw new CollectionOverflowException(Count);
+ _collection[position] = obj;
+ return position;
}
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 GetItems()
diff --git a/ProjectCatamaran/ProjectCatamaran/Program.cs b/ProjectCatamaran/ProjectCatamaran/Program.cs
index b055357..46bb482 100644
--- a/ProjectCatamaran/ProjectCatamaran/Program.cs
+++ b/ProjectCatamaran/ProjectCatamaran/Program.cs
@@ -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
{
- internal static class Program
+ [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();
-
- ServiceCollection services = new();
- ConfigureServices(services);
- using ServiceProvider serviceProvider = services.BuildServiceProvider();
Application.Run(serviceProvider.GetRequiredService());
}
+ }
- ///
- /// 01
- ///
- ///
- private static void ConfigureServices(ServiceCollection services)
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddSingleton().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()
- .AddLogging(option =>
- {
- option.SetMinimumLevel(LogLevel.Information);
- option.AddNLog("nlog.config");
- });
- }
+ 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.AddSerilog(logger);
+ });
}
}
\ No newline at end of file
diff --git a/ProjectCatamaran/ProjectCatamaran/ProjectCatamaran.csproj b/ProjectCatamaran/ProjectCatamaran/ProjectCatamaran.csproj
index f24932a..277d423 100644
--- a/ProjectCatamaran/ProjectCatamaran/ProjectCatamaran.csproj
+++ b/ProjectCatamaran/ProjectCatamaran/ProjectCatamaran.csproj
@@ -9,8 +9,11 @@
+
+
-
+
+
diff --git a/ProjectCatamaran/ProjectCatamaran/serilogConfig.json b/ProjectCatamaran/ProjectCatamaran/serilogConfig.json
index 9cc4d12..63d86d9 100644
--- a/ProjectCatamaran/ProjectCatamaran/serilogConfig.json
+++ b/ProjectCatamaran/ProjectCatamaran/serilogConfig.json
@@ -1,15 +1,20 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+{
+ "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"
+ }
+ }
+}
\ No newline at end of file