From e22da57340039502600d56a826ef17ee5be5e3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BA=D1=80=D0=B8=D1=81=D1=82=D0=B8=D0=BD=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B2=D1=80=D0=BE=D0=B2=D0=B0?= Date: Wed, 2 Oct 2024 10:44:28 +0400 Subject: [PATCH] wip 7 --- .../CollectionGenericObjects/AbstractCompany.cs | 8 ++++++-- .../ICollectionGenericObjects.cs | 1 - .../TrackedVehicleSharingService.cs | 7 ++++--- solution/lab1/Program.cs | 17 +++++++++++++---- solution/lab1/lab1.csproj | 7 +++++++ solution/lab1/serilog.json | 15 +++++++++++++++ 6 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 solution/lab1/serilog.json diff --git a/solution/lab1/CollectionGenericObjects/AbstractCompany.cs b/solution/lab1/CollectionGenericObjects/AbstractCompany.cs index 3720195..9c3a521 100644 --- a/solution/lab1/CollectionGenericObjects/AbstractCompany.cs +++ b/solution/lab1/CollectionGenericObjects/AbstractCompany.cs @@ -83,8 +83,12 @@ public abstract class AbstractCompany SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { - DrawningTrackedVehicle? obj = _collection?.Get(i); - obj?.DrawTransport(graphics); + try + { + DrawningTrackedVehicle? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + catch (Exception) { } } return bitmap; } diff --git a/solution/lab1/CollectionGenericObjects/ICollectionGenericObjects.cs b/solution/lab1/CollectionGenericObjects/ICollectionGenericObjects.cs index ab6aacc..fd97190 100644 --- a/solution/lab1/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/solution/lab1/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -47,7 +47,6 @@ public interface ICollectionGenericObjects /// Получение типа коллекции /// CollectionType GetCollectionType { get; } - int SetMaxCount { get; set; } /// /// Получение объектов коллекции по одному diff --git a/solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs b/solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs index 19ef884..3702f6c 100644 --- a/solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs +++ b/solution/lab1/CollectionGenericObjects/TrackedVehicleSharingService.cs @@ -47,11 +47,12 @@ public class TrackedVehicleSharingService : AbstractCompany int curHeight = 0; 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 + 45, curHeight * _placeSizeHeight + 30); + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(_placeSizeWidth * curWidth+28, curHeight * _placeSizeHeight + 28); } + catch (Exception) { } if (curWidth > 0) curWidth--; else diff --git a/solution/lab1/Program.cs b/solution/lab1/Program.cs index 5dafb44..8ae5b66 100644 --- a/solution/lab1/Program.cs +++ b/solution/lab1/Program.cs @@ -1,5 +1,7 @@ using Microsoft.Extensions.DependencyInjection; -using System; +using Microsoft.Extensions.Logging; +using Serilog; +using Microsoft.Extensions.Configuration; namespace lab1 { @@ -27,14 +29,21 @@ namespace lab1 /// private static void ConfigureServices(ServiceCollection services) { - + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } services.AddSingleton() .AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddSerilog(new LoggerConfiguration() - .WriteTo.File("log.txt") - .CreateLogger()); + .ReadFrom.Configuration(new ConfigurationBuilder() + .AddJsonFile($"{pathNeed}serilog.json") + .Build()) + .CreateLogger()); }); } } diff --git a/solution/lab1/lab1.csproj b/solution/lab1/lab1.csproj index d11a7da..69863ee 100644 --- a/solution/lab1/lab1.csproj +++ b/solution/lab1/lab1.csproj @@ -9,7 +9,14 @@ + + + + + + + diff --git a/solution/lab1/serilog.json b/solution/lab1/serilog.json new file mode 100644 index 0000000..d1428e1 --- /dev/null +++ b/solution/lab1/serilog.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "log.log" } + } + ], + "Properties": { + "Application": "Sample" + } + } +}