ISEbd-12 Rozhkov.I.E. Lab07 Simple #7

Closed
RozhVan wants to merge 1 commits from lab07 into lab06
15 changed files with 361 additions and 148 deletions

View File

@ -1,4 +1,5 @@
using ProjectPlane.Drawnings; using ProjectPlane.Drawnings;
using ProjectPlane.Exceptions;
namespace ProjectPlane.CollectionGenericObjects; namespace ProjectPlane.CollectionGenericObjects;
@ -26,7 +27,7 @@ public abstract class AbstractCompany
public static int operator +(AbstractCompany company, DrawningShip ship) public static int operator +(AbstractCompany company, DrawningShip ship)
{ {
return company._collection.Insert(ship); return company._collection.Insert(ship, 0);
} }
public static DrawningShip? operator -(AbstractCompany company, int position) public static DrawningShip? operator -(AbstractCompany company, int position)
@ -37,8 +38,15 @@ public abstract class AbstractCompany
public DrawningShip? GetRandomObject() public DrawningShip? GetRandomObject()
{ {
Random rnd = new(); Random rnd = new();
try
{
return _collection?.Get(rnd.Next(GetMaxCount)); return _collection?.Get(rnd.Next(GetMaxCount));
} }
catch (ObjectNotFoundException)
{
return null;
}
}
public Bitmap? Show() public Bitmap? Show()
{ {
@ -47,10 +55,17 @@ public abstract class AbstractCompany
DrawBackgound(graphics); DrawBackgound(graphics);
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
try
{ {
DrawningShip? obj = _collection?.Get(i); DrawningShip? obj = _collection?.Get(i);
obj?.DrawTransport(graphics); obj?.DrawTransport(graphics);
} }
catch (ObjectNotFoundException)
{
continue;
}
}
return bitmap; return bitmap;
} }

View File

@ -1,4 +1,5 @@
using System.CodeDom.Compiler; using ProjectPlane.Exceptions;
using System.CodeDom.Compiler;
namespace ProjectPlane.CollectionGenericObjects; namespace ProjectPlane.CollectionGenericObjects;
@ -22,9 +23,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position) public T? Get(int position)
{ {
// TODO выброс ошибки, если выход за границы списка
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
{ {
return null; throw new PositionOutOfCollectionException(position);
} }
return _collection[position]; return _collection[position];
@ -32,9 +34,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public int Insert(T obj) public int Insert(T obj)
{ {
// TODO выброс ошибки, если переполнение
if (Count == _maxCount) if (Count == _maxCount)
{ {
return -1; throw new CollectionOverflowException(Count);
} }
_collection.Add(obj); _collection.Add(obj);
@ -43,9 +46,15 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
if (Count == _maxCount || position < 0 || position > Count) // TODO выброс ошибки, если выход за границы списка
// TODO выброс ошибки, если переполнение
if (position < 0 || position > Count)
{ {
return -1; throw new PositionOutOfCollectionException(position);
}
if (Count == _maxCount)
{
throw new CollectionOverflowException(Count);
} }
_collection.Insert(position, obj); _collection.Insert(position, obj);
@ -54,14 +63,14 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public T? Remove(int position) public T? Remove(int position)
{ {
// TODO выброс ошибки, если выход за границы списка
if (position < 0 || position > Count) if (position < 0 || position > Count)
{ {
return null; throw new PositionOutOfCollectionException(position);
} }
T? obj = _collection[position]; T? obj = _collection[position];
_collection.RemoveAt(position); _collection.RemoveAt(position);
return obj; return obj;
} }

View File

@ -1,4 +1,5 @@
using ProjectPlane.Drawnings; using ProjectPlane.Drawnings;
using ProjectPlane.Exceptions;
namespace ProjectPlane.CollectionGenericObjects; namespace ProjectPlane.CollectionGenericObjects;
@ -35,6 +36,8 @@ public class Marina : AbstractCompany
int m = 0; int m = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++) for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
try
{ {
if (_collection?.Get(i) != null) if (_collection?.Get(i) != null)
{ {
@ -53,5 +56,11 @@ public class Marina : AbstractCompany
m++; m++;
} }
} }
catch(ObjectNotFoundException)
{
break;
}
}
} }
} }

View File

@ -1,4 +1,6 @@
namespace ProjectPlane.CollectionGenericObjects; using ProjectPlane.Exceptions;
namespace ProjectPlane.CollectionGenericObjects;
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class where T : class
@ -36,15 +38,23 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position) public T? Get(int position)
{ {
if (position < 0 || position > Count) // TODO выброс ошибки, если выход за границы массива
// TODO выброс ошибки, если объект пустой
if (position < 0 || position >= Count)
{ {
return null; throw new PositionOutOfCollectionException(position);
} }
if (_collection[position] == null)
{
throw new ObjectNotFoundException(position);
}
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj)
{ {
// TODO выброс ошибки, если переполнение
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
if (_collection[i] == null) if (_collection[i] == null)
@ -53,14 +63,17 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
return i; return i;
} }
} }
return -1;
throw new CollectionOverflowException(Count);
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
if (position < 0 || position > Count) // TODO выброс ошибки, если выход за границы массива
// TODO выброс ошибки, если переполнение
if (position < 0 || position >= Count)
{ {
return -1; throw new PositionOutOfCollectionException(position);
} }
if (_collection[position] == null) if (_collection[position] == null)
@ -74,7 +87,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
if (_collection[i] == null) if (_collection[i] == null)
{ {
_collection[i] = obj; _collection[i] = obj;
return position; return i;
} }
} }
@ -83,18 +96,24 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
if (_collection[i] == null) if (_collection[i] == null)
{ {
_collection[i] = obj; _collection[i] = obj;
return position; return i;
} }
} }
return -1; throw new CollectionOverflowException(Count);
} }
public T? Remove(int position) public T? Remove(int position)
{ {
if (position < 0 || position > Count || _collection[position] == null) // TODO выброс ошибки, если выход за границы массива
// TODO выброс ошибки, если объект пустой
if (position < 0 || position >= Count)
{ {
return null; throw new PositionOutOfCollectionException(position);
}
if (_collection[position] == null)
{
throw new ObjectNotFoundException(position);
} }
T? obj = _collection[position]; T? obj = _collection[position];

View File

@ -1,4 +1,5 @@
using ProjectPlane.Drawnings; using ProjectPlane.Drawnings;
using ProjectPlane.Exceptions;
using System.Text; using System.Text;
namespace ProjectPlane.CollectionGenericObjects; namespace ProjectPlane.CollectionGenericObjects;
@ -62,115 +63,111 @@ public class StorageCollection<T>
_storages.Remove(name); _storages.Remove(name);
} }
public bool SaveData(string filename) public void SaveData(string filename)
{ {
if (_storages.Count == 0) if (_storages.Count == 0)
{ {
return false; throw new NullReferenceException("В хранилище отсутствуют коллекции для сохранения");
} }
if (File.Exists(filename)) if (File.Exists(filename))
{ {
File.Delete(filename); File.Delete(filename);
} }
StringBuilder sb = new(); using (StreamWriter sw = new StreamWriter(filename))
sb.Append(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in
_storages)
{ {
sb.Append(Environment.NewLine); sw.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
sw.Write(Environment.NewLine);
// не сохраняем пустые коллекции // не сохраняем пустые коллекции
if (value.Value.Count == 0) if (value.Value.Count == 0)
{ {
continue; continue;
} }
sb.Append(value.Key); sw.Write(value.Key);
sb.Append(_separatorForKeyValue); sw.Write(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType); sw.Write(value.Value.GetCollectionType);
sb.Append(_separatorForKeyValue); sw.Write(_separatorForKeyValue);
sb.Append(value.Value.MaxCount); sw.Write(value.Value.MaxCount);
sb.Append(_separatorForKeyValue); sw.Write(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems()) foreach (T? item in value.Value.GetItems())
{ {
string data = item?.GetDataForSave() ?? string.Empty; string data = item?.GetDataForSave() ?? string.Empty;
if (string.IsNullOrEmpty(data)) if (string.IsNullOrEmpty(data))
{ {
continue; continue;
} }
sb.Append(data); sw.Write(data);
sb.Append(_separatorItems); sw.Write(_separatorItems);
}
} }
} }
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
fs.Write(info, 0, info.Length);
return true;
} }
public bool LoadData(string filename) public void LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ {
return false; throw new FileNotFoundException("Файл не существует");
} }
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open)) using (StreamReader sr = new(filename))
{ {
byte[] b = new byte[fs.Length]; string line = sr.ReadLine();
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0) if (line == null || line.Length == 0)
{ {
bufferTextFromFile += temp.GetString(b); throw new FileFormatException("В файле нет данных");
} }
} if (!line.Equals(_collectionKey))
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{ {
return false; throw new FileFormatException("В файле неверные данные");
}
if (!strs[0].Equals(_collectionKey))
{
//если нет такой записи, то это не те данные
return false;
} }
_storages.Clear(); _storages.Clear();
foreach (string data in strs) while ((line = sr.ReadLine()) != null)
{ {
string[] record = data.Split(_separatorForKeyValue, string[] record = line.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4) if (record.Length != 4)
{ {
continue; continue;
} }
CollectionType collectionType =
(CollectionType)Enum.Parse(typeof(CollectionType), record[1]); CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects<T>? collection = ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
StorageCollection<T>.CreateCollection(collectionType);
if (collection == null) if (collection == null)
{ {
return false; throw new InvalidOperationException("Не удалось создать коллекцию");
} }
collection.MaxCount = Convert.ToInt32(record[2]); collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set) foreach (string elem in set)
{ {
if (elem?.CreateDrawningShip() is T ship) if (elem?.CreateDrawningShip() is T ship)
{
try
{ {
if (collection.Insert(ship) == -1) if (collection.Insert(ship) == -1)
{ {
return false; throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch (CollectionOverflowException ex)
{
throw new OverflowException("Коллекция переполнена", ex);
} }
} }
} }
_storages.Add(record[0], collection); _storages.Add(record[0], collection);
} }
return true; }
} }
public ICollectionGenericObjects<T>? this[string name] public ICollectionGenericObjects<T>? this[string name]

View File

@ -0,0 +1,15 @@
using System.Runtime.Serialization;
namespace ProjectPlane.Exceptions;
/// <summary>
/// Класс, описывающий ошибку переполнения коллекции
/// </summary>
[Serializable]
internal class CollectionOverflowException : ApplicationException
{
public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { }
public CollectionOverflowException() : base() { }
public CollectionOverflowException(string message) : base(message) { }
public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}

View File

@ -0,0 +1,15 @@
using System.Runtime.Serialization;
namespace ProjectPlane.Exceptions;
/// <summary>
/// Класс, описывающий ошибку, что по указанной позиции нет элемента
/// </summary>
[Serializable]
internal class ObjectNotFoundException : ApplicationException
{
public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { }
public ObjectNotFoundException() : base() { }
public ObjectNotFoundException(string message) : base(message) { }
public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { }
protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}

View File

@ -0,0 +1,15 @@
using System.Runtime.Serialization;
namespace ProjectPlane.Exceptions;
/// <summary>
/// Класс, описывающий ошибку выхода за границы коллекции
/// </summary>
[Serializable]
internal class PositionOutOfCollectionException : ApplicationException
{
public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции.Позиция " + i) { }
public PositionOutOfCollectionException() : base() { }
public PositionOutOfCollectionException(string message) : base(message) { }
public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { }
protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}

View File

@ -66,9 +66,9 @@
groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(ComboBoxSelectorCompany); groupBoxTools.Controls.Add(ComboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(785, 24); groupBoxTools.Location = new Point(853, 24);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(200, 672); groupBoxTools.Size = new Size(200, 692);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
@ -248,7 +248,7 @@
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24); pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(785, 672); pictureBox.Size = new Size(853, 692);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
@ -257,7 +257,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(985, 24); menuStrip.Size = new Size(1053, 24);
menuStrip.TabIndex = 2; menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip"; menuStrip.Text = "menuStrip";
// //
@ -288,7 +288,7 @@
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(985, 696); ClientSize = new Size(1053, 716);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Controls.Add(menuStrip); Controls.Add(menuStrip);

View File

@ -1,5 +1,7 @@
using ProjectPlane.CollectionGenericObjects; using ProjectPlane.CollectionGenericObjects;
using ProjectPlane.Drawnings; using ProjectPlane.Drawnings;
using ProjectPlane.Exceptions;
using Microsoft.Extensions.Logging;
namespace ProjectPlane; namespace ProjectPlane;
@ -9,10 +11,13 @@ public partial class FormShipCollection : Form
private AbstractCompany? _company = null; private AbstractCompany? _company = null;
public FormShipCollection() private readonly ILogger _logger;
public FormShipCollection(ILogger<FormShipCollection> logger)
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new(); _storageCollection = new();
_logger = logger;
} }
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
@ -28,6 +33,8 @@ public partial class FormShipCollection : Form
} }
private void SetShip(DrawningShip? ship) private void SetShip(DrawningShip? ship)
{
try
{ {
if (_company == null || ship == null) if (_company == null || ship == null)
{ {
@ -37,11 +44,14 @@ public partial class FormShipCollection : Form
if (_company + ship != -1) if (_company + ship != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
_logger.LogInformation($"Добавлен объект {ship.GetDataForSave()}");
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
} }
else }
catch (CollectionOverflowException ex)
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show(ex.Message);
_logger.LogWarning($"Ошибка: {ex.Message}");
} }
} }
@ -58,15 +68,25 @@ public partial class FormShipCollection : Form
return; return;
} }
try
{
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null) if (_company - pos != null)
{ {
MessageBox.Show("Объект удалён"); MessageBox.Show("Объект удален");
_logger.LogInformation($"Удален объект по позиции {pos}");
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
} }
else }
catch (ObjectNotFoundException ex)
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show(ex.Message);
_logger.LogError($"Ошибка: {ex.Message}");
}
catch (PositionOutOfCollectionException ex)
{
MessageBox.Show(ex.Message);
_logger.LogError($"Ошибка: {ex.Message}");
} }
} }
@ -192,15 +212,16 @@ public partial class FormShipCollection : Form
{ {
if (saveFileDialog.ShowDialog() == DialogResult.OK) if (saveFileDialog.ShowDialog() == DialogResult.OK)
{ {
if (_storageCollection.SaveData(saveFileDialog.FileName)) try
{ {
MessageBox.Show("Сохранение прошло успешно", _storageCollection.SaveData(saveFileDialog.FileName);
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
} }
else catch (Exception ex)
{ {
MessageBox.Show("Не сохранилось", "Результат", MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.LogError("Ошибка: {Message}", ex.Message);
} }
} }
} }
@ -209,16 +230,17 @@ public partial class FormShipCollection : Form
{ {
if (openFileDialog.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
{ {
if (_storageCollection.LoadData(openFileDialog.FileName)) try
{ {
MessageBox.Show("Загрузка прошла успешно", _storageCollection.LoadData(openFileDialog.FileName);
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems(); RerfreshListBoxItems();
_logger.LogInformation("Загрузка из фала: {filename}", openFileDialog.FileName);
} }
else catch (Exception ex)
{ {
MessageBox.Show("Не загрузилось", "Результат", MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.LogError("Ошибка: {Message}", ex.Message);
} }
} }
} }

View File

@ -1,3 +1,8 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
namespace ProjectPlane namespace ProjectPlane
{ {
internal static class Program internal static class Program
@ -8,10 +13,28 @@ namespace ProjectPlane
[STAThread] [STAThread]
static void Main() static void Main()
{ {
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormShipCollection());
ServiceCollection services = new();
ConfigureServices(services);
using ServiceProvider serviceProvider = services.BuildServiceProvider();
Application.Run(serviceProvider.GetRequiredService<FormShipCollection>());
}
private static void ConfigureServices(ServiceCollection services)
{
services
.AddSingleton<FormShipCollection>()
.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
var config = new ConfigurationBuilder()
.AddJsonFile("serilogConfig.json", optional: false, reloadOnChange: true)
.Build();
option.AddSerilog(Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(config)
.CreateLogger());
});
} }
} }
} }

View File

@ -8,6 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.10" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
@ -23,4 +36,10 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="serilogConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -1,5 +0,0 @@
using ProjectPlane.Drawnings;
namespace ProjectPlane;
public delegate void ShipDelegate(DrawningShip ship);

View File

@ -0,0 +1,35 @@
2024-05-05 19:31:54.5854 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:37:42.0203 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:37:45.8102 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:37:49.7304 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:37:53.9630 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:White:Black:False:False
2024-05-05 19:37:57.7237 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:01.6675 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:06.7083 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:11.3735 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:15.1331 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:20.0620 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:24.7261 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:31.0722 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:34.3915 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:38:40.7924 | WARNING | ProjectPlane.FormShipCollection | Ошибка: В коллекции превышено допустимое количество: 13
2024-05-05 19:44:19.0599 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:44:23.5467 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:46:35.2923 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:46:39.0113 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:46:41.8356 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:46:45.7168 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:46:49.4368 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:46:52.7510 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:46:57.4698 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:00.6705 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:03.5259 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:06.1029 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:09.0793 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:11.9753 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:15.0238 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:18.0164 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:21.2964 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:White
2024-05-05 19:47:26.9699 | WARNING | ProjectPlane.FormShipCollection | Ошибка: В коллекции превышено допустимое количество: 15
2024-05-05 19:47:37.1140 | INFORMATION | ProjectPlane.FormShipCollection | Удален объект по позиции 5
2024-05-05 19:47:41.2912 | ERROR | ProjectPlane.FormShipCollection | Ошибка: Не найден объект по позиции 5

View File

@ -0,0 +1,25 @@
{
"AllowedHosts": "*",
"Serilog": {
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "C:\\Users\\rozko\\\\Documents\\Labs_OOP\\ProjectPlane\\ProjectPlane\\log.txt",
Review

Путь до файла логов не должен быть абсолютным

Путь до файла логов не должен быть абсолютным
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.ffff} | {Level:u} | {SourceContext} | {Message:1j}{NewLine}{Exception}"
}
}
]
}
}