Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9df56cdb4d | ||
|
|
7e4fd641e7 | ||
|
|
d43966d9eb | ||
|
|
d2423b1bd3 | ||
|
|
1436165717 | ||
|
|
bdbb9bae60 |
@@ -8,6 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
@@ -23,4 +36,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="loggerConfig.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
14
AirFighter/AirFighter/AircraftNotFoundException.cs
Normal file
14
AirFighter/AirFighter/AircraftNotFoundException.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
[Serializable]
|
||||
internal class AircraftNotFoundException : ApplicationException
|
||||
{
|
||||
public AircraftNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public AircraftNotFoundException() : base() { }
|
||||
public AircraftNotFoundException(string message) : base(message) { }
|
||||
public AircraftNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected AircraftNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
@@ -32,5 +32,8 @@ namespace AirFighter
|
||||
// TODO
|
||||
_airFighter.DrawTransport(g);
|
||||
}
|
||||
public string GetInfo() => _airFighter?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectAirFighter(data.CreateDrawingAirFighter());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
39
AirFighter/AirFighter/ExtensionAircraft.cs
Normal file
39
AirFighter/AirFighter/ExtensionAircraft.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
internal static class ExtentionAircraft
|
||||
{
|
||||
private static readonly char _separatorForObject = ':';
|
||||
public static DrawingAirFighter CreateDrawingAirFighter(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingAirFighter(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawingModernAirFighter(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static string GetDataForSave(this DrawingAirFighter drawningAircraft)
|
||||
{
|
||||
var aircraft = drawningAircraft.AirFighter;
|
||||
var str =
|
||||
$"{aircraft.Speed}{_separatorForObject}{aircraft.Weight}{_separatorForObject}" +
|
||||
$"{aircraft.BodyColor.Name}";
|
||||
|
||||
if (aircraft is not EntityModernAirFighter modernAircraft)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{_separatorForObject}{modernAircraft.DopColor.Name}{_separatorForObject}" +
|
||||
$"{modernAircraft.Rockets}{_separatorForObject}{modernAircraft.DopWings}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Lime;
|
||||
this.panelGreen.Location = new System.Drawing.Point(148, 31);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(50, 50);
|
||||
|
||||
76
AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
generated
76
AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
generated
@@ -45,9 +45,16 @@
|
||||
this.ButtonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.tools.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tools
|
||||
@@ -63,9 +70,9 @@
|
||||
this.tools.Controls.Add(this.ButtonShowStorage);
|
||||
this.tools.Controls.Add(this.buttonAdd);
|
||||
this.tools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.tools.Location = new System.Drawing.Point(940, 0);
|
||||
this.tools.Location = new System.Drawing.Point(940, 28);
|
||||
this.tools.Name = "tools";
|
||||
this.tools.Size = new System.Drawing.Size(250, 725);
|
||||
this.tools.Size = new System.Drawing.Size(250, 697);
|
||||
this.tools.TabIndex = 0;
|
||||
this.tools.TabStop = false;
|
||||
this.tools.Text = "Инструменты";
|
||||
@@ -138,7 +145,7 @@
|
||||
this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right;
|
||||
this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.RightButton.Location = new System.Drawing.Point(148, 683);
|
||||
this.RightButton.Location = new System.Drawing.Point(148, 655);
|
||||
this.RightButton.Name = "RightButton";
|
||||
this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.RightButton.Size = new System.Drawing.Size(30, 30);
|
||||
@@ -151,7 +158,7 @@
|
||||
this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left;
|
||||
this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.LeftButton.Location = new System.Drawing.Point(76, 683);
|
||||
this.LeftButton.Location = new System.Drawing.Point(76, 655);
|
||||
this.LeftButton.Name = "LeftButton";
|
||||
this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.LeftButton.Size = new System.Drawing.Size(30, 30);
|
||||
@@ -164,7 +171,7 @@
|
||||
this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up;
|
||||
this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.UpButton.Location = new System.Drawing.Point(112, 648);
|
||||
this.UpButton.Location = new System.Drawing.Point(112, 620);
|
||||
this.UpButton.Name = "UpButton";
|
||||
this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.UpButton.Size = new System.Drawing.Size(30, 30);
|
||||
@@ -177,7 +184,7 @@
|
||||
this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down;
|
||||
this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.DownButton.Location = new System.Drawing.Point(112, 683);
|
||||
this.DownButton.Location = new System.Drawing.Point(112, 655);
|
||||
this.DownButton.Name = "DownButton";
|
||||
this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.DownButton.Size = new System.Drawing.Size(30, 30);
|
||||
@@ -236,12 +243,54 @@
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(940, 725);
|
||||
this.pictureBox.Size = new System.Drawing.Size(940, 697);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.файлToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1190, 28);
|
||||
this.menuStrip1.TabIndex = 2;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.saveToolStripMenuItem,
|
||||
this.loadToolStripMenuItem});
|
||||
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
this.файлToolStripMenuItem.Size = new System.Drawing.Size(58, 24);
|
||||
this.файлToolStripMenuItem.Text = "файл";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.saveToolStripMenuItem.Text = "Сохранение";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
this.loadToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.loadToolStripMenuItem.Text = "Загрузка";
|
||||
this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormMapWithSetCars
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
@@ -249,6 +298,8 @@
|
||||
this.ClientSize = new System.Drawing.Size(1190, 725);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.tools);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
this.Name = "FormMapWithSetCars";
|
||||
this.Text = "FormMapWithSetCars";
|
||||
this.tools.ResumeLayout(false);
|
||||
@@ -256,7 +307,10 @@
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@@ -279,5 +333,11 @@
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem saveToolStripMenuItem;
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -24,9 +25,14 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetCars()
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public FormMapWithSetCars(ILogger<FormMapWithSetCars> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width,
|
||||
pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
@@ -70,6 +76,7 @@ namespace AirFighter
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
_logger.LogInformation("При попытке создания карты не все данные заполнены");
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
@@ -77,15 +84,18 @@ namespace AirFighter
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogInformation($"Нет карты с названием {comboBoxSelectorMap.Text}");
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text,
|
||||
_mapsDict[comboBoxSelectorMap.Text]);
|
||||
_logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
|
||||
ReloadMaps();
|
||||
}
|
||||
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
_logger?.LogInformation($"Переход на карту {listBoxMaps.SelectedItem?.ToString()}");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
@@ -101,6 +111,7 @@ namespace AirFighter
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ??
|
||||
string.Empty);
|
||||
_logger.LogInformation($"Удаление карты {listBoxMaps.SelectedItem}");
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
@@ -112,15 +123,23 @@ namespace AirFighter
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectAirFighter(aircraft) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image =
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation("На карту добавлен новый объект");
|
||||
}
|
||||
else
|
||||
} catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
MessageBox.Show($"Ошибка переполнения: {ex.Message}");
|
||||
_logger.LogWarning($"Ошибка переполнения: {ex.Message}");
|
||||
} catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
_logger.LogWarning($"Неизвестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,16 +170,27 @@ namespace AirFighter
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
|
||||
try
|
||||
{
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image =
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation($"Удален объект на позиции {pos}");
|
||||
}
|
||||
else
|
||||
} catch (AircraftNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
_logger.LogWarning($"Ошибка при удалении объекта на позиции {pos}: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
_logger.LogWarning($"Неизвестная ошибка при удалении объекта на позиции {pos}: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -176,6 +206,7 @@ namespace AirFighter
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation("Показ хранилища");
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
@@ -190,6 +221,7 @@ namespace AirFighter
|
||||
return;
|
||||
}
|
||||
pictureBox.Image =_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
_logger.LogInformation("Просмотр карты");
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
@@ -221,7 +253,41 @@ namespace AirFighter
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
|
||||
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"Успешное сохранение в файл {saveFileDialog.FileName}");
|
||||
} catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Ошибка при сохранении в файл {saveFileDialog.FileName}: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
|
||||
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"Успешная загрузка из файла {openFileDialog.FileName}");
|
||||
ReloadMaps();
|
||||
} catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Ошибка при загрузке из файла {openFileDialog.FileName}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>152, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>319, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -12,6 +12,7 @@ namespace AirFighter
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawningObject(Graphics g);
|
||||
string GetInfo();
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
|
||||
|
||||
@@ -109,9 +109,24 @@ namespace AirFighter
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
|
||||
public string GetData(char separatorType, char separatorData)
|
||||
{
|
||||
string data = $"{_map.GetType().Name}{separatorType}";
|
||||
foreach (var car in _setCars.GetCars())
|
||||
{
|
||||
data += $"{car.GetInfo()}{separatorData}";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records)
|
||||
{
|
||||
_setCars.Insert(DrawingObjectAirFighter.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setCars.Count - 1;
|
||||
|
||||
@@ -8,31 +8,19 @@ namespace AirFighter
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetCarsGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
|
||||
private char separatorDict = '|';
|
||||
private char separatorData = ';';
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string,
|
||||
MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap>>();
|
||||
_mapStorages = new Dictionary<string, MapWithSetCarsGeneric<IDrawingObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@@ -49,21 +37,68 @@ namespace AirFighter
|
||||
|
||||
_mapStorages[name] = new(_pictureWidth, _pictureHeight, map);
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
|
||||
public void DelMap(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap> this[string ind]
|
||||
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (StreamWriter fs = new(filename))
|
||||
{
|
||||
fs.Write($"MapsCollection{Environment.NewLine}");
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
|
||||
fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader fs = new(filename))
|
||||
{
|
||||
string current = fs.ReadLine();
|
||||
if (!current.Contains("MapsCollection"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new FileFormatException("Не правильный формат данных");
|
||||
}
|
||||
|
||||
_mapStorages.Clear();
|
||||
|
||||
while ((current = fs.ReadLine()) != null)
|
||||
{
|
||||
var elem = current.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "MyMap":
|
||||
map = new MyMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetCarsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public MapWithSetCarsGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal static class Program
|
||||
@@ -8,10 +13,30 @@ namespace AirFighter
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMapWithSetCars());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetCars>());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormMapWithSetCars>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("loggerConfig.json")
|
||||
.Build();
|
||||
|
||||
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(config).CreateLogger();
|
||||
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,13 @@ namespace AirFighter
|
||||
public int Insert(T car)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
if (_places.Count == _maxCount) return -1;
|
||||
if (_places.Count == _maxCount) throw new StorageOverflowException(_maxCount);
|
||||
_places.Insert(0, car);
|
||||
return 0;
|
||||
}
|
||||
public int Insert(T car, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
if (_places.Count == _maxCount) return -1;
|
||||
if (_places.Count == _maxCount) throw new StorageOverflowException(_maxCount);
|
||||
_places.Insert(position, car);
|
||||
return position;
|
||||
}
|
||||
@@ -52,10 +47,12 @@ namespace AirFighter
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||
if(position >= _maxCount || position >= _places.Count) throw new AircraftNotFoundException(position);
|
||||
|
||||
T res = _places[position];
|
||||
_places.Remove(res);
|
||||
|
||||
if (res == null) throw new AircraftNotFoundException(position);
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
13
AirFighter/AirFighter/StorageOverflowException.cs
Normal file
13
AirFighter/AirFighter/StorageOverflowException.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Runtime.Serialization;
|
||||
namespace AirFighter
|
||||
{
|
||||
[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 contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
17
AirFighter/AirFighter/loggerConfig.json
Normal file
17
AirFighter/AirFighter/loggerConfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "{Level:u4}: {Message:lj} [{Timestamp:HH:mm:ss.fff}]{NewLine}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user