Compare commits

..

No commits in common. "74d3f54bafe83f446ffc410e9e10cdc8a90391c3" and "8021e8ec78b6d3cbbd45e9e088b8cb503fa26363" have entirely different histories.

7 changed files with 53 additions and 148 deletions

View File

@ -8,16 +8,6 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

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

View File

@ -10,9 +10,7 @@ using System.Windows.Forms;
using Microsoft.VisualBasic.Logging;
using AirBomber.Exceptions;
using Serilog;
using _logger = Serilog.Log;
using System.Xml.Linq;
using System.Linq.Expressions;
using Log = Serilog.Log;
namespace AirBomber
{
@ -81,17 +79,14 @@ namespace AirBomber
{
return;
}
try
if (obj + plane > -1)
{
_ = obj + plane;
MessageBox.Show("Объект добавлен");
_logger.Information("Объект добавлен");
pictureBoxCollection.Image = obj.ShowPlanes();
}
catch (Exception ex)
else
{
MessageBox.Show(ex.Message);
_logger.Warning($"Объект не добавлен в набор {listBoxStorages.SelectedItem.ToString()}");
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
@ -114,30 +109,15 @@ namespace AirBomber
{
return;
}
try
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null)
{
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
_logger.Information("Объект удален");
pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось удалить объект");
_logger.Warning("Не удалось удалить объект");
}
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowPlanes();
}
catch (PlaneNotFoundException ex)
else
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show("Неверный ввод");
_logger.Warning("Неверный ввод");
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
@ -167,26 +147,23 @@ namespace AirBomber
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.Warning("Не все данные заполнены");
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
_logger.Information($"Добавлен набор: {textBoxStorageName.Text}");
}
private void buttonDelObject_Click(object sender, EventArgs e)
{
string Name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить набор {Name}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(Name);
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
_logger.Information($"Удален набор: {Name}");
}
}
/// <summary>
@ -198,16 +175,13 @@ namespace AirBomber
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
if (_storage.SaveData(saveFileDialog.FileName))
{
_storage.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.Information("Сохранение прошло успешно");
}
catch (Exception ex)
else
{
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.Warning($"Не сохранилось: {ex.Message}");
}
}
}
@ -221,17 +195,15 @@ namespace AirBomber
// TODO продумать логику DONE
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
if (_storage.LoadData(openFileDialog.FileName))
{
_storage.LoadData(openFileDialog.FileName);
MessageBox.Show("Загрузка прошла успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.Information("Загрузка прошла успешно");
ReloadObjects();
}
catch(Exception ex)
else
{
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.Warning($"Не загрузилось: {ex.Message}");
MessageBox.Show("Не загрузилось!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

View File

@ -49,13 +49,13 @@ namespace AirBomber
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(PlanesGenericCollection<T, U> collect, T obj)
public static int operator +(PlanesGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return false;
return -1;
}
return collect._collection.Insert(obj);
return collect?._collection.Insert(obj) ?? -1;
}
/// <summary>
/// Перегрузка оператора вычитания
@ -63,15 +63,15 @@ namespace AirBomber
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(PlanesGenericCollection<T, U> collect, int
pos)
public static bool operator -(PlanesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
return true;
}
return obj;
return false;
}
/// <summary>
/// Получение объекта IMoveableObject

View File

@ -1,5 +1,4 @@
using AirBomber.Exceptions;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -169,20 +168,9 @@ namespace AirBomber
DrawningAirPlane? plane = elem?.CreateDrawningAirPlane(_separatorForObject, _pictureWidth, _pictureHeight);
if (plane != null)
{
if (!(collection + plane))
if ((collection + plane) == -1)
{
try
{
_ = collection + plane;
}
catch (PlaneNotFoundException e)
{
throw e;
}
catch (StorageOverflowException e)
{
throw e;
}
throw new Exception("Ошибка добавления в коллекцию");
}
}
}

View File

@ -1,8 +1,3 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
namespace AirBomber
{
internal static class Program
@ -16,30 +11,7 @@ namespace AirBomber
// 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())
{
Application.Run(serviceProvider.GetRequiredService<FormPlaneCollection>());
}
//Application.Run(new FormPlaneCollection());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormPlaneCollection>().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.AddSerilog(logger);
});
Application.Run(new FormPlaneCollection());
}
}
}

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.Exceptions;
namespace AirBomber
{
@ -36,8 +35,9 @@ namespace AirBomber
/// </summary>
/// <param name="plane">Добавляемый самолет</param>
/// <returns></returns>
public bool Insert(T plane)
public int Insert(T plane)
{
//was TODO
return Insert(plane, 0);
}
/// <summary>
@ -46,15 +46,19 @@ namespace AirBomber
/// <param name="plane">Добавляемый самолет</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T plane, int position)
public int Insert(T plane, int position)
{
// TODO проверка позиции DONE
// TODO проверка, что элемент массива по этой позиции пустой,если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
if (position < 0 || position >= _maxCount)
throw new StorageOverflowException("Impossible to insert");
if (Count >= _maxCount)
{
throw new StorageOverflowException(_maxCount);
_places.Insert(0, plane);
return true;
}
_places.Insert(position, plane);
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
@ -63,11 +67,13 @@ namespace AirBomber
/// <returns></returns>
public bool Remove(int position)
{
if (position >= Count || position < 0)
throw new PlaneNotFoundException("Invalid operation");
if (_places[position] == null)
// TODO проверка позиции DONE
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (!(position >= 0 && position < Count) || _places[position] == null)
{
throw new PlaneNotFoundException(position);
_places.RemoveAt(position);
}
_places[position] = null;
return true;
}
/// <summary>
@ -88,14 +94,11 @@ namespace AirBomber
}
set
{
try
{
Insert(value, position);
}
catch
{
return;
}
// TODO проверка позиции DONE
// TODO проверка свободных мест в списке DONE
// TODO вставка в список по позиции DONE
if (position < 0 || position >= Count || Count == _maxCount) return;
_places.Insert(position, value);
}
}
/// <summary>