8 Commits

Author SHA1 Message Date
d499114437 fix conflict 2024-05-20 09:50:56 +04:00
bd98017e3a fix conflicts 2024-05-17 11:57:01 +04:00
f068f2ed13 LabWork08 2024-05-16 12:18:51 +04:00
181f1c8dff LabWork08 2024-05-16 12:16:23 +04:00
e5657c372e LabWork07 2024-05-02 11:55:16 +04:00
1597553ddc LabWork07 2024-05-02 11:23:05 +04:00
246c2ee2c2 LabWork07 2024-05-02 10:05:13 +04:00
83c9dfd598 LabWork07 2024-05-01 21:23:16 +04:00
32 changed files with 636 additions and 282 deletions

View File

@@ -1,4 +1,5 @@
using ProjectMotorboat.Drownings;
using ProjectMotorboat.Exceptions;
namespace ProjectMotorboat.CollectionGenericObjects;
@@ -15,9 +16,8 @@ public abstract class AbstractCompany
protected ICollectionGenericObjects<DrawningBoat>? _collection = null;
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection)
{
_pictureWidth = picWidth;
@@ -27,7 +27,7 @@ public abstract class AbstractCompany
}
public static int operator +(AbstractCompany company, DrawningBoat boat)
{
return company._collection.Insert(boat);
return company._collection.Insert(boat, new DrawningBoatEqutables());
}
public static DrawningBoat operator -(AbstractCompany company, int position)
@@ -48,12 +48,20 @@ public abstract class AbstractCompany
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;
}
public void Sort(IComparer<DrawningBoat?> comparer) => _collection?.CollectionSort(comparer);
protected abstract void DrawBackgound(Graphics g);
protected abstract void SetObjectsPosition();

View File

@@ -0,0 +1,45 @@
namespace ProjectMotorboat.CollectionGenericObjects;
public class CollectionInfo : IEquatable<CollectionInfo>
{
public string Name { get; private set; }
public CollectionType CollectionType { get; private set; }
public string Description { get; private set; }
private static readonly string _separator = "-";
public CollectionInfo(string name, CollectionType collectionType, string description)
{
Name = name;
CollectionType = collectionType;
Description = description;
}
public static CollectionInfo? GetCollectionInfo(string data)
{
string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (strs.Length < 1 || strs.Length > 3)
{
return null;
}
return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]),
strs.Length > 2 ? strs[2] : string.Empty);
}
public override string ToString()
{
return Name + _separator + CollectionType + _separator + Description;
}
public bool Equals(CollectionInfo? other)
{
return Name == other?.Name;
}
public override bool Equals(object? obj)
{
return Equals(obj as CollectionInfo);
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
}

View File

@@ -1,9 +1,6 @@

namespace ProjectMotorboat.CollectionGenericObjects;
namespace ProjectMotorboat.CollectionGenericObjects;
public enum CollectionType
{
None = 0,
Massive = 1,
List = 2

View File

@@ -1,9 +1,7 @@

using ProjectMotorboat.Drownings;
using ProjectMotorboat.Drownings;
using ProjectMotorboat.Exceptions;
namespace ProjectMotorboat.CollectionGenericObjects;
public class HarborService : AbstractCompany
{
public HarborService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) : base(picWidth, picHeight, collection)
@@ -36,12 +34,13 @@ public class HarborService : 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 * boatWidth + 20, boatHeight * _placeSizeHeight + 20);
}
catch (ObjectNotFoundException) { }
catch (PositionOutOfCollectionException e) { }
if (boatWidth < width - 1)
boatWidth++;
else

View File

@@ -1,5 +1,4 @@

namespace ProjectMotorboat.CollectionGenericObjects;
namespace ProjectMotorboat.CollectionGenericObjects;
public interface ICollectionGenericObjects<T>
@@ -7,11 +6,12 @@ public interface ICollectionGenericObjects<T>
{
int Count { get; }
int MaxCount { get; set; }
int Insert(T obj);
int Insert(T obj, int position);
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
T Remove(int position);
T? Get(int position);
CollectionType GetCollectionType { get; }
IEnumerable<T> GetItems();
void CollectionSort(IComparer<T?> comparer);
}

View File

@@ -1,13 +1,16 @@
namespace ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Exceptions;
namespace ProjectMotorboat.CollectionGenericObjects;
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
private readonly List<T?> _collection;
public CollectionType GetCollectionType => CollectionType.List;
private int _maxCount;
public int Count => _collection.Count;
@@ -32,33 +35,56 @@ where T : class
_collection = new();
}
public T? Get(int position)
public T Get(int position)
{
if (position >= Count || position < 0) return null;
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
return _collection[position];
}
public int Insert(T obj)
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
{
if (Count + 1 > _maxCount) return -1;
if (comparer != null)
{
if (_collection.Contains(obj, comparer))
{
throw new CollectionOverflowException();
}
}
if (Count == _maxCount)
{
throw new CollectionOverflowException(Count);
}
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
{
if (Count + 1 > _maxCount) return -1;
if (position < 0 || position > Count) return -1;
if (comparer != null)
{
if (_collection.Contains(obj, comparer))
{
throw new CollectionOverflowException();
}
}
if (Count == _maxCount)
{
throw new CollectionOverflowException(Count);
}
if (position >= Count || position < 0)
{
throw new PositionOutOfCollectionException(position);
}
_collection.Insert(position, obj);
return 1;
return position;
}
public T? Remove(int position)
public T Remove(int position)
{
if (position < 0 || position > Count) return null;
T? pos = _collection[position];
if (position >= _collection.Count || position < 0) throw new PositionOutOfCollectionException(position);
T obj = _collection[position];
_collection.RemoveAt(position);
return pos;
return obj;
}
public IEnumerable<T> GetItems()
@@ -68,4 +94,8 @@ where T : class
yield return _collection[i];
}
}
public void CollectionSort(IComparer<T?> comparer)
{
_collection.Sort(comparer);
}
}

View File

@@ -1,4 +1,6 @@
namespace ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Exceptions;
namespace ProjectMotorboat.CollectionGenericObjects;
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
@@ -38,15 +40,34 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position)
{
if (position < 0 || position >= _collection.Length)
{
return null;
}
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)
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
{
for (int i = 0; i < _collection.Length; i++)
return Insert(obj, 0, comparer);
}
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
{
if (position < 0 || position >= Count)
{
throw new PositionOutOfCollectionException(position);
}
if (comparer != null)
{
if (_collection.Contains(obj, comparer))
{
throw new CollectionOverflowException();
}
}
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
for (int i = position + 1; i < Count; i++)
{
if (_collection[i] == null)
{
@@ -54,52 +75,26 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
return i;
}
}
return -1;
}
public int Insert(T obj, int position)
{
if (position < 0 || position >= _collection.Length) { return position; }
if (_collection[position] == null)
for (int i = position - 1; i >= 0; i--)
{
_collection[position] = obj;
return position;
}
else
{
for (int i = position + 1; i < _collection.Length; i++)
if (_collection[i] == null)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
for (int i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
_collection[i] = obj;
return i;
}
}
return -1;
throw new CollectionOverflowException(Count);
}
public T Remove(int position)
{
if (position < 0 || position >= _collection.Length)
{
return null;
}
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
T? obj = _collection[position];
if (_collection[position] == null) throw new ObjectNotFoundException(position);
T? temp = _collection[position];
_collection[position] = null;
return obj;
return temp;
}
public IEnumerable<T> GetItems()
@@ -109,7 +104,12 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
yield return _collection[i];
}
}
public void CollectionSort(IComparer<T?> comparer)
{
Array.Sort(_collection, comparer);
}
}

View File

@@ -1,56 +1,57 @@
using ProjectMotorboat.Drownings;
using System.Text;
using ProjectMotorboat.Exceptions;
namespace ProjectMotorboat.CollectionGenericObjects;
public class StorageCollection<T>
where T : DrawningBoat
{
private Dictionary<string, ICollectionGenericObjects<T>> _storages;
private Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
public List<string> Keys => _storages.Keys.ToList();
public List<CollectionInfo> Keys => _storages.Keys.ToList();
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
}
public void AddCollection(string name, CollectionType collectionType)
{
if (name == null || _storages.ContainsKey(name)) { return; }
switch (collectionType)
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
if (_storages.ContainsKey(collectionInfo))
{
case CollectionType.None:
return;
case CollectionType.Massive:
_storages[name] = new MassiveGenericObjects<T>();
return;
case CollectionType.List:
_storages[name] = new ListGenericObjects<T>();
return;
return;
}
if (collectionType == CollectionType.None)
{
return;
}
else if (collectionType == CollectionType.Massive)
{
_storages[collectionInfo] = new MassiveGenericObjects<T>();
}
else if (collectionType == CollectionType.List)
{
_storages[collectionInfo] = new ListGenericObjects<T>();
}
}
public void DelCollection(string name)
{
if (_storages.ContainsKey(name))
_storages.Remove(name);
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
if (_storages.ContainsKey(collectionInfo))
{
_storages.Remove(collectionInfo);
}
}
public ICollectionGenericObjects<T>? this[string name]
{
get
{
if (name == null || !_storages.ContainsKey(name)) { return null; }
return _storages[name];
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
if (_storages.ContainsKey(collectionInfo))
{
return _storages[collectionInfo];
}
return null;
}
}
@@ -59,13 +60,11 @@ public class StorageCollection<T>
private readonly string _separatorForKeyValue = "|";
private readonly string _separatorItems = ";";
public bool SaveData(string filename)
public void SaveData(string filename)
{
if (_storages.Count == 0)
{
return false;
throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
}
if (File.Exists(filename))
@@ -76,21 +75,18 @@ public class StorageCollection<T>
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
{
StringBuilder sb = new();
sb.Append(Environment.NewLine);
writer.Write(Environment.NewLine);
if (value.Value.Count == 0)
{
continue;
}
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
writer.Write(value.Key);
writer.Write(_separatorForKeyValue);
writer.Write(value.Value.MaxCount);
writer.Write(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
@@ -98,67 +94,72 @@ public class StorageCollection<T>
{
continue;
}
sb.Append(data);
sb.Append(_separatorItems);
writer.Write(data);
writer.Write(_separatorItems);
}
writer.Write(sb);
}
}
return true;
}
public bool LoadData(string filename)
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
throw new FileNotFoundException("Файл не существует");
}
using (StreamReader fs = File.OpenText(filename))
using (StreamReader read = File.OpenText(filename))
{
string str = fs.ReadLine();
string str = read.ReadLine();
if (str == null || str.Length == 0)
{
return false;
throw new FormatException("В файле нет данных");
}
if (!str.StartsWith(_collectionKey))
{
return false;
throw new FormatException("В файле неверные данные");
}
_storages.Clear();
string strs = "";
while ((strs = fs.ReadLine()) != null)
while ((strs = read.ReadLine()) != null)
{
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
if (record.Length != 3)
{
continue;
}
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null)
{
return false;
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
throw new InvalidOperationException("Не удалось создать коллекцию");
collection.MaxCount = Convert.ToInt32(record[1]);
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningBoat() is T boat)
{
if (collection.Insert(boat) == -1)
try
{
return false;
if (collection.Insert(boat) == -1)
{
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch (CollectionOverflowException ex)
{
throw new CollectionOverflowException("Коллекция переполнена", ex);
}
}
}
_storages.Add(record[0], collection);
_storages.Add(collectionInfo, collection);
}
return true;
}
}
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
{
return collectionType switch

View File

@@ -1,5 +1,4 @@

namespace ProjectMotorboat.Drownings
namespace ProjectMotorboat.Drownings
{
public enum DirectionType
{

View File

@@ -108,14 +108,14 @@ public class DrawningBoat
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX.Value - EntityBoat.Step > 0)
{
_startPosX -= (int)EntityBoat.Step;
}
return true;
case DirectionType.Up:
if (_startPosY.Value - EntityBoat.Step > 0)
{
@@ -129,7 +129,7 @@ public class DrawningBoat
_startPosX += (int)EntityBoat.Step;
}
return true;
case DirectionType.Down:
if (_startPosY.Value + EntityBoat.Step + _drawningBoatHeight < _pictureHeight)
{
@@ -140,8 +140,6 @@ public class DrawningBoat
return false;
}
}
public virtual void DrawTransport(Graphics g)
{
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
@@ -149,7 +147,7 @@ public class DrawningBoat
Pen pen = new(Color.Black);
Brush mainBrush = new SolidBrush(EntityBoat.BodyColor);
Point[] hull = new Point[]
{
new Point(_startPosX.Value + 5, _startPosY.Value + 0),
@@ -161,6 +159,7 @@ public class DrawningBoat
g.FillPolygon(mainBrush, hull);
g.DrawPolygon(pen, hull);
Brush blockBrush = new SolidBrush(EntityBoat.BodyColor);
g.FillRectangle(blockBrush, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40);
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40);

View File

@@ -0,0 +1,30 @@
namespace ProjectMotorboat.Drownings;
public class DrawningBoatCompareByColor : IComparer<DrawningBoat?>
{
public int Compare(DrawningBoat? x, DrawningBoat? y)
{
if (x == null || x.EntityBoat == null)
{
return -1;
}
if (y == null || y.EntityBoat == null)
{
return 1;
}
if (x.EntityBoat.BodyColor.Name != y.EntityBoat.BodyColor.Name)
{
return x.EntityBoat.BodyColor.Name.CompareTo(y.EntityBoat.BodyColor.Name);
}
var speedCompare = x.EntityBoat.Speed.CompareTo(y.EntityBoat.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityBoat.Weight.CompareTo(y.EntityBoat.Weight);
}
}

View File

@@ -0,0 +1,30 @@
namespace ProjectMotorboat.Drownings;
public class DrawningBoatCompareByType : IComparer<DrawningBoat?>
{
public int Compare(DrawningBoat? x, DrawningBoat? y)
{
if (x == null || x.EntityBoat == null)
{
return -1;
}
if (y == null || y.EntityBoat == null)
{
return 1;
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityBoat.Speed.CompareTo(y.EntityBoat.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityBoat.Weight.CompareTo(y.EntityBoat.Weight);
}
}

View File

@@ -0,0 +1,66 @@
using ProjectMotorboat.Entities;
using System.Diagnostics.CodeAnalysis;
namespace ProjectMotorboat.Drownings;
public class DrawningBoatEqutables : IEqualityComparer<DrawningBoat>
{
public bool Equals(DrawningBoat? x, DrawningBoat? y)
{
if (x == null || x.EntityBoat == null)
{
return false;
}
if (y == null || y.EntityBoat == null)
{
return false;
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityBoat.Speed != y.EntityBoat.Speed)
{
return false;
}
if (x.EntityBoat.Weight != y.EntityBoat.Weight)
{
return false;
}
if (x.EntityBoat.BodyColor != y.EntityBoat.BodyColor)
{
return false;
}
if (x is DrawningMotorboat && y is DrawningMotorboat)
{
EntityMotorboat EntityX = (EntityMotorboat)x.EntityBoat;
EntityMotorboat EntityY = (EntityMotorboat)y.EntityBoat;
if (EntityX.Glass != EntityY.Glass)
{
return false;
}
if (EntityX.Motor != EntityY.Motor)
{
return false;
}
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
{
return false;
}
}
return true;
}
public int GetHashCode([DisallowNull] DrawningBoat obj)
{
return obj.GetHashCode();
}
}

View File

@@ -1,5 +1,4 @@
using ProjectMotorboat.Entities;
namespace ProjectMotorboat.Drownings;
public class DrawningMotorboat : DrawningBoat
@@ -26,15 +25,12 @@ public class DrawningMotorboat : DrawningBoat
Brush additionalBrush = new SolidBrush(motorboat.AdditionalColor);
base.DrawTransport(g);
if (motorboat.Glass)
{
Brush glassBrush = new SolidBrush(Color.LightBlue);
g.FillEllipse(glassBrush, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40);
}
if (motorboat.Motor)
{
Brush engineBrush = new

View File

@@ -1,9 +1,9 @@
using ProjectMotorboat.Entities;
namespace ProjectMotorboat.Drownings;
public static class ExtentionDrawningBoat
{
private static readonly string _separatorForObject = ":";
public static DrawningBoat? CreateDrawningBoat(this string info)
{
string[] strs = info.Split(_separatorForObject);

View File

@@ -1,5 +1,4 @@
namespace ProjectMotorboat.Entities;
public class EntityBoat
{
public int Speed { get; private set; }

View File

@@ -0,0 +1,18 @@

using System.Runtime.Serialization;
namespace ProjectMotorboat.Exceptions;
[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 ProjectMotorboat.Exceptions;
[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,17 @@
using System.Runtime.Serialization;
namespace ProjectMotorboat.Exceptions;
[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

@@ -52,6 +52,8 @@
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
buttonSortByColor = new Button();
buttonSortByType = new Button();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
@@ -66,15 +68,17 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(1096, 28);
groupBoxTools.Location = new Point(967, 28);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(231, 793);
groupBoxTools.Size = new Size(231, 681);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonSortByColor);
panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(buttonAddBoat);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonRefresh);
@@ -82,17 +86,17 @@
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 486);
panelCompanyTools.Location = new Point(3, 359);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(225, 304);
panelCompanyTools.Size = new Size(225, 319);
panelCompanyTools.TabIndex = 7;
//
// buttonAddBoat
//
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBoat.Location = new Point(6, 7);
buttonAddBoat.Location = new Point(3, 3);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(219, 54);
buttonAddBoat.Size = new Size(219, 30);
buttonAddBoat.TabIndex = 1;
buttonAddBoat.Text = "Добавление лодки";
buttonAddBoat.UseVisualStyleBackColor = true;
@@ -100,7 +104,7 @@
//
// maskedTextBox
//
maskedTextBox.Location = new Point(3, 67);
maskedTextBox.Location = new Point(3, 39);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(219, 27);
@@ -110,9 +114,9 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(3, 220);
buttonRefresh.Location = new Point(3, 156);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(219, 54);
buttonRefresh.Size = new Size(219, 31);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -121,9 +125,9 @@
// buttonDelBoat
//
buttonDelBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBoat.Location = new Point(3, 100);
buttonDelBoat.Location = new Point(3, 72);
buttonDelBoat.Name = "buttonDelBoat";
buttonDelBoat.Size = new Size(222, 54);
buttonDelBoat.Size = new Size(222, 37);
buttonDelBoat.TabIndex = 4;
buttonDelBoat.Text = "удалить лодку";
buttonDelBoat.UseVisualStyleBackColor = true;
@@ -132,9 +136,9 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(3, 160);
buttonGoToCheck.Location = new Point(3, 115);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(219, 54);
buttonGoToCheck.Size = new Size(219, 35);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -142,7 +146,7 @@
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(6, 383);
buttonCreateCompany.Location = new Point(3, 324);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(222, 29);
buttonCreateCompany.TabIndex = 8;
@@ -162,12 +166,12 @@
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 23);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(225, 320);
panelStorage.Size = new Size(225, 261);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(0, 251);
buttonCollectionDel.Location = new Point(0, 220);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(222, 29);
buttonCollectionDel.TabIndex = 6;
@@ -178,14 +182,14 @@
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.Location = new Point(3, 141);
listBoxCollection.Location = new Point(3, 130);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(213, 104);
listBoxCollection.Size = new Size(213, 84);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 106);
buttonCollectionAdd.Location = new Point(0, 95);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(222, 29);
buttonCollectionAdd.TabIndex = 4;
@@ -196,7 +200,7 @@
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(121, 76);
radioButtonList.Location = new Point(136, 65);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(80, 24);
radioButtonList.TabIndex = 3;
@@ -207,7 +211,7 @@
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(13, 76);
radioButtonMassive.Location = new Point(14, 65);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(82, 24);
radioButtonMassive.TabIndex = 2;
@@ -217,7 +221,7 @@
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(3, 43);
textBoxCollectionName.Location = new Point(3, 32);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(219, 27);
textBoxCollectionName.TabIndex = 1;
@@ -225,7 +229,7 @@
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(43, 20);
labelCollectionName.Location = new Point(31, 9);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(158, 20);
labelCollectionName.TabIndex = 0;
@@ -237,7 +241,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 349);
comboBoxSelectorCompany.Location = new Point(6, 290);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(213, 28);
comboBoxSelectorCompany.TabIndex = 0;
@@ -248,7 +252,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 28);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(1096, 793);
pictureBox.Size = new Size(967, 681);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -258,7 +262,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1327, 28);
menuStrip.Size = new Size(1198, 28);
menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip";
//
@@ -289,11 +293,33 @@
//
saveFileDialog.Filter = "txt file | *.txt";
//
// buttonSortByColor
//
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonSortByColor.Location = new Point(3, 259);
buttonSortByColor.Name = "buttonSortByColor";
buttonSortByColor.Size = new Size(219, 31);
buttonSortByColor.TabIndex = 8;
buttonSortByColor.Text = "Сортировка по цвету";
buttonSortByColor.UseVisualStyleBackColor = true;
buttonSortByColor.Click += ButtonSortByColor_Click;
//
// buttonSortByType
//
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonSortByType.Location = new Point(3, 218);
buttonSortByType.Name = "buttonSortByType";
buttonSortByType.Size = new Size(219, 35);
buttonSortByType.TabIndex = 7;
buttonSortByType.Text = "Сортировка по типу";
buttonSortByType.UseVisualStyleBackColor = true;
buttonSortByType.Click += ButtonSortByType_Click;
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1327, 821);
ClientSize = new Size(1198, 709);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
@@ -338,5 +364,7 @@
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@@ -1,48 +1,61 @@
using ProjectMotorboat.CollectionGenericObjects;
using Microsoft.Extensions.Logging;
using ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Drownings;
namespace ProjectMotorboat;
public partial class FormBoatCollection : Form
{
private readonly StorageCollection<DrawningBoat> _storageCollection;
private AbstractCompany? _company = null;
public FormBoatCollection()
private readonly ILogger _logger;
public FormBoatCollection(ILogger<FormBoatCollection> logger)
{
InitializeComponent();
_storageCollection = new();
_logger = logger;
_logger.LogInformation("Форма загрузилась");
}
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
panelCompanyTools.Enabled = false;
}
private void ButtonAddBoat_Click(object sender, EventArgs e)
{
FormBoatConfig form = new();
form.Show();
form.AddEvent(SetBoat);
form.Show();
}
private void SetBoat(DrawningBoat? boat)
private void SetBoat(DrawningBoat boat)
{
if (_company == null || boat == null)
{
return;
}
if (_company + boat != -1)
try
{
var res = _company + boat;
MessageBox.Show("Объект добавлен");
_logger.LogInformation($"Объект добавлен под индексом {res}");
pictureBox.Image = _company.Show();
}
else
catch (Exception ex)
{
MessageBox.Show("Не удалось добавить объект");
MessageBox.Show($"Такой объект уже присутствует в коллекции", "Результат", MessageBoxButtons.OK,
MessageBoxIcon.Error);
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
}
}
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
@@ -50,23 +63,30 @@ public partial class FormBoatCollection : Form
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos != null)
try
{
var res = _company - pos;
MessageBox.Show("Объект удален");
_logger.LogInformation($"Объект удален под индексом {pos}");
pictureBox.Image = _company.Show();
}
else
catch (Exception ex)
{
MessageBox.Show("Не удалось удалить объект");
MessageBox.Show(ex.Message, "Не удалось удалить объект",
MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
}
}
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
@@ -85,12 +105,10 @@ public partial class FormBoatCollection : Form
break;
}
}
if (boat == null)
{
return;
}
FormMotorboat form = new()
{
SetBoat = boat
@@ -98,6 +116,7 @@ public partial class FormBoatCollection : Form
form.ShowDialog();
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
@@ -110,7 +129,8 @@ public partial class FormBoatCollection : Form
private void ButtonCollectionAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
if (string.IsNullOrEmpty(textBoxCollectionName.Text) ||
(!radioButtonList.Checked && !radioButtonMassive.Checked))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
@@ -126,22 +146,36 @@ public partial class FormBoatCollection : Form
collectionType = CollectionType.List;
}
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
RerfreshListBoxItems();
try
{
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
_logger.LogInformation("Добавление коллекции");
RerfreshListBoxItems();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
}
}
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedItem == null)
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
DialogResult.Yes)
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
_logger.LogInformation("Коллекция удалена");
RerfreshListBoxItems();
}
@@ -150,7 +184,7 @@ public partial class FormBoatCollection : Form
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
string? colName = _storageCollection.Keys?[i];
string? colName = _storageCollection.Keys?[i].Name;
if (!string.IsNullOrEmpty(colName))
{
listBoxCollection.Items.Add(colName);
@@ -166,7 +200,8 @@ public partial class FormBoatCollection : Form
return;
}
ICollectionGenericObjects<DrawningBoat>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
ICollectionGenericObjects<DrawningBoat>? collection =
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
@@ -177,24 +212,27 @@ public partial class FormBoatCollection : Form
{
case "Хранилище":
_company = new HarborService(pictureBox.Width, pictureBox.Height, collection);
_logger.LogInformation("Компания создана");
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.SaveData(saveFileDialog.FileName))
try
{
_storageCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
}
else
catch (Exception ex)
{
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
@@ -203,15 +241,37 @@ public partial class FormBoatCollection : Form
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.LoadData(openFileDialog.FileName))
try
{
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_storageCollection.LoadData(openFileDialog.FileName);
RerfreshListBoxItems();
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
}
else
catch (Exception ex)
{
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Загрузка не выполнена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
}
private void ButtonSortByType_Click(object sender, EventArgs e)
{
CompareBoat(new DrawningBoatCompareByType());
}
private void ButtonSortByColor_Click(object sender, EventArgs e)
{
CompareBoat(new DrawningBoatCompareByColor());
}
private void CompareBoat(IComparer<DrawningBoat?> comparer)
{
if (_company == null)
{
return;
}
_company.Sort(comparer);
pictureBox.Image = _company.Show();
}
}

View File

@@ -1,6 +1,5 @@
using ProjectMotorboat.Drownings;
using ProjectMotorboat.Entities;
namespace ProjectMotorboat
{
public partial class FormBoatConfig : Form
@@ -72,11 +71,9 @@ namespace ProjectMotorboat
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelBodyColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)

View File

@@ -1,30 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy;
namespace ProjectMotorboat.MovementStrategy;
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private StrategyStatus _state = StrategyStatus.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public StrategyStatus GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
@@ -39,7 +25,6 @@ public abstract class AbstractStrategy
FieldHeight = height;
}
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)
@@ -56,22 +41,16 @@ public abstract class AbstractStrategy
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
protected bool MoveRight() => MoveTo(MovementDirection.Right);
protected bool MoveUp() => MoveTo(MovementDirection.Up);
protected bool MoveDown() => MoveTo(MovementDirection.Down);
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != StrategyStatus.InProgress)
@@ -81,13 +60,10 @@ public abstract class AbstractStrategy
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(MovementDirection movementDirection)
{
if (_state != StrategyStatus.InProgress)

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy;
namespace ProjectMotorboat.MovementStrategy;
public interface IMoveableObject
{
@@ -12,7 +6,6 @@ public interface IMoveableObject
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool TryMoveObject(MovementDirection direction);
}

View File

@@ -1,5 +1,4 @@

namespace ProjectMotorboat.MovementStrategy;
namespace ProjectMotorboat.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()

View File

@@ -1,9 +1,4 @@
using ProjectMotorboat.Drownings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy;

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.MovementStrategy;
namespace ProjectMotorboat.MovementStrategy;
public enum MovementDirection
{

View File

@@ -1,5 +1,4 @@

namespace ProjectMotorboat.MovementStrategy;
namespace ProjectMotorboat.MovementStrategy;
public class ObjectParameters
{

View File

@@ -1,4 +1,5 @@
namespace ProjectMotorboat.MovementStrategy;

namespace ProjectMotorboat.MovementStrategy;
public enum StrategyStatus
{

View File

@@ -1,15 +1,43 @@
namespace ProjectMotorboat
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
namespace ProjectMotorboat;
internal static class Program
{
internal static class Program
[STAThread]
static void Main()
{
[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();
Application.Run(new FormBoatCollection());
Application.Run(serviceProvider.GetRequiredService<FormBoatCollection>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormBoatCollection>().AddLogging(option =>
{
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}serilogConfig.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
}

View File

@@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.3.2" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.10" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="serilogConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,20 @@
{
"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": "Motorboat"
}
}
}