diff --git a/Battleship/Battleship/Battleship.csproj b/Battleship/Battleship/Battleship.csproj
index 1a78906..835bda0 100644
--- a/Battleship/Battleship/Battleship.csproj
+++ b/Battleship/Battleship/Battleship.csproj
@@ -9,8 +9,16 @@
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs
index cb9a9d9..c438ebd 100644
--- a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -26,7 +26,7 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Сравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, IEqualityComparer comparer = null);
+ int Insert(T obj, IEqualityComparer comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -35,7 +35,7 @@ public interface ICollectionGenericObjects
/// Позиция
/// Сравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position, IEqualityComparer comparer = null);
+ int Insert(T obj, int position, IEqualityComparer comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
diff --git a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs
index 0704491..a429a02 100644
--- a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs
+++ b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs
@@ -39,10 +39,10 @@ public class ListGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj, IEqualityComparer? comparer = null)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
// TODO выброс ошибки, если такой объект есть в коллекции
- if (comparer != null && _collection.Contains(obj))
+ if (comparer != null && _collection.Contains(obj, comparer))
{
throw new CollectionAlreadyExistsException();
}
@@ -56,10 +56,10 @@ public class ListGenericObjects : ICollectionGenericObjects
return _maxCount;
}
- public int Insert(T obj, int position, IEqualityComparer? comparer = null)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
// TODO выброс ошибки, если такой объект есть в коллекции
- if (comparer != null && _collection.Contains(obj))
+ if (comparer != null && _collection.Contains(obj, comparer))
{
throw new CollectionAlreadyExistsException();
}
diff --git a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs
index 1b9f878..5d9be79 100644
--- a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -61,10 +61,10 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj, IEqualityComparer? comparer = null)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
// TODO выброс ошибки, если такой объект есть в коллекции
- if (comparer != null && _collection.Contains(obj))
+ if (comparer != null && _collection.Contains(obj, comparer))
{
throw new CollectionAlreadyExistsException();
}
@@ -82,11 +82,11 @@ public class MassiveGenericObjects : ICollectionGenericObjects
throw new CollectionOverflowException(Count);
}
- public int Insert(T obj, int position, IEqualityComparer? comparer = null)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
// TODO выброс ошибки, если такой объект есть в коллекции
- if (comparer != null && _collection.Contains(obj))
+ if (comparer != null && _collection.Contains(obj, comparer))
{
throw new CollectionAlreadyExistsException();
}
diff --git a/Battleship/Battleship/Drawings/DrawingWarshipEqutables.cs b/Battleship/Battleship/Drawings/DrawingWarshipEqutables.cs
index cb0552f..512ce10 100644
--- a/Battleship/Battleship/Drawings/DrawingWarshipEqutables.cs
+++ b/Battleship/Battleship/Drawings/DrawingWarshipEqutables.cs
@@ -34,6 +34,10 @@ public class DrawingWarshipEqutables : IEqualityComparer
{
return false;
}
+ if (x.EntityWarship.BodyColor != y.EntityWarship.BodyColor)
+ {
+ return false;
+ }
if (x is DrawingBattleship && y is DrawingBattleship)
{
diff --git a/Battleship/Battleship/Exception/CollectionAlreadyExistsException.cs b/Battleship/Battleship/Exception/CollectionAlreadyExistsException.cs
index d605e63..10e1840 100644
--- a/Battleship/Battleship/Exception/CollectionAlreadyExistsException.cs
+++ b/Battleship/Battleship/Exception/CollectionAlreadyExistsException.cs
@@ -1,5 +1,4 @@
using Battleship.CollectionGenericObjects;
-using Battleship.CollectionGenericObjects;
using System.Runtime.Serialization;
namespace Battleship.Exceptions;
@@ -11,7 +10,7 @@ namespace Battleship.Exceptions;
internal class CollectionAlreadyExistsException : ApplicationException
{
public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base("В коллекции уже есть такой элемент: " + collectionInfo) { }
- public CollectionAlreadyExistsException() : base() { }
+ public CollectionAlreadyExistsException() : base("В коллекции уже есть такой элемент") { }
public CollectionAlreadyExistsException(string message) : base(message) { }
public CollectionAlreadyExistsException(string message, Exception exception) : base(message, exception) { }
protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { }
diff --git a/Battleship/Battleship/FormWarshipCollection.cs b/Battleship/Battleship/FormWarshipCollection.cs
index d8c1a6e..0139428 100644
--- a/Battleship/Battleship/FormWarshipCollection.cs
+++ b/Battleship/Battleship/FormWarshipCollection.cs
@@ -80,7 +80,11 @@ public partial class FormWarshipCollection : Form
MessageBox.Show(ex.Message);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
-
+ catch (CollectionAlreadyExistsException ex)
+ {
+ MessageBox.Show(ex.Message);
+ _logger.LogError("Ошибка: {Message}", ex.Message);
+ }
}
///
diff --git a/Battleship/Battleship/Program.cs b/Battleship/Battleship/Program.cs
index e682443..48e655e 100644
--- a/Battleship/Battleship/Program.cs
+++ b/Battleship/Battleship/Program.cs
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using NLog.Extensions.Logging;
+using Microsoft.Extensions.Configuration;
+using Serilog;
namespace Battleship
{
@@ -27,13 +28,22 @@ namespace Battleship
///
private static void ConfigureServices(ServiceCollection services)
{
- services.AddSingleton().AddLogging(option =>
+ 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.AddNLog("nlog.config");
+ option.AddSerilog(new LoggerConfiguration()
+ .ReadFrom.Configuration(new ConfigurationBuilder()
+ .AddJsonFile($"{pathNeed}serilog.json")
+ .Build())
+ .CreateLogger());
});
}
-
-
}
}
\ No newline at end of file
diff --git a/Battleship/Battleship/serilog.json b/Battleship/Battleship/serilog.json
new file mode 100644
index 0000000..fa91ef7
--- /dev/null
+++ b/Battleship/Battleship/serilog.json
@@ -0,0 +1,15 @@
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.File" ],
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "File",
+ "Args": { "path": "log.log" }
+ }
+ ],
+ "Properties": {
+ "Application": "Sample"
+ }
+ }
+}
\ No newline at end of file