доделал
This commit is contained in:
parent
650d8d2563
commit
1a8269e81b
@ -95,7 +95,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
|
|||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
// TODO: Изменение x, y, если при установке объект выходит за границы
|
// TODO: Изменение x, y, если при установке объект выходит за границы
|
||||||
if (x < 0 || y < 0 || x + _ustaWidth > _pictureWidth || y + _ustaHeight > _pictureHeight)
|
if (x < 0 || y < 0 )
|
||||||
{
|
{
|
||||||
x = 10;
|
x = 10;
|
||||||
y = 10;
|
y = 10;
|
||||||
|
@ -30,6 +30,7 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_storage = new UstaGenericStorage(pictureBoxCollection.Width,
|
_storage = new UstaGenericStorage(pictureBoxCollection.Width,
|
||||||
pictureBoxCollection.Height);
|
pictureBoxCollection.Height);
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Заполнение listBoxObjects
|
/// Заполнение listBoxObjects
|
||||||
@ -171,6 +172,8 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
try
|
||||||
|
{
|
||||||
if (obj - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
@ -181,7 +184,12 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
|
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (UstaNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning($"{ex.Message} из набора {listBoxStorage.SelectedItem.ToString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -3,6 +3,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace ProjectUsta
|
namespace ProjectUsta
|
||||||
{
|
{
|
||||||
@ -25,11 +26,19 @@ namespace ProjectUsta
|
|||||||
|
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<FormSelfPropelledArtilleryUnitCollection>()
|
services.AddSingleton<FormSelfPropelledArtilleryUnitCollection>().AddLogging(option =>
|
||||||
.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}appsettings.json", optional: false, reloadOnChange: true).Build();
|
||||||
|
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||||
|
|
||||||
option.SetMinimumLevel(LogLevel.Information);
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
option.AddNLog("nlog.config");
|
option.AddSerilog(logger);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,8 +9,13 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -65,8 +65,13 @@ namespace SelfPropelledArtilleryUnit.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if ((position < 0) || (position > _maxCount)) return false;
|
if (position < 0 || position > _maxCount || position >= Count)
|
||||||
_places.RemoveAt(position);
|
throw new UstaNotFoundException();
|
||||||
|
if (_places[position] == null)
|
||||||
|
{
|
||||||
|
throw new UstaNotFoundException();
|
||||||
|
}
|
||||||
|
_places[position] = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -57,14 +57,14 @@ namespace SelfPropelledArtilleryUnit.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int? operator +(UstaGenericCollection<T, U> collect, T?
|
public static int operator +(UstaGenericCollection<T, U> collect, T?
|
||||||
obj)
|
obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return collect?._collection.Insert(obj);
|
return collect?._collection.Insert(obj) ?? -1;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
@ -72,15 +72,15 @@ namespace SelfPropelledArtilleryUnit.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="pos"></param>
|
/// <param name="pos"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator -(UstaGenericCollection<T, U> collect, int
|
public static T operator -(UstaGenericCollection<T, U> collect, int
|
||||||
pos)
|
pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection[pos];
|
T obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return collect._collection.Remove(pos);
|
collect?._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return false;
|
return obj;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта IMoveableObject
|
/// Получение объекта IMoveableObject
|
||||||
|
@ -126,7 +126,6 @@ namespace SelfPropelledArtilleryUnit.Generics
|
|||||||
using (StreamWriter writer = new StreamWriter(filename))
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
{
|
{
|
||||||
writer.Write($"UstaStorage{Environment.NewLine}{data}");
|
writer.Write($"UstaStorage{Environment.NewLine}{data}");
|
||||||
writer.Write(data.ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.Serialization;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SelfPropelledArtilleryUnit.Exceptions
|
namespace SelfPropelledArtilleryUnit
|
||||||
{
|
{
|
||||||
[Serializable] internal class UstaNotFoundException : ApplicationException
|
[Serializable] internal class UstaNotFoundException : ApplicationException
|
||||||
{
|
{
|
||||||
|
@ -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": "GasolineTanker"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user