AllDone
This commit is contained in:
parent
bb75afe944
commit
53d754014b
@ -8,6 +8,13 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="DirectionType.enum" />
|
||||
<None Remove="FormAirplaneConfig.Designer.cs~RF9e39eb.TMP" />
|
||||
|
@ -40,8 +40,7 @@ namespace ProjectAirFighter.Generics
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
collect._collection.Remove(pos);
|
||||
collect._collection.Remove(pos);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
21
AirFighter/AirplaneNotFoundException.cs
Normal file
21
AirFighter/AirplaneNotFoundException.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
namespace ProjectAirFighter.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class AirplaneNotFoundException : ApplicationException
|
||||
{
|
||||
public AirplaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public AirplaneNotFoundException() : base() { }
|
||||
public AirplaneNotFoundException(string message) : base(message) { }
|
||||
public AirplaneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected AirplaneNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace ProjectAirFighter.Generics
|
||||
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
string toWrite = $"AirplaneStorage{Environment.NewLine}{data}";
|
||||
var strs = toWrite.Split(new char[] { '\n', '\r' },
|
||||
@ -68,7 +68,7 @@ StringSplitOptions.RemoveEmptyEntries);
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new IOException("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
@ -79,11 +79,11 @@ StringSplitOptions.RemoveEmptyEntries);
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
return false;
|
||||
throw new IOException("Нет данных для загрузки");
|
||||
}
|
||||
if (!strs[0].StartsWith("AirplaneStorage"))
|
||||
{
|
||||
return false;
|
||||
throw new IOException("Неверный формат данных");
|
||||
}
|
||||
_airplaneStorages.Clear();
|
||||
do
|
||||
|
@ -16,6 +16,7 @@ namespace ProjectAirFighter.DrawningObjects
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
char separator = '|';
|
||||
protected int _startPosY;
|
||||
protected readonly int _airplaneWidth = 163;
|
||||
protected readonly int _airplaneHeight = 160;
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectAirFighter.Entities;
|
||||
|
@ -1,5 +1,7 @@
|
||||
using ProjectAirFighter.DrawningObjects;
|
||||
using ProjectAirFighter.Generics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
using ProjectAirFighter.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -10,6 +12,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using Serilog;
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
using Log = Serilog.Log;
|
||||
|
||||
namespace ProjectAirFighter
|
||||
{
|
||||
@ -28,15 +34,17 @@ namespace ProjectAirFighter
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_storage.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Log.Warning("Не удалось сохранить");
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,20 +52,22 @@ namespace ProjectAirFighter
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
foreach (var collection in _storage.Keys)
|
||||
{
|
||||
listBoxStorages.Items.Add(collection);
|
||||
}
|
||||
|
||||
ReloadObjects();
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Log.Warning("Не удалось загрузить");
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,6 +113,7 @@ namespace ProjectAirFighter
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
Log.Information($"Добавлен набор: {textBoxStorageName.Text}");
|
||||
|
||||
}
|
||||
private void deleteAirplaneButton_Click(object sender, EventArgs e)
|
||||
@ -122,15 +133,23 @@ namespace ProjectAirFighter
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
try
|
||||
{
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
var q = obj - pos;
|
||||
MessageBox.Show("Объект удален");
|
||||
Log.Information($"Удален объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty} по номеру {pos}");
|
||||
pictureBoxCollection.Image = obj.ShowAirplanes();
|
||||
}
|
||||
else
|
||||
catch (AirplaneNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
Log.Warning($"Не получилось удалить объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
Log.Warning($"Было введено не число");
|
||||
MessageBox.Show("Введите число");
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,15 +184,18 @@ namespace ProjectAirFighter
|
||||
form.Show();
|
||||
Action<DrawningAirplane>? airplaneDelegate = new((m) =>
|
||||
{
|
||||
bool q = (obj + m);
|
||||
if (q)
|
||||
try
|
||||
{
|
||||
bool q = obj + m;
|
||||
MessageBox.Show("Объект добавлен");
|
||||
Log.Information($"Добавлен объект в коллекцию {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||
pictureBoxCollection.Image = obj.ShowAirplanes();
|
||||
}
|
||||
else
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
Log.Warning($"Коллекция {listBoxStorages.SelectedItem.ToString() ?? string.Empty} переполнена");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
});
|
||||
form.AddEvent(airplaneDelegate);
|
||||
@ -191,12 +213,14 @@ _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplane
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||||
?? string.Empty);
|
||||
string name = listBoxStorages.SelectedItem.ToString()
|
||||
?? string.Empty;
|
||||
_storage.DelSet(name);
|
||||
ReloadObjects();
|
||||
Log.Information($"Удален набор: {name}");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
using System.Drawing;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using System.Drawing;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using Serilog.Formatting.Json;
|
||||
namespace ProjectAirFighter
|
||||
{
|
||||
internal static class Program
|
||||
@ -7,8 +13,13 @@ namespace ProjectAirFighter
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
|
||||
ApplicationConfiguration.Initialize();
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.File("log.txt")
|
||||
.MinimumLevel.Debug()
|
||||
.CreateLogger();
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormAirplaneCollection());
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectAirFighter.Generics
|
||||
{
|
||||
@ -23,7 +25,7 @@ namespace ProjectAirFighter.Generics
|
||||
public bool Insert(T airplane)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
return false;
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(airplane, 0);
|
||||
return true;
|
||||
|
||||
@ -31,7 +33,9 @@ namespace ProjectAirFighter.Generics
|
||||
|
||||
public bool Insert(T airplane, int position)
|
||||
{
|
||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return false;
|
||||
_places.Insert(position, airplane);
|
||||
return true;
|
||||
@ -39,7 +43,7 @@ namespace ProjectAirFighter.Generics
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return false;
|
||||
throw new AirplaneNotFoundException(position);
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
19
AirFighter/StorageOverflowException.cs
Normal file
19
AirFighter/StorageOverflowException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAirFighter.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user