допкаГотовая лабораторная работа 7

This commit is contained in:
sqdselo 2024-05-06 23:02:05 +04:00 committed by Timur_Sharafutdinov
parent ea555cc897
commit 84b3e6f21e
6 changed files with 48 additions and 13 deletions

View File

@ -30,7 +30,7 @@ namespace HoistingCrane.CollectionGenericObjects
{
get
{
return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-2;
return (pictureWidth / _placeSizeWidth) * (pictureHeight / _placeSizeHeight);
}
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedVehicle> array)

View File

@ -44,7 +44,7 @@ namespace HoistingCrane
else
{
MessageBox.Show("Не удалось добавить объект");
logger.LogInformation("Не удалось добавить корабль {ship} в коллекцию", drawningTrackedVehicle.GetType().Name);
logger.LogInformation("Не удалось добавить кран {crane} в коллекцию", drawningTrackedVehicle.GetType().Name);
}
}
catch (CollectionOverflowException ex)
@ -142,12 +142,12 @@ namespace HoistingCrane
if (radioButtonMassive.Checked)
{
collectionType = CollectionType.Massive;
logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text);
logger.LogInformation("Создана коллекция {nameCol} , название: {name}", collectionType, textBoxCollectionName.Text);
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text);
logger.LogInformation("Создана коллекция {nameCol} , название: {name}", collectionType, textBoxCollectionName.Text);
}
_storageCollection.AddCollection(textBoxCollectionName.Text,collectionType);RerfreshListBoxItems();
}
@ -205,7 +205,7 @@ namespace HoistingCrane
{
_storageCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName.ToString());
}
catch (Exception ex)
{
@ -229,7 +229,7 @@ namespace HoistingCrane
_storageCollection.LoadData(openFileDialog.FileName);
RerfreshListBoxItems();
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName);
logger.LogInformation("Загрузка из файла: {filename}", saveFileDialog.FileName.ToString());
}
catch(Exception ex)
{

View File

@ -13,8 +13,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />

View File

@ -1,8 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Extensions.Logging;
namespace HoistingCrane
{
internal static class Program
@ -18,11 +17,24 @@ namespace HoistingCrane
}
private static void ConfigureServices(ServiceCollection services)
{
// Èíèöèàëèçèðóåì Serilog
Log.Logger = new LoggerConfiguration().WriteTo.File("E:\\myLog.log").CreateLogger();
services.AddSingleton<FormCarCollection>().AddLogging(builder =>
string[] path = Directory.GetCurrentDirectory().Split('\\');
string pathNeed = "";
for (int i = 0; i < path.Length - 3; i++)
{
builder.AddSerilog();
pathNeed += path[i] + "\\";
}
services.AddSingleton<FormCarCollection>()
.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.AddJsonFile($"{pathNeed}serilog.json")
.Build())
.CreateLogger());
});
}
}

View File

@ -0,0 +1,18 @@

{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "log.log"
}
}
],
"Properties": {
"Application": "Sample"
}
}
}

View File

@ -0,0 +1,2 @@
CollectionsStorage
массив|Massive|25|EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:Purple;EntityHoistingCrane:100:100:Gray:Black:True:False;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:White;EntityHoistingCrane:100:100:Green:Black:False:False;EntityTrackedVehicle:100:100:Gray;EntityTrackedVehicle:100:100:Red;EntityHoistingCrane:100:100:White:Black:False:False;EntityHoistingCrane:100:100:Green:Blue:True:False;EntityHoistingCrane:100:100:Black:Black:True:True;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Black;EntityTrackedVehicle:100:100:Blue;EntityTrackedVehicle:100:100:Gray;EntityTrackedVehicle:100:100:Red;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Green;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:Blue;EntityTrackedVehicle:100:100:Gray;