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