Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c7a4a2c6b | ||
|
|
7e1761c5c8 | ||
|
|
8b75e1f20b | ||
|
|
feeb709fd2 |
20
Liner/AppSettings.json
Normal file
20
Liner/AppSettings.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "Loco"
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Liner/Drawing/ExtentionDrawingLiner.cs
Normal file
69
Liner/Drawing/ExtentionDrawingLiner.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Liner.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityLiner
|
||||
/// </summary>
|
||||
public static class ExtentionDrawningLiner
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawingLiner? CreateDrawingLiner(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingLiner(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawingBigLiner(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="drawingLiner">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawingLiner drawingLiner,
|
||||
char separatorForObject)
|
||||
{
|
||||
var liner = drawingLiner.EntityLiner;
|
||||
if (liner == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str =
|
||||
$"{liner.Speed}{separatorForObject}{liner.Weight}{separatorForObject}{liner.BottomColor.Name}";
|
||||
if (liner is not EntityBigLiner bigLiner)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{bigLiner.BodyColor.Name}{separatorForObject}{bigLiner.SwimmingPool}{separatorForObject}" +
|
||||
$"{bigLiner.Deck}";
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Liner/Exceptions/LinerNotFoundException.cs
Normal file
21
Liner/Exceptions/LinerNotFoundException.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class LinerNotFoundException : ApplicationException
|
||||
{
|
||||
public LinerNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public LinerNotFoundException() : base() { }
|
||||
public LinerNotFoundException(string message) : base(message) { }
|
||||
public LinerNotFoundException(string message, Exception exception) :
|
||||
base(message, exception) { }
|
||||
protected LinerNotFoundException(SerializationInfo info,
|
||||
StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
21
Liner/Exceptions/StorageOverflowException.cs
Normal file
21
Liner/Exceptions/StorageOverflowException.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner.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) { }
|
||||
}
|
||||
}
|
||||
123
Liner/FormLinerCollection.Designer.cs
generated
123
Liner/FormLinerCollection.Designer.cs
generated
@@ -39,9 +39,16 @@
|
||||
textBoxNumber = new TextBox();
|
||||
buttonAddLiner = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
FileMenuStrip = new MenuStrip();
|
||||
FileToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
groupBoxTools.SuspendLayout();
|
||||
Storages.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
FileMenuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
@@ -51,9 +58,11 @@
|
||||
groupBoxTools.Controls.Add(buttonDeleteLiner);
|
||||
groupBoxTools.Controls.Add(textBoxNumber);
|
||||
groupBoxTools.Controls.Add(buttonAddLiner);
|
||||
groupBoxTools.Location = new Point(739, 0);
|
||||
groupBoxTools.Location = new Point(845, 0);
|
||||
groupBoxTools.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(211, 565);
|
||||
groupBoxTools.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBoxTools.Size = new Size(241, 753);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Tools";
|
||||
@@ -64,9 +73,11 @@
|
||||
Storages.Controls.Add(buttonDeleteSet);
|
||||
Storages.Controls.Add(textBoxStorageName);
|
||||
Storages.Controls.Add(buttonAddStorage);
|
||||
Storages.Location = new Point(7, 19);
|
||||
Storages.Location = new Point(8, 29);
|
||||
Storages.Margin = new Padding(3, 4, 3, 4);
|
||||
Storages.Name = "Storages";
|
||||
Storages.Size = new Size(200, 276);
|
||||
Storages.Padding = new Padding(3, 4, 3, 4);
|
||||
Storages.Size = new Size(229, 364);
|
||||
Storages.TabIndex = 4;
|
||||
Storages.TabStop = false;
|
||||
Storages.Text = "Sets";
|
||||
@@ -74,18 +85,20 @@
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 15;
|
||||
listBoxStorages.Location = new Point(6, 113);
|
||||
listBoxStorages.ItemHeight = 20;
|
||||
listBoxStorages.Location = new Point(7, 151);
|
||||
listBoxStorages.Margin = new Padding(3, 4, 3, 4);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(187, 109);
|
||||
listBoxStorages.Size = new Size(213, 144);
|
||||
listBoxStorages.TabIndex = 4;
|
||||
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||
//
|
||||
// buttonDeleteSet
|
||||
//
|
||||
buttonDeleteSet.Location = new Point(10, 228);
|
||||
buttonDeleteSet.Location = new Point(11, 304);
|
||||
buttonDeleteSet.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDeleteSet.Name = "buttonDeleteSet";
|
||||
buttonDeleteSet.Size = new Size(184, 30);
|
||||
buttonDeleteSet.Size = new Size(210, 40);
|
||||
buttonDeleteSet.TabIndex = 3;
|
||||
buttonDeleteSet.Text = "Delete Set";
|
||||
buttonDeleteSet.UseVisualStyleBackColor = true;
|
||||
@@ -93,16 +106,18 @@
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(34, 39);
|
||||
textBoxStorageName.Location = new Point(39, 52);
|
||||
textBoxStorageName.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(139, 23);
|
||||
textBoxStorageName.Size = new Size(158, 27);
|
||||
textBoxStorageName.TabIndex = 2;
|
||||
//
|
||||
// buttonAddStorage
|
||||
//
|
||||
buttonAddStorage.Location = new Point(10, 68);
|
||||
buttonAddStorage.Location = new Point(11, 91);
|
||||
buttonAddStorage.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddStorage.Name = "buttonAddStorage";
|
||||
buttonAddStorage.Size = new Size(184, 30);
|
||||
buttonAddStorage.Size = new Size(210, 40);
|
||||
buttonAddStorage.TabIndex = 1;
|
||||
buttonAddStorage.Text = "Add Set";
|
||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||
@@ -110,9 +125,10 @@
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(11, 501);
|
||||
buttonRefreshCollection.Location = new Point(13, 668);
|
||||
buttonRefreshCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(194, 40);
|
||||
buttonRefreshCollection.Size = new Size(222, 53);
|
||||
buttonRefreshCollection.TabIndex = 3;
|
||||
buttonRefreshCollection.Text = "Refresh Collection";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
@@ -120,9 +136,10 @@
|
||||
//
|
||||
// buttonDeleteLiner
|
||||
//
|
||||
buttonDeleteLiner.Location = new Point(11, 408);
|
||||
buttonDeleteLiner.Location = new Point(13, 544);
|
||||
buttonDeleteLiner.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDeleteLiner.Name = "buttonDeleteLiner";
|
||||
buttonDeleteLiner.Size = new Size(194, 40);
|
||||
buttonDeleteLiner.Size = new Size(222, 53);
|
||||
buttonDeleteLiner.TabIndex = 2;
|
||||
buttonDeleteLiner.Text = "Delete Liner";
|
||||
buttonDeleteLiner.UseVisualStyleBackColor = true;
|
||||
@@ -130,16 +147,18 @@
|
||||
//
|
||||
// textBoxNumber
|
||||
//
|
||||
textBoxNumber.Location = new Point(41, 368);
|
||||
textBoxNumber.Location = new Point(47, 491);
|
||||
textBoxNumber.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxNumber.Name = "textBoxNumber";
|
||||
textBoxNumber.Size = new Size(139, 23);
|
||||
textBoxNumber.Size = new Size(158, 27);
|
||||
textBoxNumber.TabIndex = 1;
|
||||
//
|
||||
// buttonAddLiner
|
||||
//
|
||||
buttonAddLiner.Location = new Point(11, 313);
|
||||
buttonAddLiner.Location = new Point(13, 417);
|
||||
buttonAddLiner.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddLiner.Name = "buttonAddLiner";
|
||||
buttonAddLiner.Size = new Size(194, 40);
|
||||
buttonAddLiner.Size = new Size(222, 53);
|
||||
buttonAddLiner.TabIndex = 0;
|
||||
buttonAddLiner.Text = "Add Liner";
|
||||
buttonAddLiner.UseVisualStyleBackColor = true;
|
||||
@@ -147,19 +166,64 @@
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new Point(2, 0);
|
||||
pictureBoxCollection.Location = new Point(2, 36);
|
||||
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(731, 565);
|
||||
pictureBoxCollection.Size = new Size(835, 717);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FileMenuStrip
|
||||
//
|
||||
FileMenuStrip.ImageScalingSize = new Size(20, 20);
|
||||
FileMenuStrip.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem });
|
||||
FileMenuStrip.Location = new Point(0, 0);
|
||||
FileMenuStrip.Name = "FileMenuStrip";
|
||||
FileMenuStrip.Padding = new Padding(7, 3, 0, 3);
|
||||
FileMenuStrip.Size = new Size(1087, 30);
|
||||
FileMenuStrip.TabIndex = 2;
|
||||
FileMenuStrip.Text = "FileMenuStrip";
|
||||
//
|
||||
// FileToolStripMenuItem
|
||||
//
|
||||
FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||
FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||
FileToolStripMenuItem.Size = new Size(49, 24);
|
||||
FileToolStripMenuItem.Text = "FILE";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(130, 26);
|
||||
SaveToolStripMenuItem.Text = "SAVE";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(130, 26);
|
||||
LoadToolStripMenuItem.Text = "LOAD";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.FileName = "saveFile";
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormLinerCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(951, 568);
|
||||
ClientSize = new Size(1087, 757);
|
||||
Controls.Add(FileMenuStrip);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBoxTools);
|
||||
MainMenuStrip = FileMenuStrip;
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormLinerCollection";
|
||||
Text = "Liner Collection";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
@@ -167,7 +231,10 @@
|
||||
Storages.ResumeLayout(false);
|
||||
Storages.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
FileMenuStrip.ResumeLayout(false);
|
||||
FileMenuStrip.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -183,5 +250,11 @@
|
||||
private Button buttonDeleteSet;
|
||||
private TextBox textBoxStorageName;
|
||||
private Button buttonAddStorage;
|
||||
private MenuStrip FileMenuStrip;
|
||||
private ToolStripMenuItem FileToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Liner.Exceptions;
|
||||
using System.Xml.Linq;
|
||||
namespace Liner
|
||||
{
|
||||
/// <summary>
|
||||
@@ -23,12 +25,17 @@ namespace Liner
|
||||
/// </summary>
|
||||
private readonly LinersGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormLinerCollection()
|
||||
public FormLinerCollection(ILogger<FormLinerCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new LinersGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@@ -39,6 +46,7 @@ namespace Liner
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Добавление лайнера не удалось (индекс вне границ)");
|
||||
return;
|
||||
}
|
||||
var formLinerConfig = new FormLinerConfig();
|
||||
@@ -50,21 +58,32 @@ namespace Liner
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Добавление лайнера не удалось (индекс вне границ)");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning($"Добавление лайнера не удалось (нет хранилища)");
|
||||
return;
|
||||
}
|
||||
if ((obj + liner) != -1)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowLiners();
|
||||
if ((obj + liner) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation($"Добавление лайнера успешно {listBoxStorages.SelectedItem.ToString()}");
|
||||
pictureBoxCollection.Image = obj.ShowLiners();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning($"Добавление лайнера в {listBoxStorages.SelectedItem.ToString()} не удалось (переполнение коллекции)");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -74,39 +93,56 @@ namespace Liner
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveLiner_Click(object sender, EventArgs e)
|
||||
{
|
||||
int pos;
|
||||
int pos = 0; //фикс недосмотра
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Удаление лайнера не удалось (индекс вне границ)");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning($"Удаление лайнера не удалось (нет хранилища)");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
_logger.LogWarning($"Удаление лайнера не удалось (выбран вариант 'Нет')");
|
||||
return;
|
||||
}
|
||||
if (textBoxNumber.Text != "")
|
||||
if (textBoxNumber.Text != "") //улучшил проверку
|
||||
{
|
||||
pos = Convert.ToInt32(textBoxNumber.Text);
|
||||
if(!int.TryParse(textBoxNumber.Text, out pos))
|
||||
{
|
||||
_logger.LogWarning($"Удаление лайнера не удалось (неверный формат)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"Удаление лайнера не удалось (пустое поле ввода)");
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
return;
|
||||
}
|
||||
pos = 0;
|
||||
if (obj - pos)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowLiners();
|
||||
if (obj - pos)
|
||||
{
|
||||
_logger.LogInformation($"Удаление лайнера успешно {listBoxStorages.SelectedItem.ToString()} {pos}");
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowLiners();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"Удаление лайнера не удалось(обьект не найден)");
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (LinerNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogWarning($"Удаление лайнера не удалось {ex.Message}");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -118,11 +154,13 @@ namespace Liner
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
_logger.LogWarning($"Обновление набора не удалось (не все данные заполнены)");
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text} ");
|
||||
ReloadObjects();
|
||||
}
|
||||
/// <summary>
|
||||
@@ -144,12 +182,15 @@ namespace Liner
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Удаление набора не удалось (индекс вне границ)");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||
_storage.DelSet(name);
|
||||
_logger.LogInformation($"Удаление набора успешно: {name}");
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
@@ -162,13 +203,16 @@ namespace Liner
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Обновление объектов не удалось (индекс вне границ)");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning($"Обновление объектов не удалось (нет хранилища)");
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation($"Обновление объектов успешно");
|
||||
pictureBoxCollection.Image = obj.ShowLiners();
|
||||
}
|
||||
/// <summary>
|
||||
@@ -191,5 +235,42 @@ namespace Liner
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.SaveData(saveFileDialog.FileName);
|
||||
_logger.LogInformation($"Cохранение успешно");
|
||||
MessageBox.Show("Сохранение прошло успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Сохранение не удалось {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
_logger.LogInformation($"Загрузка успешна");
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Загрузка не удалась {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<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="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>
|
||||
@@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="FileMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>144, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>284, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -50,7 +50,11 @@ namespace Liner.Generics
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// </summary>
|
||||
/// Получение объектов коллекции
|
||||
/// <summary>
|
||||
public IEnumerable<T?> GetLiners => _collection.GetLiners();
|
||||
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
|
||||
@@ -30,6 +30,18 @@ namespace Liner.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>
|
||||
@@ -76,5 +88,88 @@ namespace Liner.Generics
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации по лайнерам в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,
|
||||
LinerGenericCollection<DrawingLiner, DrawingObjectLiner>> record in _linerStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingLiner? elem in record.Value.GetLiners)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
string dataStr = data.ToString();
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.WriteLine("LinerStorage");
|
||||
writer.WriteLine(dataStr);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по автомобилям в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader reader = new StreamReader(filename))
|
||||
{
|
||||
string checker = reader.ReadLine();
|
||||
if (checker == null)
|
||||
{
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
}
|
||||
if (!checker.StartsWith("LinerStorage"))
|
||||
{
|
||||
throw new FormatException("Неверный формат данных");
|
||||
}
|
||||
_linerStorages.Clear();
|
||||
string strs;
|
||||
while ((strs = reader.ReadLine()) != null) //переделал ужасную логику
|
||||
{
|
||||
if (strs == null)
|
||||
break;
|
||||
if (strs == string.Empty)
|
||||
break;
|
||||
string name = strs.Split('|')[0];
|
||||
LinerGenericCollection<DrawingLiner, DrawingObjectLiner> collection = new(_pictureWidth, _pictureHeight);
|
||||
foreach (string data in strs.Split('|')[1].Split(';').Reverse())
|
||||
{
|
||||
DrawingLiner? liner =
|
||||
data?.CreateDrawingLiner(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (liner != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
int? tmp = collection + liner;
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
throw new ApplicationException($"Ошибка добавления в коллекцию: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
_linerStorages.Add(name, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Liner.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -41,12 +42,13 @@ namespace Liner.Generics
|
||||
/// <returns></returns>
|
||||
public int Insert(T liner)
|
||||
{
|
||||
if (_places.Count + 1 <= _maxCount)
|
||||
if (_places.Count >= _maxCount)
|
||||
{
|
||||
_places.Insert(0, liner);
|
||||
return 0;
|
||||
throw new StorageOverflowException(_places.Count);
|
||||
}
|
||||
return -1;
|
||||
_places.Insert(0, liner);
|
||||
return 0;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@@ -56,12 +58,16 @@ namespace Liner.Generics
|
||||
/// <returns></returns>
|
||||
public int Insert(T liner, int position)
|
||||
{
|
||||
if (_places.Count + 1 <= _maxCount && _places.Count >= position)
|
||||
if(_places.Count >= _maxCount)
|
||||
{
|
||||
_places.Insert(position, liner);
|
||||
return position;
|
||||
throw new StorageOverflowException(_places.Count);
|
||||
}
|
||||
return -1;
|
||||
if(position < 0 || position > _places.Count)
|
||||
{
|
||||
throw new LinerNotFoundException(position);
|
||||
}
|
||||
_places.Insert(position, liner);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@@ -75,7 +81,7 @@ namespace Liner.Generics
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
throw new LinerNotFoundException(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
@@ -94,9 +100,13 @@ namespace Liner.Generics
|
||||
}
|
||||
set
|
||||
{
|
||||
if(_places.Count + 1 <= _maxCount && position >= 0 && _places.Count > position)
|
||||
try
|
||||
{
|
||||
_places[position] = value;
|
||||
Insert(value, position);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,23 @@
|
||||
<None Remove="MovingStrategy\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<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="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" Version="8.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.7" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
namespace Liner
|
||||
{
|
||||
internal static class Program
|
||||
@@ -11,7 +18,28 @@ namespace Liner
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormLinerCollection());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
ApplicationConfiguration.Initialize();
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormLinerCollection>());
|
||||
}
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormLinerCollection>().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.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user