Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9323704e05 | ||
|
|
cffd746ec7 | ||
|
|
3070770d5a |
@@ -1,6 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
|
||||
69
ProjectBomber/ProjectBomber/ExtentionDrawningPlane.cs
Normal file
69
ProjectBomber/ProjectBomber/ExtentionDrawningPlane.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using ProjectBomber.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityBomber
|
||||
/// </summary>
|
||||
public static class ExtentionDrawningPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningBomber CreateDrawningPlane(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningBomber(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawningBomberAdvanced(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]),
|
||||
Convert.ToBoolean(strs[6]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningPlane">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningBomber drawningPlane,
|
||||
char separatorForObject)
|
||||
{
|
||||
var plane = drawningPlane.EntityBomber;
|
||||
if (plane == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
|
||||
if (!(plane is EntityBomberAdvanced bomberAdvanced))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{bomberAdvanced.AdditionalColor.Name}{separatorForObject}{bomberAdvanced.Bombs}" +
|
||||
$"{separatorForObject}{bomberAdvanced.FuelTanks}{separatorForObject}{bomberAdvanced.Line}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,16 @@
|
||||
this.ButtonRemovePlane = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddPlane = new System.Windows.Forms.Button();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBoxSet.SuspendLayout();
|
||||
this.menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -51,9 +58,10 @@
|
||||
this.groupBox1.Controls.Add(this.ButtonRemovePlane);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddPlane);
|
||||
this.groupBox1.Location = new System.Drawing.Point(586, 2);
|
||||
this.groupBox1.Controls.Add(this.menuStrip);
|
||||
this.groupBox1.Location = new System.Drawing.Point(592, 2);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(216, 563);
|
||||
this.groupBox1.Size = new System.Drawing.Size(210, 563);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
@@ -109,7 +117,7 @@
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(18, 509);
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(20, 492);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(178, 41);
|
||||
this.ButtonRefreshCollection.TabIndex = 3;
|
||||
@@ -119,7 +127,7 @@
|
||||
//
|
||||
// ButtonRemovePlane
|
||||
//
|
||||
this.ButtonRemovePlane.Location = new System.Drawing.Point(18, 430);
|
||||
this.ButtonRemovePlane.Location = new System.Drawing.Point(21, 445);
|
||||
this.ButtonRemovePlane.Name = "ButtonRemovePlane";
|
||||
this.ButtonRemovePlane.Size = new System.Drawing.Size(179, 41);
|
||||
this.ButtonRemovePlane.TabIndex = 2;
|
||||
@@ -129,14 +137,14 @@
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(18, 388);
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(18, 351);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(180, 20);
|
||||
this.maskedTextBoxNumber.TabIndex = 1;
|
||||
//
|
||||
// ButtonAddPlane
|
||||
//
|
||||
this.ButtonAddPlane.Location = new System.Drawing.Point(18, 327);
|
||||
this.ButtonAddPlane.Location = new System.Drawing.Point(18, 305);
|
||||
this.ButtonAddPlane.Name = "ButtonAddPlane";
|
||||
this.ButtonAddPlane.Size = new System.Drawing.Size(185, 40);
|
||||
this.ButtonAddPlane.TabIndex = 0;
|
||||
@@ -144,14 +152,57 @@
|
||||
this.ButtonAddPlane.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click);
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.fileToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(3, 536);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(204, 24);
|
||||
this.menuStrip.TabIndex = 5;
|
||||
this.menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.saveToolStripMenuItem,
|
||||
this.loadToolStripMenuItem});
|
||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
||||
this.fileToolStripMenuItem.Text = "File";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.saveToolStripMenuItem.Text = "Save";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
this.loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.loadToolStripMenuItem.Text = "Load";
|
||||
this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(-2, 2);
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 2);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(600, 563);
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(600, 565);
|
||||
this.pictureBoxCollection.TabIndex = 1;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.FileName = "openFileDialog";
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormPlaneCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@@ -159,12 +210,15 @@
|
||||
this.ClientSize = new System.Drawing.Size(800, 564);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormPlaneCollection";
|
||||
this.Text = "Набор самолетов";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBoxSet.ResumeLayout(false);
|
||||
this.groupBoxSet.PerformLayout();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@@ -183,5 +237,11 @@
|
||||
private System.Windows.Forms.ListBox ListBoxStorages;
|
||||
private System.Windows.Forms.Button ButtonAddObject;
|
||||
private System.Windows.Forms.TextBox textBoxStorageName;
|
||||
private System.Windows.Forms.MenuStrip menuStrip;
|
||||
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ using System.Windows.Forms;
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using ProjectBomber.Generics;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
@@ -23,12 +25,17 @@ namespace ProjectBomber
|
||||
/// </summary>
|
||||
private readonly PlanesGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormPlaneCollection()
|
||||
public FormPlaneCollection(ILogger<FormPlaneCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
@@ -63,10 +70,12 @@ namespace ProjectBomber
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Пустое название набора");
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Добавлен набор:{ textBoxStorageName.Text} ");
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
@@ -87,13 +96,18 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes()
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Удаление невыбранного набора");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {ListBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
string name = ListBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||
|
||||
if (MessageBox.Show($"Удалить объект {name}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(ListBoxStorages.SelectedItem.ToString()?? string.Empty);
|
||||
_storage.DelSet(ListBoxStorages.SelectedItem.ToString()
|
||||
?? string.Empty);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Удален набор: {name}");
|
||||
}
|
||||
}
|
||||
private void AddPlane(DrawningBomber plane)
|
||||
@@ -105,16 +119,21 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes()
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning("Добавление пустого объекта");
|
||||
return;
|
||||
}
|
||||
if ((obj + plane) != -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
_ = obj + plane;
|
||||
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
_logger.LogInformation($"Добавлен объект в набор {ListBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning($"{ex.Message} в наборе {ListBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -126,6 +145,7 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes()
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Неудачная попытка добавить объект: набор не выбран");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
@@ -139,18 +159,20 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes()
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// </summary>labelModifiedObject
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Удаление объекта из несуществующего набора");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning($"Ошибка удаления объекта из набора: место в наборе пусто");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
@@ -159,14 +181,24 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes()
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
_logger.LogInformation($"Удален объект из набора {ListBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogWarning($"Не удалось удалить объект из набора {ListBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch(PlaneNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"{ex.Message} из набора {ListBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -188,5 +220,53 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes()
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.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($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Данные успешно загружены.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Загрузились наборы из файла {openFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.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>132, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>244, 19</value>
|
||||
</metadata>
|
||||
</root>
|
||||
20
ProjectBomber/ProjectBomber/PlaneNotFoundException.cs
Normal file
20
ProjectBomber/ProjectBomber/PlaneNotFoundException.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
[Serializable]
|
||||
internal class PlaneNotFoundException : ApplicationException
|
||||
{
|
||||
public PlaneNotFoundException(int i) : base($"Не найден объект по позиции { i}") { }
|
||||
public PlaneNotFoundException() : base() { }
|
||||
public PlaneNotFoundException(string message) : base(message) { }
|
||||
public PlaneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected PlaneNotFoundException(SerializationInfo info,
|
||||
StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,10 @@ namespace ProjectBomber.Generics
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T> GetPlanes => _collection.GetPlanes();
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
@@ -77,7 +81,7 @@ namespace ProjectBomber.Generics
|
||||
T obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
collect?._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -134,13 +138,13 @@ namespace ProjectBomber.Generics
|
||||
int row = 0;
|
||||
foreach (var plane in _collection.GetPlanes())
|
||||
{
|
||||
plane._pictureHeight = pictureHeight;
|
||||
plane._pictureWidth = pictureWidth;
|
||||
// Установка позиции бомбардировщика
|
||||
int xPosition = column * _placeSizeWidth;
|
||||
int yPosition = row * _placeSizeHeight;
|
||||
if (plane != null)
|
||||
{
|
||||
plane._pictureHeight = pictureHeight;
|
||||
plane._pictureWidth = pictureWidth;
|
||||
// Перемещение по ячейкам влево, вниз
|
||||
column--;
|
||||
if (column < 0)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -43,6 +44,18 @@ namespace ProjectBomber.Generics
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
@@ -93,5 +106,97 @@ namespace ProjectBomber.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации по самолетам в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (_planeStorages.Count == 0)
|
||||
throw new InvalidOperationException("Невалидная операция: нет данных для сохранения");
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
foreach (KeyValuePair<string,
|
||||
PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>> record in _planeStorages)
|
||||
{
|
||||
StringBuilder records = new StringBuilder();
|
||||
foreach (DrawningBomber elem in record.Value.GetPlanes)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
throw new Exception("Невалидная операция: нет данных для сохранения");
|
||||
}
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.Write($"PlanesStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по самолетам в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader reader = new StreamReader(filename))
|
||||
{
|
||||
string cheker = reader.ReadLine();
|
||||
if (cheker == null || cheker.Length == 0)
|
||||
{
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
}
|
||||
if (!cheker.StartsWith("PlanesStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new InvalidDataException("Неверный формат данных");
|
||||
}
|
||||
_planeStorages.Clear();
|
||||
string strs;
|
||||
bool firstinit = true;
|
||||
while ((strs = reader.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null && firstinit)
|
||||
{
|
||||
throw new Exception("Нет данных для загрузки");
|
||||
}
|
||||
if (strs == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
firstinit = false;
|
||||
string name = strs.Split(_separatorForKeyValue)[0];
|
||||
PlanesGenericCollection<DrawningBomber, DrawningObjectBomber> collection = new PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>(_pictureWidth, _pictureHeight);
|
||||
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
|
||||
{
|
||||
DrawningBomber plane = data?.CreateDrawningPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (plane != null)
|
||||
{
|
||||
try { _ = collection + plane; }
|
||||
catch (PlaneNotFoundException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (StorageOverflowException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
_planeStorages.Add(name, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Serilog;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
@@ -16,7 +22,31 @@ namespace ProjectBomber
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormPlaneCollection());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider =
|
||||
services.BuildServiceProvider())
|
||||
{
|
||||
|
||||
Application.Run(serviceProvider.GetRequiredService<FormPlaneCollection>());
|
||||
}
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
// Установка текущего рабочего каталога
|
||||
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
|
||||
// Использование Path.Combine для формирования абсолютного пути к appsettings.json
|
||||
var pathToAppsettings = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");
|
||||
services.AddSingleton<FormPlaneCollection>().AddLogging(option =>
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile(path: pathToAppsettings, optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>ProjectBomber</RootNamespace>
|
||||
<AssemblyName>ProjectBomber</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
@@ -24,9 +25,9 @@
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -48,8 +49,106 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Configuration, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Configuration.8.0.0\lib\net462\Microsoft.Extensions.Configuration.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Configuration.Abstractions.8.0.0\lib\net462\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Configuration.Binder, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Configuration.Binder.8.0.0\lib\net462\Microsoft.Extensions.Configuration.Binder.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Configuration.FileExtensions.8.0.0\lib\net462\Microsoft.Extensions.Configuration.FileExtensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Configuration.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Configuration.Json.8.0.0\lib\net462\Microsoft.Extensions.Configuration.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyModel.8.0.0\lib\net462\Microsoft.Extensions.DependencyModel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.FileProviders.Abstractions.8.0.0\lib\net462\Microsoft.Extensions.FileProviders.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.FileProviders.Physical, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.FileProviders.Physical.8.0.0\lib\net462\Microsoft.Extensions.FileProviders.Physical.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.FileSystemGlobbing, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.FileSystemGlobbing.8.0.0\lib\net462\Microsoft.Extensions.FileSystemGlobbing.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.8.0.0\lib\net462\Microsoft.Extensions.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.8.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Options, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Options.8.0.0\lib\net462\Microsoft.Extensions.Options.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Primitives.8.0.0\lib\net462\Microsoft.Extensions.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.5.2.7\lib\net46\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog.Extensions.Logging, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.Extensions.Logging.5.3.5\lib\net461\NLog.Extensions.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Serilog.3.1.1\lib\net471\Serilog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Serilog.Extensions.Logging, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Serilog.Extensions.Logging.8.0.0\lib\net462\Serilog.Extensions.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Serilog.Settings.Configuration, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Serilog.Settings.Configuration.8.0.0\lib\net462\Serilog.Settings.Configuration.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Serilog.Sinks.File, Version=5.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Serilog.Sinks.File.5.0.0\lib\net45\Serilog.Sinks.File.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.8.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Json.8.0.0\lib\net462\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -68,6 +167,7 @@
|
||||
<Compile Include="DrawningObjectBomber.cs" />
|
||||
<Compile Include="EntityBomber.cs" />
|
||||
<Compile Include="EntityBomberAdvanced.cs" />
|
||||
<Compile Include="ExtentionDrawningPlane.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -90,12 +190,14 @@
|
||||
<Compile Include="MoveToBottomRight.cs" />
|
||||
<Compile Include="MoveToCenter.cs" />
|
||||
<Compile Include="ObjectParameters.cs" />
|
||||
<Compile Include="PlaneNotFoundException.cs" />
|
||||
<Compile Include="PlanesGenericCollection.cs" />
|
||||
<Compile Include="PlanesGenericStorage.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SetGeneric.cs" />
|
||||
<Compile Include="Status.cs" />
|
||||
<Compile Include="StorageOverflowException.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -105,24 +207,9 @@
|
||||
<EmbeddedResource Include="FormPlaneConfig.resx">
|
||||
<DependentUpon>FormPlaneConfig.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
<None Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программным средством.
|
||||
// Версия среды выполнения: 4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если
|
||||
// код создан повторно.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ProjectBomber.Properties
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурсов со строгим типом для поиска локализованных строк и пр.
|
||||
/// </summary>
|
||||
// Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder
|
||||
// класс с помощью таких средств, как ResGen или Visual Studio.
|
||||
// Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen
|
||||
// с параметром /str или заново постройте свой VS-проект.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возврат кэшированного экземпляра ResourceManager, используемого этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectBomber.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Переопределяет свойство CurrentUICulture текущего потока для всех
|
||||
/// подстановки ресурсов с помощью этого класса ресурсов со строгим типом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -1,30 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ProjectBomber.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
@@ -10,7 +10,7 @@ namespace ProjectBomber.Generics
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
internal class SetGeneric<T> : NullReferenceException
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
@@ -59,8 +59,10 @@ namespace ProjectBomber.Generics
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
throw new StorageOverflowException(_places.Count);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@@ -74,23 +76,27 @@ namespace ProjectBomber.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (position < _places.Count && _places[position] == null)
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = plane;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(plane);
|
||||
for (int i = position; i < _places.Count; i++)
|
||||
{
|
||||
T temp = _places[i];
|
||||
_places[i] = _places[_places.Count - 1];
|
||||
_places[_places.Count - 1] = temp;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ищем первую пустую позицию и вставляем туда.
|
||||
for (int i = 0; i < _maxCount; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
_places[i] = plane;
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new StorageOverflowException();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@@ -99,8 +105,12 @@ namespace ProjectBomber.Generics
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return false;
|
||||
if (position < 0 || position > _maxCount || position >= Count)
|
||||
throw new PlaneNotFoundException();
|
||||
if (_places[position] == null)
|
||||
{
|
||||
throw new PlaneNotFoundException();
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
21
ProjectBomber/ProjectBomber/StorageOverflowException.cs
Normal file
21
ProjectBomber/ProjectBomber/StorageOverflowException.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 ProjectBomber
|
||||
{
|
||||
[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) { }
|
||||
}
|
||||
}
|
||||
20
ProjectBomber/ProjectBomber/appsettings.json
Normal file
20
ProjectBomber/ProjectBomber/appsettings.json
Normal file
@@ -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": "ProjectBomber"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user