PIbd-23 Yakobchuk S.V. LabWork_07 #8

Closed
sofia7ya wants to merge 4 commits from LabWork_07 into LabWork_06
11 changed files with 86 additions and 17 deletions
Showing only changes of commit b51f1183fc - Show all commits

View File

@ -1,4 +1,9 @@
using System.Runtime.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace Sailboat.Exceptions
{

View File

@ -77,13 +77,10 @@ namespace Sailboat.Generics
public static bool operator -(BoatsGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
collect._collection.Remove(pos);
return false;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>

View File

@ -115,11 +115,11 @@ namespace Sailboat.Generics
}
if (data.Length == 0)
{
throw new Exception("Невалиданя операция, нет данных для сохранения");
throw new Exception("Невалидная операция, нет данных для сохранения");
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write($"PlaneStorage{Environment.NewLine}{data}");
writer.Write($"SailboatStorage{Environment.NewLine}{data}");
}
return true;
}

View File

@ -22,6 +22,9 @@ namespace Sailboat.DrawingObjects
private readonly int _boatWidth = 185;
private readonly int _boatHeight = 160;
public int GetPosX => _startPosX;
char separator = '|';
public int GetPosY => _startPosY;
public int GetWidth => _boatWidth;
public int GetHeight => _boatHeight;

View File

@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic.Logging;
using Sailboat.Entities;
namespace Sailboat.DrawingObjects

View File

@ -1,12 +1,16 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Metrics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using Serilog;
using Sailboat.DrawingObjects;
using Sailboat.Exceptions;
@ -18,10 +22,12 @@ namespace Sailboat
public partial class FormBoatCollection : Form
{
private readonly BoatsGenericStorage _storage;
private readonly ILogger _logger;
public FormBoatCollection()
{
InitializeComponent();
_storage = new BoatsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
_logger = logger;
}
private void ReloadObjects()
@ -135,6 +141,7 @@ namespace Sailboat
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
_logger.LogInformation($"Добавлен набор:{textBoxStorageName.Text}");
}
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
@ -149,11 +156,12 @@ namespace Sailboat
{
return;
}
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
_storage.DelSet(name);
ReloadObjects(); ;
_logger.LogInformation($"Удален набор: {name}");
}
}

View File

@ -1,3 +1,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Json;
using Serilog.Configuration;
namespace Sailboat
{
internal static class Program
@ -10,7 +18,22 @@ namespace Sailboat
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
ApplicationConfiguration.Initialize(); string[] path = Directory.GetCurrentDirectory().Split('\\');
string pathNeed = "";
for (int i = 0; i < path.Length - 3; i++)
{
pathNeed += path[i] + "\\";
}
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: $"{pathNeed}debug.json", optional: false, reloadOnChange: true)
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormBoatCollection());
}
}

View File

@ -8,6 +8,13 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@ -1,8 +1,10 @@
using System;
using Sailboat.Exceptions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sailboat.Generics
{
@ -38,7 +40,7 @@ namespace Sailboat.Generics
{
if (_places.Count == _maxCount)
{
return false;
throw new StorageOverflowException(_maxCount);
}
Insert(boat, 0);
return true;
@ -51,7 +53,9 @@ namespace Sailboat.Generics
/// <returns></returns>
public bool Insert(T boat, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
if (_places.Count == _maxCount)
throw new StorageOverflowException(_maxCount);
if (!(position >= 0 && position <= Count))
{
return false;
}
@ -67,7 +71,7 @@ namespace Sailboat.Generics
{
if (position < 0 || position >= Count)
{
return false;
throw new BoatNotFoundException(position);
}
_places.RemoveAt(position);
return true;

View File

@ -1,4 +1,9 @@
using System.Runtime.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace Sailboat.Exceptions
{

View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": { "path": "log.txt" }
}
],
"Properties": {
"Application": "Sample"
}
}
}