Логирование удаления по некорректному индексу.

This commit is contained in:
Nikolaeva_Y.A 2022-12-06 10:46:46 +04:00
parent 447415895f
commit fc705e5d4e
4 changed files with 25 additions and 37 deletions

View File

@ -84,8 +84,8 @@ namespace Airbus
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsCollection.AddMap(textBoxNewMapName.Text,
_mapsDict[comboBoxSelectorMap.Text]); _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
_logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text); _logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text);
ReloadMaps();
} }
//Выбор карты //Выбор карты
@ -105,9 +105,8 @@ namespace Airbus
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
_logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty); _logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
} }
} }
@ -282,6 +281,7 @@ namespace Airbus
MessageBox.Show("Загрузка данных прошла успешно", "Результат", MessageBox.Show("Загрузка данных прошла успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -28,10 +28,8 @@ namespace Airbus
//конструктор //конструктор
public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map) public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map)
{ {
int width = picWidth / _placeSizeWidth; _setPlanes = new SetPlanesGeneric<T>(18);
int height = picHeight / _placeSizeHeight;
_setPlanes = new SetPlanesGeneric<T>(width * height);
_pictureWidth = picWidth; _pictureWidth = picWidth;
_pictureHeight = picHeight; _pictureHeight = picHeight;
_map = map; _map = map;

View File

@ -27,23 +27,19 @@ namespace Airbus
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetPlanes>()); Application.Run(serviceProvider.GetRequiredService<FormMapWithSetPlanes>());
} }
} }
private static void ConfigureServices(ServiceCollection services) private static void ConfigureServices(ServiceCollection services)
{ {
services.AddSingleton<FormMapWithSetPlanes>() services.AddSingleton<FormMapWithSetPlanes>();
.AddLogging(option =>
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "C:\\Users\\Programmist73\\Desktop\\Ïðàêòèêà\\2-é êóðñ\\ÐÏÏ\\Base\\PIbd-21_Eliseev_E.E._Airbus_Base\\Airbus\\Airbus\\appsettings.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration() var serilogLogger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration) .WriteTo.RollingFile("Logs\\log.txt")
.CreateLogger(); .CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger); services.AddLogging(option =>
}); {
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger: serilogLogger, dispose: true);
});
} }
} }
} }

View File

@ -29,6 +29,11 @@ namespace Airbus
//добавление объекта в набор //добавление объекта в набор
public int Insert(T plane) public int Insert(T plane)
{ {
if (Count == _maxCount)
{
throw new StorageOverflowException(_maxCount);
}
if (Count + 1 <= _maxCount) return Insert(plane, 0); if (Count + 1 <= _maxCount) return Insert(plane, 0);
else return -1; else return -1;
} }
@ -45,11 +50,6 @@ namespace Airbus
throw new ArgumentException($"Объект {plane} уже есть в наборе"); throw new ArgumentException($"Объект {plane} уже есть в наборе");
} }
if (Count == _maxCount)
{
throw new StorageOverflowException(_maxCount);
}
_places.Insert(position, plane); _places.Insert(position, plane);
return position; return position;
} }
@ -57,21 +57,15 @@ namespace Airbus
//удаление объекта из набора с конкретной позиции //удаление объекта из набора с конкретной позиции
public T Remove(int position) public T Remove(int position)
{ {
if (position < _maxCount && position >= 0) if (position >= Count || position < 0)
{ {
if (_places.ElementAt(position) != null)
{
T result = _places.ElementAt(position);
_places.RemoveAt(position);
return result;
}
throw new PlaneNotFoundException(position); throw new PlaneNotFoundException(position);
} }
return null; T result = _places[position];
_places.RemoveAt(position);
return result;
} }
//получение объекта из набора по позиции //получение объекта из набора по позиции