This commit is contained in:
Александр Чегодаев 2023-12-22 17:38:52 +04:00
parent 2a4b5ecabc
commit ce4dd23448
14 changed files with 2387 additions and 250 deletions

View File

@ -8,4 +8,28 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -43,14 +43,14 @@ namespace ProjectCruiser
return collect?._collection.Insert(obj);
}
public static bool operator -(CruiserGenericCollection<T, U> collect, int pos)
public static T operator -(CruiserGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return false;
return obj;
}
public U? GetU(int pos)
@ -91,15 +91,18 @@ namespace ProjectCruiser
int i = 0;
foreach (var cruiser in _collection.GetCruiser())
{
cruiser._pictureHeight = _pictureHeight;
cruiser._pictureWidth = _pictureWidth;
_collection[i]?.SetPosition(Ix, Iy);
_collection[i]?.DrawTransport(g);
Ix += _placeSizeWidth;
if (Ix + _placeSizeHeight > _pictureWidth)
if (cruiser != null)
{
Ix = 0;
Iy = _placeSizeHeight;
cruiser._pictureHeight = _pictureHeight;
cruiser._pictureWidth = _pictureWidth;
_collection[i]?.SetPosition(Ix, Iy);
_collection[i]?.DrawTransport(g);
Ix += _placeSizeWidth;
if (Ix + _placeSizeHeight > _pictureWidth)
{
Ix = 3;
Iy = _placeSizeHeight+15;
}
}
i++;
}

View File

@ -1,4 +1,6 @@
using ProjectCruiser.DrawningObjects;
using Cruiser;
using Cruiser.Exceptions;
using ProjectCruiser.DrawningObjects;
using ProjectCruiser.MovementStrategy;
using System;
using System.Collections.Generic;
@ -62,7 +64,7 @@ DrawningObjectCruiser>> _CruiserStorages;
}
}
public bool SaveData(string filename)
public void SaveData(string filename)
{
if (File.Exists(filename))
{
@ -80,22 +82,20 @@ DrawningObjectCruiser>> _CruiserStorages;
}
if (data.Length == 0)
{
return false;
throw new Exception("Невалидная операция, нет данных для сохранения");
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write($"CruiserStorage{Environment.NewLine}{data}");
}
return true;
}
public bool LoadData(string filename)
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
throw new Exception("Файл не найден");
}
using (StreamReader reader = new StreamReader(filename))
@ -103,11 +103,11 @@ DrawningObjectCruiser>> _CruiserStorages;
string cheker = reader.ReadLine();
if (cheker == null)
{
return false;
throw new Exception("Нет данных для загрузки");
}
if (!cheker.StartsWith("CruiserStorage"))
{
return false;
throw new Exception("Неверный формат ввода");
}
_CruiserStorages.Clear();
string strs;
@ -116,11 +116,11 @@ DrawningObjectCruiser>> _CruiserStorages;
{
if (strs == null && firstinit)
{
return false;
throw new Exception("Нет данных для загрузки");
}
if (strs == null)
{
return false;
break;
}
firstinit = false;
string name = strs.Split(_separatorForKeyValue)[0];
@ -131,16 +131,19 @@ DrawningObjectCruiser>> _CruiserStorages;
data?.CreateDrawningCruiser(_separatorForObject, _pictureWidth, _pictureHeight);
if (cruiser != null)
{
int? result = collection + cruiser;
if (result == null || result.Value == -1)
try { _ = collection + cruiser; }
catch (CruiserNotFoundException e)
{
return false;
throw e;
}
catch (StorageOverflowException e)
{
throw e;
}
}
}
_CruiserStorages.Add(name, collection);
}
return true;
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser
{
[Serializable] internal class CruiserNotFoundException : ApplicationException
{
public CruiserNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
public CruiserNotFoundException() : base() { }
public CruiserNotFoundException(string message) : base(message) { }
public CruiserNotFoundException(string message, Exception exception) : base(message, exception) { }
protected CruiserNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -28,146 +28,147 @@
/// </summary>
private void InitializeComponent()
{
comboBoxStrategy = new System.Windows.Forms.ComboBox();
ButtonCreateCruiserBat = new System.Windows.Forms.Button();
ButtonCreateCruiser = new System.Windows.Forms.Button();
ButtonStep = new System.Windows.Forms.Button();
buttonUp = new System.Windows.Forms.Button();
buttonDown = new System.Windows.Forms.Button();
buttonLeft = new System.Windows.Forms.Button();
buttonRight = new System.Windows.Forms.Button();
pictureBoxCruiser = new System.Windows.Forms.PictureBox();
ButtonSelectCruiser = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(pictureBoxCruiser)).BeginInit();
SuspendLayout();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCruiser));
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.ButtonCreateCruiserBat = new System.Windows.Forms.Button();
this.ButtonCreateCruiser = new System.Windows.Forms.Button();
this.ButtonStep = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.ButtonSelectCruiser = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.SuspendLayout();
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] {
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"MoveToCenter",
"MoveToBorder",
"-"});
comboBoxStrategy.Location = new System.Drawing.Point(667, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
comboBoxStrategy.TabIndex = 0;
this.comboBoxStrategy.Location = new System.Drawing.Point(667, 12);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
this.comboBoxStrategy.TabIndex = 0;
//
// ButtonCreateCruiserBat
//
ButtonCreateCruiserBat.Location = new System.Drawing.Point(19, 386);
ButtonCreateCruiserBat.Name = "ButtonCreateCruiserBat";
ButtonCreateCruiserBat.Size = new System.Drawing.Size(160, 57);
ButtonCreateCruiserBat.TabIndex = 1;
ButtonCreateCruiserBat.Text = "Создать крейсер с ракетными шахтами и площадкой под вертолет";
ButtonCreateCruiserBat.UseVisualStyleBackColor = true;
ButtonCreateCruiserBat.Click += new System.EventHandler(ButtonCreateCruiserBat_Click);
this.ButtonCreateCruiserBat.Location = new System.Drawing.Point(19, 386);
this.ButtonCreateCruiserBat.Name = "ButtonCreateCruiserBat";
this.ButtonCreateCruiserBat.Size = new System.Drawing.Size(160, 57);
this.ButtonCreateCruiserBat.TabIndex = 1;
this.ButtonCreateCruiserBat.Text = "Создать крейсер с ракетными шахтами и площадкой под вертолет";
this.ButtonCreateCruiserBat.UseVisualStyleBackColor = true;
this.ButtonCreateCruiserBat.Click += new System.EventHandler(this.ButtonCreateCruiserBat_Click);
//
// ButtonCreateCruiser
//
ButtonCreateCruiser.Location = new System.Drawing.Point(185, 386);
ButtonCreateCruiser.Name = "ButtonCreateCruiser";
ButtonCreateCruiser.Size = new System.Drawing.Size(160, 57);
ButtonCreateCruiser.TabIndex = 2;
ButtonCreateCruiser.Text = "Создать крейсер";
ButtonCreateCruiser.UseVisualStyleBackColor = true;
ButtonCreateCruiser.Click += new System.EventHandler(ButtonCreateCruiser_Click);
this.ButtonCreateCruiser.Location = new System.Drawing.Point(185, 386);
this.ButtonCreateCruiser.Name = "ButtonCreateCruiser";
this.ButtonCreateCruiser.Size = new System.Drawing.Size(160, 57);
this.ButtonCreateCruiser.TabIndex = 2;
this.ButtonCreateCruiser.Text = "Создать крейсер";
this.ButtonCreateCruiser.UseVisualStyleBackColor = true;
this.ButtonCreateCruiser.Click += new System.EventHandler(this.ButtonCreateCruiser_Click);
//
// ButtonStep
//
ButtonStep.Location = new System.Drawing.Point(713, 50);
ButtonStep.Name = "ButtonStep";
ButtonStep.Size = new System.Drawing.Size(75, 23);
ButtonStep.TabIndex = 3;
ButtonStep.Text = "Шаг";
ButtonStep.UseVisualStyleBackColor = true;
ButtonStep.Click += new System.EventHandler(ButtonStep_Click);
this.ButtonStep.Location = new System.Drawing.Point(713, 50);
this.ButtonStep.Name = "ButtonStep";
this.ButtonStep.Size = new System.Drawing.Size(75, 23);
this.ButtonStep.TabIndex = 3;
this.ButtonStep.Text = "Шаг";
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// buttonUp
//
buttonUp.BackgroundImage = global::ProjectCruiser.Properties.Resources.вверх;
buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
buttonUp.Location = new System.Drawing.Point(678, 352);
buttonUp.Name = "buttonUp";
buttonUp.Size = new System.Drawing.Size(44, 38);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += new System.EventHandler(ButtonMove_Click);
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(678, 352);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(44, 38);
this.buttonUp.TabIndex = 4;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
buttonDown.BackgroundImage = global::ProjectCruiser.Properties.Resources.вниз;
buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
buttonDown.Location = new System.Drawing.Point(678, 395);
buttonDown.Name = "buttonDown";
buttonDown.Size = new System.Drawing.Size(44, 38);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += new System.EventHandler(ButtonMove_Click);
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(678, 395);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(44, 38);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
buttonLeft.BackgroundImage = global::ProjectCruiser.Properties.Resources.влево;
buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
buttonLeft.Location = new System.Drawing.Point(629, 395);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new System.Drawing.Size(44, 38);
buttonLeft.TabIndex = 6;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += new System.EventHandler(ButtonMove_Click);
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(629, 395);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(44, 38);
this.buttonLeft.TabIndex = 6;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
buttonRight.BackgroundImage = global::ProjectCruiser.Properties.Resources.вправо;
buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
buttonRight.Location = new System.Drawing.Point(727, 395);
buttonRight.Name = "buttonRight";
buttonRight.Size = new System.Drawing.Size(44, 38);
buttonRight.TabIndex = 7;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += new System.EventHandler(ButtonMove_Click);
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(727, 395);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(44, 38);
this.buttonRight.TabIndex = 7;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// pictureBoxCruiser
//
pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
pictureBoxCruiser.Name = "pictureBoxCruiser";
pictureBoxCruiser.Size = new System.Drawing.Size(800, 450);
pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
pictureBoxCruiser.TabIndex = 8;
pictureBoxCruiser.TabStop = false;
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
this.pictureBoxCruiser.Size = new System.Drawing.Size(800, 450);
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCruiser.TabIndex = 8;
this.pictureBoxCruiser.TabStop = false;
//
// ButtonSelectCruiser
//
ButtonSelectCruiser.Location = new System.Drawing.Point(351, 386);
ButtonSelectCruiser.Name = "ButtonSelectCruiser";
ButtonSelectCruiser.Size = new System.Drawing.Size(160, 57);
ButtonSelectCruiser.TabIndex = 9;
ButtonSelectCruiser.Text = "Выбор";
ButtonSelectCruiser.UseVisualStyleBackColor = true;
ButtonSelectCruiser.Click += new System.EventHandler(ButtonSelectCruiser_Click);
this.ButtonSelectCruiser.Location = new System.Drawing.Point(351, 386);
this.ButtonSelectCruiser.Name = "ButtonSelectCruiser";
this.ButtonSelectCruiser.Size = new System.Drawing.Size(160, 57);
this.ButtonSelectCruiser.TabIndex = 9;
this.ButtonSelectCruiser.Text = "Выбор";
this.ButtonSelectCruiser.UseVisualStyleBackColor = true;
this.ButtonSelectCruiser.Click += new System.EventHandler(this.ButtonSelectCruiser_Click);
//
// FormCruiser
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(800, 450);
Controls.Add(ButtonSelectCruiser);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(ButtonStep);
Controls.Add(ButtonCreateCruiser);
Controls.Add(ButtonCreateCruiserBat);
Controls.Add(comboBoxStrategy);
Controls.Add(pictureBoxCruiser);
Name = "FormCruiser";
Text = "FormCruiser";
((System.ComponentModel.ISupportInitialize)(pictureBoxCruiser)).EndInit();
ResumeLayout(false);
PerformLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ButtonSelectCruiser);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.ButtonCreateCruiser);
this.Controls.Add(this.ButtonCreateCruiserBat);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.pictureBoxCruiser);
this.Name = "FormCruiser";
this.Text = "FormCruiser";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}

File diff suppressed because it is too large Load Diff

View File

@ -28,27 +28,27 @@
/// </summary>
private void InitializeComponent()
{
groupBox1 = new System.Windows.Forms.GroupBox();
groupBox2 = new System.Windows.Forms.GroupBox();
listBoxStorage = new System.Windows.Forms.ListBox();
textBoxStorageName = new System.Windows.Forms.TextBox();
ButtonAddObject = new System.Windows.Forms.Button();
ButtonDelObject = new System.Windows.Forms.Button();
maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
ButtonRefreshCollection = new System.Windows.Forms.Button();
ButtonRemoveCruiser = new System.Windows.Forms.Button();
buttonAddCruiser = new System.Windows.Forms.Button();
pictureBoxCollection = new System.Windows.Forms.PictureBox();
menuStrip = new System.Windows.Forms.MenuStrip();
fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
openFileDialog = new System.Windows.Forms.OpenFileDialog();
saveFileDialog = new System.Windows.Forms.SaveFileDialog();
groupBox1 = new GroupBox();
groupBox2 = new GroupBox();
listBoxStorage = new ListBox();
textBoxStorageName = new TextBox();
ButtonAddObject = new Button();
ButtonDelObject = new Button();
maskedTextBoxNumber = new MaskedTextBox();
ButtonRefreshCollection = new Button();
ButtonRemoveCruiser = new Button();
buttonAddCruiser = new Button();
menuStrip = new MenuStrip();
fileToolStripMenuItem = new ToolStripMenuItem();
SaveToolStripMenuItem = new ToolStripMenuItem();
LoadToolStripMenuItem = new ToolStripMenuItem();
pictureBoxCollection = new PictureBox();
openFileDialog = new OpenFileDialog();
saveFileDialog = new SaveFileDialog();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(pictureBoxCollection)).BeginInit();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// groupBox1
@ -59,9 +59,9 @@
groupBox1.Controls.Add(ButtonRemoveCruiser);
groupBox1.Controls.Add(buttonAddCruiser);
groupBox1.Controls.Add(menuStrip);
groupBox1.Location = new System.Drawing.Point(643, 12);
groupBox1.Location = new Point(637, 10);
groupBox1.Name = "groupBox1";
groupBox1.Size = new System.Drawing.Size(196, 483);
groupBox1.Size = new Size(183, 467);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
@ -72,9 +72,9 @@
groupBox2.Controls.Add(textBoxStorageName);
groupBox2.Controls.Add(ButtonAddObject);
groupBox2.Controls.Add(ButtonDelObject);
groupBox2.Location = new System.Drawing.Point(9, 58);
groupBox2.Location = new Point(9, 58);
groupBox2.Name = "groupBox2";
groupBox2.Size = new System.Drawing.Size(179, 256);
groupBox2.Size = new Size(179, 256);
groupBox2.TabIndex = 4;
groupBox2.TabStop = false;
groupBox2.Text = "Наборы";
@ -83,25 +83,25 @@
//
listBoxStorage.FormattingEnabled = true;
listBoxStorage.ItemHeight = 15;
listBoxStorage.Location = new System.Drawing.Point(6, 93);
listBoxStorage.Location = new Point(6, 93);
listBoxStorage.Name = "listBoxStorage";
listBoxStorage.Size = new System.Drawing.Size(167, 109);
listBoxStorage.Size = new Size(154, 94);
listBoxStorage.TabIndex = 5;
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
//
// textBoxStorageName
//
textBoxStorageName.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
textBoxStorageName.Location = new System.Drawing.Point(6, 22);
textBoxStorageName.Font = new Font("Lucida Sans Unicode", 9F, FontStyle.Regular, GraphicsUnit.Point);
textBoxStorageName.Location = new Point(6, 22);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new System.Drawing.Size(167, 26);
textBoxStorageName.Size = new Size(154, 26);
textBoxStorageName.TabIndex = 4;
//
// ButtonAddObject
//
ButtonAddObject.Location = new System.Drawing.Point(6, 54);
ButtonAddObject.Location = new Point(6, 54);
ButtonAddObject.Name = "ButtonAddObject";
ButtonAddObject.Size = new System.Drawing.Size(167, 33);
ButtonAddObject.Size = new Size(154, 30);
ButtonAddObject.TabIndex = 3;
ButtonAddObject.Text = "Добавить набор";
ButtonAddObject.UseVisualStyleBackColor = true;
@ -109,9 +109,9 @@
//
// ButtonDelObject
//
ButtonDelObject.Location = new System.Drawing.Point(6, 217);
ButtonDelObject.Location = new Point(6, 217);
ButtonDelObject.Name = "ButtonDelObject";
ButtonDelObject.Size = new System.Drawing.Size(167, 33);
ButtonDelObject.Size = new Size(154, 30);
ButtonDelObject.TabIndex = 2;
ButtonDelObject.Text = "Удалить набор";
ButtonDelObject.UseVisualStyleBackColor = true;
@ -119,18 +119,18 @@
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
maskedTextBoxNumber.Location = new System.Drawing.Point(34, 359);
maskedTextBoxNumber.Font = new Font("Lucida Sans Unicode", 9F, FontStyle.Regular, GraphicsUnit.Point);
maskedTextBoxNumber.Location = new Point(34, 359);
maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new System.Drawing.Size(130, 26);
maskedTextBoxNumber.Size = new Size(117, 26);
maskedTextBoxNumber.TabIndex = 3;
//
// ButtonRefreshCollection
//
ButtonRefreshCollection.Location = new System.Drawing.Point(6, 430);
ButtonRefreshCollection.Location = new Point(6, 430);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new System.Drawing.Size(184, 33);
ButtonRefreshCollection.Size = new Size(171, 30);
ButtonRefreshCollection.TabIndex = 2;
ButtonRefreshCollection.Text = "Обовить коллекцию";
ButtonRefreshCollection.UseVisualStyleBackColor = true;
@ -138,9 +138,9 @@
//
// ButtonRemoveCruiser
//
ButtonRemoveCruiser.Location = new System.Drawing.Point(6, 391);
ButtonRemoveCruiser.Location = new Point(6, 391);
ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
ButtonRemoveCruiser.Size = new System.Drawing.Size(184, 33);
ButtonRemoveCruiser.Size = new Size(171, 30);
ButtonRemoveCruiser.TabIndex = 1;
ButtonRemoveCruiser.Text = "Удалить крейсер";
ButtonRemoveCruiser.UseVisualStyleBackColor = true;
@ -148,58 +148,55 @@
//
// buttonAddCruiser
//
buttonAddCruiser.Location = new System.Drawing.Point(6, 320);
buttonAddCruiser.Location = new Point(6, 320);
buttonAddCruiser.Name = "buttonAddCruiser";
buttonAddCruiser.Size = new System.Drawing.Size(184, 33);
buttonAddCruiser.Size = new Size(171, 30);
buttonAddCruiser.TabIndex = 0;
buttonAddCruiser.Text = "Добавить крейсер";
buttonAddCruiser.UseVisualStyleBackColor = true;
buttonAddCruiser.Click += buttonAddCruiser_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new System.Drawing.Point(1, 4);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new System.Drawing.Size(637, 491);
pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
//
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
fileToolStripMenuItem});
menuStrip.Location = new System.Drawing.Point(3, 19);
menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
menuStrip.Location = new Point(3, 19);
menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(7, 3, 0, 3);
menuStrip.Size = new System.Drawing.Size(190, 24);
menuStrip.Size = new Size(177, 25);
menuStrip.TabIndex = 5;
menuStrip.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
SaveToolStripMenuItem,
LoadToolStripMenuItem});
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
fileToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
fileToolStripMenuItem.Size = new Size(48, 19);
fileToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
SaveToolStripMenuItem.Size = new Size(141, 22);
SaveToolStripMenuItem.Text = "Сохранение";
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
// LoadToolStripMenuItem
//
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
LoadToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
LoadToolStripMenuItem.Size = new Size(141, 22);
LoadToolStripMenuItem.Text = "Загрузка";
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(1, 4);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(630, 266);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog1";
@ -213,9 +210,9 @@
//
// FormCruiserCollection
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(853, 536);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(826, 480);
Controls.Add(pictureBoxCollection);
Controls.Add(groupBox1);
MainMenuStrip = menuStrip;
@ -226,11 +223,10 @@
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(pictureBoxCollection)).EndInit();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
}
#endregion

View File

@ -2,6 +2,7 @@
using ProjectCruiser.Drawnings;
using ProjectCruiser.Generics;
using ProjectCruiser.MovementStrategy;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
namespace ProjectCruiser
@ -10,11 +11,14 @@ namespace ProjectCruiser
{
private readonly CruiserGenericStorage _storage;
public FormCruiserCollection()
private readonly ILogger _logger;
public FormCruiserCollection(ILogger<FormCruiserCollection> logger)
{
InitializeComponent();
_storage = new CruiserGenericStorage(pictureBoxCollection.Width,
pictureBoxCollection.Height);
_logger = logger;
}
private void ReloadObjects()
@ -43,10 +47,12 @@ namespace ProjectCruiser
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("Пустое название набора");
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
_logger.LogInformation($"Добавлен набор:{textBoxStorageName.Text}");
}
private void listBoxStorage_SelectedIndexChanged(object sender,
@ -60,49 +66,59 @@ namespace ProjectCruiser
{
if (listBoxStorage.SelectedIndex == -1)
{
_logger.LogWarning("Удаление невыбранного набора");
return;
}
string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void AddCruiser(DrawningCruiser cruiser)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
if (obj != null)
{
if (obj + cruiser != 1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowCruiser();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
_logger.LogInformation($"Удален набор: {name}");
}
}
private void buttonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var formCruiserConfig = new FormCruiserConfig();
formCruiserConfig.AddEvent(cruiser =>
{
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
_logger.LogWarning("Добавление пустого объекта");
return;
}
try
{
_ = obj + cruiser;
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowCruiser();
_logger.LogInformation($"Добавлен объект в набор {listBoxStorage.SelectedItem.ToString()}");
}
catch (Exception ex)
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorage.SelectedItem.ToString()}");
}
});
formCruiserConfig.Show();
formCruiserConfig.AddEvent(AddCruiser);
}
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
_logger.LogWarning("Удаление объекта из несуществующего набора");
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
@ -121,10 +137,12 @@ namespace ProjectCruiser
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowCruiser();
_logger.LogInformation($"Удален объект из набора {listBoxStorage.SelectedItem.ToString()}");
}
else
{
MessageBox.Show("Не удалось удалить объект");
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
}
}
@ -146,15 +164,16 @@ namespace ProjectCruiser
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.SaveData(saveFileDialog.FileName))
try
{
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_storage.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Сохранение наборов в файл {saveFileDialog.FileName}");
}
else
catch (Exception ex)
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
}
}
}
@ -163,14 +182,17 @@ namespace ProjectCruiser
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(openFileDialog.FileName))
try
{
MessageBox.Show("Данные успешно загружены.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
_storage.LoadData(openFileDialog.FileName);
ReloadObjects();
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Загрузились наборы из файла {openFileDialog.FileName}");
}
else
catch (Exception ex)
{
MessageBox.Show("Ошибка при загрузке данных.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось загрузить наборы с ошибкой: {ex.Message}");
}
}
}

View File

@ -1,4 +1,64 @@
<root>
<?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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
@ -66,7 +126,4 @@
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>281, 16</value>
</metadata>
<metadata name="$TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>74</value>
</metadata>
</root>

View File

@ -1,17 +1,41 @@
using ProjectCruiser;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Serilog;
namespace ProjectCruiser
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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 FormCruiserCollection());
var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormCruiserCollection>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormCruiserCollection>().AddLogging(option =>
{
string[] path = Directory.GetCurrentDirectory().Split('\\');
string pathNeed = "";
for (int i = 0; i < path.Length - 3; i++)
{
pathNeed += path[i] + "\\";
}
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true).Build();
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
}
}

View File

@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectCruiser.Properties {
namespace Cruiser.Properties {
using System;
@ -39,7 +39,7 @@ namespace ProjectCruiser.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectCruiser.Properties.Resources", typeof(Resources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Cruiser.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@ -1,4 +1,6 @@
using System;
using Cruiser;
using Cruiser.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -23,25 +25,51 @@ namespace ProjectCruiser.Generics
public int Insert(T cruiser)
{
return Insert(cruiser, 0);
if (_places.Count == 0)
{
_places.Add(cruiser);
return 0;
}
else
{
if (_places.Count < _maxCount)
{
_places.Add(cruiser);
for (int i = 0; i < _places.Count; i++)
{
T temp = _places[i];
_places[i] = _places[_places.Count - 1];
_places[_places.Count - 1] = temp;
}
return 0;
}
else
{
throw new StorageOverflowException(_places.Count);
}
}
}
public int Insert(T cruiser, int position)
public bool Insert(T cruiser, int position)
{
if (position < 0 || position >= _maxCount)
return -1;
throw new CruiserNotFoundException(position);
if (Count >= _maxCount)
return -1;
_places.Insert(position, cruiser);
return position;
throw new StorageOverflowException(position);
_places.Insert(0, cruiser);
return true;
}
public bool Remove(int position)
{
if ((position < 0) || (position > _maxCount)) return false;
_places.RemoveAt(position);
if (position < 0 || position > _maxCount || position >= Count)
throw new CruiserNotFoundException();
if (_places[position] == null)
{
throw new CruiserNotFoundException();
}
_places[position] = null;
return true;
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.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 contex) : base(info, contex) { }
}
}

View 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": "GasolineTanker"
}
}
}