Compare commits
18 Commits
LabWork_04
...
LabWork_07
| Author | SHA1 | Date | |
|---|---|---|---|
| 16da11f0e2 | |||
| 918be42c06 | |||
| 9953e40a20 | |||
| 6b440d6ada | |||
| a58085b4d1 | |||
| f3ce9dd416 | |||
| 7e81c6ca04 | |||
| d1356fb01e | |||
| c266418c75 | |||
| 9379418cf7 | |||
| c549fc6a3c | |||
| 737d77ac68 | |||
| 71b1caa094 | |||
| 814b0b8252 | |||
| cc83e1aa48 | |||
| 8bcd0f4089 | |||
| 213ec2a858 | |||
| 7ab4e0f118 |
20
base/Catamaran/Catamaran/AppSetting.json
Normal file
20
base/Catamaran/Catamaran/AppSetting.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": "Battleship"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,17 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" 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.5" />
|
||||
<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>
|
||||
|
||||
22
base/Catamaran/Catamaran/CatamaranNotFoundException.cs
Normal file
22
base/Catamaran/Catamaran/CatamaranNotFoundException.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
namespace Catamaran.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class CatamaranNotFoundException : ApplicationException
|
||||
{
|
||||
public CatamaranNotFoundException(int i) : base($"Не найден объект по позиции { i}") { }
|
||||
public CatamaranNotFoundException() : base() { }
|
||||
public CatamaranNotFoundException(string message) : base(message) { }
|
||||
public CatamaranNotFoundException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected CatamaranNotFoundException(SerializationInfo info,
|
||||
StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,10 @@ namespace Catamaran.Generics
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetCatamarans => _collection.GetCatamarans();
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
@@ -146,6 +150,8 @@ namespace Catamaran.Generics
|
||||
}
|
||||
if (catamaran != null)
|
||||
{
|
||||
catamaran._pictureWidth = _pictureWidth;
|
||||
catamaran._pictureHeight = _pictureHeight;
|
||||
catamaran.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40,
|
||||
(height - diff) * _placeSizeHeight + _placeSizeHeight / 15);
|
||||
catamaran.DrawTransport(g);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Catamaran.DrawningObjects;
|
||||
using Catamaran.MovementStrategy;
|
||||
using System.Text;
|
||||
|
||||
namespace Catamaran.Generics
|
||||
{
|
||||
/// <summary>
|
||||
@@ -25,6 +27,18 @@ namespace Catamaran.Generics
|
||||
/// </summary>
|
||||
private readonly int _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="pictureWidth"></param>
|
||||
@@ -73,5 +87,94 @@ namespace Catamaran.Generics
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации по катамаранам в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>> record in _catamaranStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningCatamaran? elem in record.Value.GetCatamarans)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
throw new Exception("Невалидная операция, нет данных для сохранения");
|
||||
}
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
byte[] info = new
|
||||
UTF8Encoding(true).GetBytes($"CatamaranStorage{Environment.NewLine}{data}");
|
||||
fs.Write(info, 0, info.Length);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new Exception("Файл не найден");
|
||||
}
|
||||
|
||||
string bufferTextFromFile = "";
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
{
|
||||
byte[] b = new byte[fs.Length];
|
||||
UTF8Encoding temp = new(true);
|
||||
while (fs.Read(b, 0, b.Length) > 0)
|
||||
{
|
||||
bufferTextFromFile += temp.GetString(b);
|
||||
}
|
||||
}
|
||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
throw new Exception("Нет данных для загрузки");
|
||||
}
|
||||
if (!strs[0].StartsWith("CatamaranStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new Exception("Неверный формат данных");
|
||||
}
|
||||
_catamaranStorages.Clear();
|
||||
foreach (string data in strs)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>
|
||||
collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawningCatamaran? catamaran =
|
||||
elem?.CreateDrawningCatamaran(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (catamaran != null)
|
||||
{
|
||||
if (!(collection + catamaran))
|
||||
{
|
||||
throw new Exception("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
}
|
||||
_catamaranStorages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ namespace Catamaran.DrawningObjects
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки катамарана
|
||||
/// </summary>
|
||||
@@ -220,6 +220,20 @@ namespace Catamaran.DrawningObjects
|
||||
SolidBrush brushBrown = new SolidBrush(Color.Brown);
|
||||
g.FillEllipse(brushBrown, _startPosX + 30, _startPosY + 60, 100, 40);
|
||||
}
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (EntityCatamaran == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityCatamaran.BodyColor = color;
|
||||
}
|
||||
|
||||
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
|
||||
{
|
||||
_pictureWidth = pictureBoxWidth;
|
||||
_pictureHeight = pictureBoxHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,10 @@ namespace Catamaran.DrawningObjects
|
||||
g.DrawRectangle(pen, _startPosX + 70, _startPosY, 3, 85);
|
||||
}
|
||||
}
|
||||
public void SetAddColor(Color color)
|
||||
{
|
||||
((EntitySailCatamaran)EntityCatamaran).AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Catamaran.Entities
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color BodyColor { get; set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения катамарана
|
||||
/// </summary>
|
||||
@@ -33,12 +33,17 @@ namespace Catamaran.Entities
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public EntityCatamaran(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public void setBodyColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Catamaran.Entities
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public Color AdditionalColor { get; set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия паруса
|
||||
/// </summary>
|
||||
@@ -39,5 +39,9 @@ namespace Catamaran.Entities
|
||||
Sail = sail;
|
||||
FloatDetail = floatDetail;
|
||||
}
|
||||
public void setAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
66
base/Catamaran/Catamaran/ExtentionDrawningCatamaran.cs
Normal file
66
base/Catamaran/Catamaran/ExtentionDrawningCatamaran.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Catamaran.Entities;
|
||||
namespace Catamaran.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityCatamaran
|
||||
/// </summary>
|
||||
public static class ExtentionDrawningCatamaran
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningCatamaran? CreateDrawningCatamaran(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningCatamaran(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawningSailCatamaran(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningCatamaran">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningCatamaran drawningCatamaran,
|
||||
char separatorForObject)
|
||||
{
|
||||
var catamaran = drawningCatamaran.EntityCatamaran;
|
||||
if (catamaran == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{catamaran.Speed}{separatorForObject}{catamaran.Weight}{separatorForObject}{catamaran.BodyColor.Name}";
|
||||
if (catamaran is not EntitySailCatamaran sailCatamaran)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{sailCatamaran.AdditionalColor.Name}{separatorForObject}{sailCatamaran.Sail}{separatorForObject}{sailCatamaran.FloatDetail}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,9 +39,16 @@
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveCatamaran = new System.Windows.Forms.Button();
|
||||
this.ButtonAddCatamaran = new System.Windows.Forms.Button();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
this.groupBoxSets.SuspendLayout();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
@@ -59,6 +66,7 @@
|
||||
this.groupBoxTools.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.groupBoxTools.Controls.Add(this.ButtonRemoveCatamaran);
|
||||
this.groupBoxTools.Controls.Add(this.ButtonAddCatamaran);
|
||||
this.groupBoxTools.Controls.Add(this.menuStrip);
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(739, 1);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(147, 460);
|
||||
@@ -72,23 +80,23 @@
|
||||
this.groupBoxSets.Controls.Add(this.buttonDelObject);
|
||||
this.groupBoxSets.Controls.Add(this.listBoxStorages);
|
||||
this.groupBoxSets.Controls.Add(this.buttonAddObject);
|
||||
this.groupBoxSets.Location = new System.Drawing.Point(3, 21);
|
||||
this.groupBoxSets.Location = new System.Drawing.Point(3, 63);
|
||||
this.groupBoxSets.Name = "groupBoxSets";
|
||||
this.groupBoxSets.Size = new System.Drawing.Size(138, 245);
|
||||
this.groupBoxSets.Size = new System.Drawing.Size(138, 203);
|
||||
this.groupBoxSets.TabIndex = 4;
|
||||
this.groupBoxSets.TabStop = false;
|
||||
this.groupBoxSets.Text = "Наборы";
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(3, 36);
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(6, 22);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(134, 23);
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(130, 23);
|
||||
this.textBoxStorageName.TabIndex = 4;
|
||||
//
|
||||
// buttonDelObject
|
||||
//
|
||||
this.buttonDelObject.Location = new System.Drawing.Point(3, 209);
|
||||
this.buttonDelObject.Location = new System.Drawing.Point(3, 167);
|
||||
this.buttonDelObject.Name = "buttonDelObject";
|
||||
this.buttonDelObject.Size = new System.Drawing.Size(134, 27);
|
||||
this.buttonDelObject.TabIndex = 3;
|
||||
@@ -100,17 +108,17 @@
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 15;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(3, 102);
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(6, 82);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(134, 94);
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(132, 79);
|
||||
this.listBoxStorages.TabIndex = 2;
|
||||
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddObject
|
||||
//
|
||||
this.buttonAddObject.Location = new System.Drawing.Point(3, 65);
|
||||
this.buttonAddObject.Location = new System.Drawing.Point(6, 51);
|
||||
this.buttonAddObject.Name = "buttonAddObject";
|
||||
this.buttonAddObject.Size = new System.Drawing.Size(134, 25);
|
||||
this.buttonAddObject.Size = new System.Drawing.Size(131, 25);
|
||||
this.buttonAddObject.TabIndex = 1;
|
||||
this.buttonAddObject.Text = "Добавить набор";
|
||||
this.buttonAddObject.UseVisualStyleBackColor = true;
|
||||
@@ -153,13 +161,51 @@
|
||||
this.ButtonAddCatamaran.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddCatamaran.Click += new System.EventHandler(this.ButtonAddCatamaran_Click);
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(3, 19);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(141, 24);
|
||||
this.menuStrip.TabIndex = 5;
|
||||
this.menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// ToolStripMenuItem
|
||||
//
|
||||
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
|
||||
this.ToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
|
||||
this.ToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
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 = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.FileName = "openFileDialog1";
|
||||
//
|
||||
// FormCatamaranCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.ClientSize = new System.Drawing.Size(885, 461);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormCatamaranCollection";
|
||||
this.Text = "Набор катамаранов";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
@@ -167,6 +213,8 @@
|
||||
this.groupBoxTools.PerformLayout();
|
||||
this.groupBoxSets.ResumeLayout(false);
|
||||
this.groupBoxSets.PerformLayout();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@@ -184,5 +232,11 @@
|
||||
private Button buttonDelObject;
|
||||
private ListBox listBoxStorages;
|
||||
private TextBox textBoxStorageName;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem ToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,18 @@
|
||||
using Catamaran.DrawningObjects;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Catamaran.DrawningObjects;
|
||||
using Catamaran.Exceptions;
|
||||
using Catamaran.Generics;
|
||||
using Catamaran.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
@@ -13,16 +25,21 @@ namespace Catamaran
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly CatamaransGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormCatamaranCollection()
|
||||
public FormCatamaranCollection(ILogger<FormCatamaranCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new CatamaransGenericStorage(pictureBoxCollection.Width,pictureBoxCollection.Height);
|
||||
_storage = new CatamaransGenericStorage(pictureBoxCollection.Width,
|
||||
pictureBoxCollection.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Заполнение listBoxStorages
|
||||
/// </summary>
|
||||
@@ -45,7 +62,6 @@ namespace Catamaran
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
@@ -61,14 +77,43 @@ namespace Catamaran
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Добавлен набор:{ textBoxStorageName.Text}");
|
||||
}
|
||||
private void AddCatamaran(DrawningCatamaran drawningCatamaran)
|
||||
{
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning("Добавление пустого объекта");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (obj + drawningCatamaran)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowCatamarans();
|
||||
_logger.LogInformation($"Объект добавлен");
|
||||
}
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowCatamarans();
|
||||
@@ -84,17 +129,17 @@ namespace Catamaran
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
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(name);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Удален набор: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
@@ -102,6 +147,7 @@ namespace Catamaran
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
@@ -109,20 +155,11 @@ namespace Catamaran
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormCatamaran form = new FormCatamaran();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (obj + form.SelectedCatamaran)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowCatamarans();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
var formBoatConfig = new FormCatamaranConfig();
|
||||
// TODO Call method AddEvent from FormCatamaranConfig
|
||||
var FormCatamaranConfig = new FormCatamaranConfig();
|
||||
FormCatamaranConfig.AddEvent(AddCatamaran);
|
||||
FormCatamaranConfig.Show();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
@@ -147,17 +184,31 @@ namespace Catamaran
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
try
|
||||
{
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
_logger.LogInformation($"Удален объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty} по номеру {pos}");
|
||||
pictureBoxCollection.Image = obj.ShowCatamarans();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
catch (CatamaranNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Нет объекта{ex.Message} из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
_logger.LogWarning($"Было введено не число");
|
||||
MessageBox.Show("Введите число");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
@@ -177,7 +228,54 @@ namespace Catamaran
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowCatamarans();
|
||||
|
||||
}
|
||||
/// <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.Information);
|
||||
_logger.LogWarning($"Не удалось сохранить информацию в файл: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
{
|
||||
// TODO продумать логику
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"Данные загружены из файла {openFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogWarning($"Не удалось загрузить информацию из файла: {ex.Message}");
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,16 @@
|
||||
<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="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>125, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>254, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>96</value>
|
||||
</metadata>
|
||||
</root>
|
||||
414
base/Catamaran/Catamaran/FormCatamaranConfig.Designer.cs
generated
Normal file
414
base/Catamaran/Catamaran/FormCatamaranConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,414 @@
|
||||
namespace Catamaran
|
||||
{
|
||||
partial class FormCatamaranConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxParameters = new System.Windows.Forms.GroupBox();
|
||||
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBoxColor = new System.Windows.Forms.GroupBox();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panelWhite = new System.Windows.Forms.Panel();
|
||||
this.panelGray = new System.Windows.Forms.Panel();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.checkBoxSail = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxFloatDetails = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonOk = new System.Windows.Forms.Button();
|
||||
this.labelAddColor = new System.Windows.Forms.Label();
|
||||
this.labelBodyColor = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxParameters.SuspendLayout();
|
||||
this.groupBoxColor.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
this.panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxParameters
|
||||
//
|
||||
this.groupBoxParameters.Controls.Add(this.labelModifiedObject);
|
||||
this.groupBoxParameters.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBoxParameters.Controls.Add(this.groupBoxColor);
|
||||
this.groupBoxParameters.Controls.Add(this.checkBoxSail);
|
||||
this.groupBoxParameters.Controls.Add(this.checkBoxFloatDetails);
|
||||
this.groupBoxParameters.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBoxParameters.Controls.Add(this.labelWeight);
|
||||
this.groupBoxParameters.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxParameters.Location = new System.Drawing.Point(18, 9);
|
||||
this.groupBoxParameters.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBoxParameters.Name = "groupBoxParameters";
|
||||
this.groupBoxParameters.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBoxParameters.Size = new System.Drawing.Size(524, 260);
|
||||
this.groupBoxParameters.TabIndex = 0;
|
||||
this.groupBoxParameters.TabStop = false;
|
||||
this.groupBoxParameters.Text = "Параметры";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelModifiedObject.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.labelModifiedObject.Location = new System.Drawing.Point(399, 205);
|
||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||
this.labelModifiedObject.Size = new System.Drawing.Size(106, 28);
|
||||
this.labelModifiedObject.TabIndex = 8;
|
||||
this.labelModifiedObject.Text = "Продвинутый";
|
||||
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(274, 205);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(109, 28);
|
||||
this.labelSimpleObject.TabIndex = 7;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// groupBoxColor
|
||||
//
|
||||
this.groupBoxColor.Controls.Add(this.panelRed);
|
||||
this.groupBoxColor.Controls.Add(this.panelBlue);
|
||||
this.groupBoxColor.Controls.Add(this.panelYellow);
|
||||
this.groupBoxColor.Controls.Add(this.panelWhite);
|
||||
this.groupBoxColor.Controls.Add(this.panelGray);
|
||||
this.groupBoxColor.Controls.Add(this.panelBlack);
|
||||
this.groupBoxColor.Controls.Add(this.panelPurple);
|
||||
this.groupBoxColor.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColor.Location = new System.Drawing.Point(274, 28);
|
||||
this.groupBoxColor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBoxColor.Name = "groupBoxColor";
|
||||
this.groupBoxColor.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.groupBoxColor.Size = new System.Drawing.Size(231, 162);
|
||||
this.groupBoxColor.TabIndex = 6;
|
||||
this.groupBoxColor.TabStop = false;
|
||||
this.groupBoxColor.Text = "Цвета";
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Tomato;
|
||||
this.panelRed.Location = new System.Drawing.Point(6, 29);
|
||||
this.panelRed.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelRed.TabIndex = 1;
|
||||
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.CornflowerBlue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(125, 29);
|
||||
this.panelBlue.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelBlue.TabIndex = 1;
|
||||
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Gold;
|
||||
this.panelYellow.Location = new System.Drawing.Point(187, 29);
|
||||
this.panelYellow.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelYellow.TabIndex = 1;
|
||||
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(5, 86);
|
||||
this.panelWhite.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelWhite.TabIndex = 1;
|
||||
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||
this.panelGray.Location = new System.Drawing.Point(65, 86);
|
||||
this.panelGray.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelGray.Name = "panelGray";
|
||||
this.panelGray.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelGray.TabIndex = 1;
|
||||
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(125, 86);
|
||||
this.panelBlack.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelBlack.TabIndex = 1;
|
||||
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Violet;
|
||||
this.panelPurple.Location = new System.Drawing.Point(187, 86);
|
||||
this.panelPurple.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelPurple.TabIndex = 1;
|
||||
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.LightGreen;
|
||||
this.panelGreen.Location = new System.Drawing.Point(65, 29);
|
||||
this.panelGreen.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(40, 40);
|
||||
this.panelGreen.TabIndex = 0;
|
||||
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// checkBoxSail
|
||||
//
|
||||
this.checkBoxSail.AutoSize = true;
|
||||
this.checkBoxSail.Location = new System.Drawing.Point(13, 148);
|
||||
this.checkBoxSail.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.checkBoxSail.Name = "checkBoxSail";
|
||||
this.checkBoxSail.Size = new System.Drawing.Size(164, 19);
|
||||
this.checkBoxSail.TabIndex = 5;
|
||||
this.checkBoxSail.Text = "Признак наличия паруса";
|
||||
this.checkBoxSail.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxFloatDetails
|
||||
//
|
||||
this.checkBoxFloatDetails.AutoSize = true;
|
||||
this.checkBoxFloatDetails.Location = new System.Drawing.Point(13, 114);
|
||||
this.checkBoxFloatDetails.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.checkBoxFloatDetails.Name = "checkBoxFloatDetails";
|
||||
this.checkBoxFloatDetails.Size = new System.Drawing.Size(185, 19);
|
||||
this.checkBoxFloatDetails.TabIndex = 4;
|
||||
this.checkBoxFloatDetails.Text = "Признак наличия поплавков";
|
||||
this.checkBoxFloatDetails.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(94, 60);
|
||||
this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.numericUpDownWeight.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(51, 23);
|
||||
this.numericUpDownWeight.TabIndex = 3;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(94, 28);
|
||||
this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(59, 23);
|
||||
this.numericUpDownSpeed.TabIndex = 2;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(13, 68);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(26, 15);
|
||||
this.labelWeight.TabIndex = 1;
|
||||
this.labelWeight.Text = "Вес";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(13, 36);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(59, 15);
|
||||
this.labelSpeed.TabIndex = 0;
|
||||
this.labelSpeed.Text = "Скорость";
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.AllowDrop = true;
|
||||
this.panel1.Controls.Add(this.buttonCancel);
|
||||
this.panel1.Controls.Add(this.buttonOk);
|
||||
this.panel1.Controls.Add(this.labelAddColor);
|
||||
this.panel1.Controls.Add(this.labelBodyColor);
|
||||
this.panel1.Controls.Add(this.pictureBoxObject);
|
||||
this.panel1.Location = new System.Drawing.Point(560, 9);
|
||||
this.panel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(312, 263);
|
||||
this.panel1.TabIndex = 0;
|
||||
this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(175, 223);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(108, 24);
|
||||
this.buttonCancel.TabIndex = 12;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
this.buttonOk.Location = new System.Drawing.Point(38, 223);
|
||||
this.buttonOk.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonOk.Name = "buttonOk";
|
||||
this.buttonOk.Size = new System.Drawing.Size(108, 24);
|
||||
this.buttonOk.TabIndex = 11;
|
||||
this.buttonOk.Text = "Добавить";
|
||||
this.buttonOk.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// labelAddColor
|
||||
//
|
||||
this.labelAddColor.AllowDrop = true;
|
||||
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelAddColor.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.labelAddColor.Location = new System.Drawing.Point(175, 22);
|
||||
this.labelAddColor.Name = "labelAddColor";
|
||||
this.labelAddColor.Size = new System.Drawing.Size(109, 28);
|
||||
this.labelAddColor.TabIndex = 10;
|
||||
this.labelAddColor.Text = "Доп. цвет";
|
||||
this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// labelBodyColor
|
||||
//
|
||||
this.labelBodyColor.AllowDrop = true;
|
||||
this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelBodyColor.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.labelBodyColor.Location = new System.Drawing.Point(38, 22);
|
||||
this.labelBodyColor.Name = "labelBodyColor";
|
||||
this.labelBodyColor.Size = new System.Drawing.Size(109, 28);
|
||||
this.labelBodyColor.TabIndex = 9;
|
||||
this.labelBodyColor.Text = "Цвет";
|
||||
this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelBodyColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.labelBodyColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(15, 58);
|
||||
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(282, 160);
|
||||
this.pictureBoxObject.TabIndex = 0;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// FormCatamaranConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 277);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.groupBoxParameters);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormCatamaranConfig";
|
||||
this.Text = "FormShipConfig";
|
||||
this.groupBoxParameters.ResumeLayout(false);
|
||||
this.groupBoxParameters.PerformLayout();
|
||||
this.groupBoxColor.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
this.panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxParameters;
|
||||
private GroupBox groupBoxColor;
|
||||
private Panel panelRed;
|
||||
private Panel panelBlue;
|
||||
private Panel panelYellow;
|
||||
private Panel panelWhite;
|
||||
private Panel panelGray;
|
||||
private Panel panelBlack;
|
||||
private Panel panelPurple;
|
||||
private Panel panelGreen;
|
||||
private CheckBox checkBoxSail;
|
||||
private CheckBox checkBoxFloatDetails;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private Panel panel1;
|
||||
private Button buttonOk;
|
||||
private Label labelAddColor;
|
||||
private Label labelBodyColor;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
||||
174
base/Catamaran/Catamaran/FormCatamaranConfig.cs
Normal file
174
base/Catamaran/Catamaran/FormCatamaranConfig.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
using Catamaran.DrawningObjects;
|
||||
using Catamaran.Entities;
|
||||
using Catamaran.Generics;
|
||||
using Catamaran.MovementStrategy;
|
||||
namespace Catamaran
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма создания объекта
|
||||
/// </summary>
|
||||
public partial class FormCatamaranConfig : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная-выбранный катамаран
|
||||
/// </summary>
|
||||
DrawningCatamaran? _catamaran = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawningCatamaran>? EventAddCatamaran;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormCatamaranConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelGray.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
// TODO buttonCancel.Click with lambda
|
||||
buttonCancel.Click += (s, e) => Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать катамаран
|
||||
/// </summary>
|
||||
private void DrawCatamaran()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_catamaran?.SetPosition(5, 5);
|
||||
_catamaran?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
internal void AddEvent(Action<DrawningCatamaran> ev)
|
||||
{
|
||||
if (EventAddCatamaran == null)
|
||||
{
|
||||
EventAddCatamaran = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddCatamaran += ev;
|
||||
}
|
||||
}
|
||||
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||
DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
ILogger<FormCatamaranCollection> logger = new NullLogger<FormCatamaranCollection>();
|
||||
FormCatamaranCollection form = new FormCatamaranCollection(logger);
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_catamaran = new DrawningCatamaran((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_catamaran = new DrawningSailCatamaran((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxSail.Checked,
|
||||
checkBoxFloatDetails.Checked, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawCatamaran();
|
||||
}
|
||||
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
|
||||
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_catamaran == null)
|
||||
return;
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelBodyColor":
|
||||
_catamaran.SetColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAddColor":
|
||||
if (!(_catamaran is DrawningSailCatamaran))
|
||||
return;
|
||||
(_catamaran as DrawningSailCatamaran).SetAddColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawCatamaran();
|
||||
}
|
||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление машины
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddCatamaran?.Invoke(_catamaran);
|
||||
Close();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
60
base/Catamaran/Catamaran/FormCatamaranConfig.resx
Normal file
60
base/Catamaran/Catamaran/FormCatamaranConfig.resx
Normal file
@@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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">
|
||||
<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" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</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" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -1,3 +1,9 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
internal static class Program
|
||||
@@ -8,10 +14,31 @@ namespace Catamaran
|
||||
[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 FormCatamaranCollection());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormCatamaranCollection>());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormCatamaranCollection>().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}appSetting.json", optional: false, reloadOnChange: true).Build();
|
||||
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Catamaran.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
@@ -42,33 +43,22 @@ namespace Catamaran.Generics
|
||||
/// <returns></returns>
|
||||
public bool Insert(T catamaran)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
if (_places.Count == _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Insert(catamaran, 0);
|
||||
return true;
|
||||
return Insert(catamaran, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="catamaran">Добавляемый катамаран</param>
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T catamaran, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой,
|
||||
//если нет, то проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (position < 0 || position >= _maxCount)
|
||||
throw new CatamaranNotFoundException(position);
|
||||
|
||||
_places.Insert(position, catamaran);
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
_places.Insert(0, catamaran);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -80,9 +70,13 @@ namespace Catamaran.Generics
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position < 0 || position >= Count)
|
||||
if (position >= Count || position < 0)
|
||||
{
|
||||
return false;
|
||||
throw new CatamaranNotFoundException("Invalid operation");
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
throw new CatamaranNotFoundException(position);
|
||||
}
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
|
||||
21
base/Catamaran/Catamaran/StorageOverflowException.cs
Normal file
21
base/Catamaran/Catamaran/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 Catamaran.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) { }
|
||||
}
|
||||
}
|
||||
14
base/Catamaran/Catamaran/nlog.config
Normal file
14
base/Catamaran/Catamaran/nlog.config
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="carlog-
|
||||
${shortdate}.log" />
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user