Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c7a4a2c6b | ||
|
|
7e1761c5c8 |
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
74
Liner/FormLinerCollection.Designer.cs
generated
74
Liner/FormLinerCollection.Designer.cs
generated
@@ -58,9 +58,11 @@
|
|||||||
groupBoxTools.Controls.Add(buttonDeleteLiner);
|
groupBoxTools.Controls.Add(buttonDeleteLiner);
|
||||||
groupBoxTools.Controls.Add(textBoxNumber);
|
groupBoxTools.Controls.Add(textBoxNumber);
|
||||||
groupBoxTools.Controls.Add(buttonAddLiner);
|
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.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.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Tools";
|
groupBoxTools.Text = "Tools";
|
||||||
@@ -71,9 +73,11 @@
|
|||||||
Storages.Controls.Add(buttonDeleteSet);
|
Storages.Controls.Add(buttonDeleteSet);
|
||||||
Storages.Controls.Add(textBoxStorageName);
|
Storages.Controls.Add(textBoxStorageName);
|
||||||
Storages.Controls.Add(buttonAddStorage);
|
Storages.Controls.Add(buttonAddStorage);
|
||||||
Storages.Location = new Point(7, 22);
|
Storages.Location = new Point(8, 29);
|
||||||
|
Storages.Margin = new Padding(3, 4, 3, 4);
|
||||||
Storages.Name = "Storages";
|
Storages.Name = "Storages";
|
||||||
Storages.Size = new Size(200, 273);
|
Storages.Padding = new Padding(3, 4, 3, 4);
|
||||||
|
Storages.Size = new Size(229, 364);
|
||||||
Storages.TabIndex = 4;
|
Storages.TabIndex = 4;
|
||||||
Storages.TabStop = false;
|
Storages.TabStop = false;
|
||||||
Storages.Text = "Sets";
|
Storages.Text = "Sets";
|
||||||
@@ -81,18 +85,20 @@
|
|||||||
// listBoxStorages
|
// listBoxStorages
|
||||||
//
|
//
|
||||||
listBoxStorages.FormattingEnabled = true;
|
listBoxStorages.FormattingEnabled = true;
|
||||||
listBoxStorages.ItemHeight = 15;
|
listBoxStorages.ItemHeight = 20;
|
||||||
listBoxStorages.Location = new Point(6, 113);
|
listBoxStorages.Location = new Point(7, 151);
|
||||||
|
listBoxStorages.Margin = new Padding(3, 4, 3, 4);
|
||||||
listBoxStorages.Name = "listBoxStorages";
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
listBoxStorages.Size = new Size(187, 109);
|
listBoxStorages.Size = new Size(213, 144);
|
||||||
listBoxStorages.TabIndex = 4;
|
listBoxStorages.TabIndex = 4;
|
||||||
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// buttonDeleteSet
|
// 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.Name = "buttonDeleteSet";
|
||||||
buttonDeleteSet.Size = new Size(184, 30);
|
buttonDeleteSet.Size = new Size(210, 40);
|
||||||
buttonDeleteSet.TabIndex = 3;
|
buttonDeleteSet.TabIndex = 3;
|
||||||
buttonDeleteSet.Text = "Delete Set";
|
buttonDeleteSet.Text = "Delete Set";
|
||||||
buttonDeleteSet.UseVisualStyleBackColor = true;
|
buttonDeleteSet.UseVisualStyleBackColor = true;
|
||||||
@@ -100,16 +106,18 @@
|
|||||||
//
|
//
|
||||||
// textBoxStorageName
|
// 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.Name = "textBoxStorageName";
|
||||||
textBoxStorageName.Size = new Size(139, 23);
|
textBoxStorageName.Size = new Size(158, 27);
|
||||||
textBoxStorageName.TabIndex = 2;
|
textBoxStorageName.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// buttonAddStorage
|
// 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.Name = "buttonAddStorage";
|
||||||
buttonAddStorage.Size = new Size(184, 30);
|
buttonAddStorage.Size = new Size(210, 40);
|
||||||
buttonAddStorage.TabIndex = 1;
|
buttonAddStorage.TabIndex = 1;
|
||||||
buttonAddStorage.Text = "Add Set";
|
buttonAddStorage.Text = "Add Set";
|
||||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||||
@@ -117,9 +125,10 @@
|
|||||||
//
|
//
|
||||||
// buttonRefreshCollection
|
// 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.Name = "buttonRefreshCollection";
|
||||||
buttonRefreshCollection.Size = new Size(194, 40);
|
buttonRefreshCollection.Size = new Size(222, 53);
|
||||||
buttonRefreshCollection.TabIndex = 3;
|
buttonRefreshCollection.TabIndex = 3;
|
||||||
buttonRefreshCollection.Text = "Refresh Collection";
|
buttonRefreshCollection.Text = "Refresh Collection";
|
||||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
@@ -127,9 +136,10 @@
|
|||||||
//
|
//
|
||||||
// buttonDeleteLiner
|
// 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.Name = "buttonDeleteLiner";
|
||||||
buttonDeleteLiner.Size = new Size(194, 40);
|
buttonDeleteLiner.Size = new Size(222, 53);
|
||||||
buttonDeleteLiner.TabIndex = 2;
|
buttonDeleteLiner.TabIndex = 2;
|
||||||
buttonDeleteLiner.Text = "Delete Liner";
|
buttonDeleteLiner.Text = "Delete Liner";
|
||||||
buttonDeleteLiner.UseVisualStyleBackColor = true;
|
buttonDeleteLiner.UseVisualStyleBackColor = true;
|
||||||
@@ -137,16 +147,18 @@
|
|||||||
//
|
//
|
||||||
// textBoxNumber
|
// 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.Name = "textBoxNumber";
|
||||||
textBoxNumber.Size = new Size(139, 23);
|
textBoxNumber.Size = new Size(158, 27);
|
||||||
textBoxNumber.TabIndex = 1;
|
textBoxNumber.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// buttonAddLiner
|
// 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.Name = "buttonAddLiner";
|
||||||
buttonAddLiner.Size = new Size(194, 40);
|
buttonAddLiner.Size = new Size(222, 53);
|
||||||
buttonAddLiner.TabIndex = 0;
|
buttonAddLiner.TabIndex = 0;
|
||||||
buttonAddLiner.Text = "Add Liner";
|
buttonAddLiner.Text = "Add Liner";
|
||||||
buttonAddLiner.UseVisualStyleBackColor = true;
|
buttonAddLiner.UseVisualStyleBackColor = true;
|
||||||
@@ -154,18 +166,21 @@
|
|||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(2, 27);
|
pictureBoxCollection.Location = new Point(2, 36);
|
||||||
|
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(731, 538);
|
pictureBoxCollection.Size = new Size(835, 717);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// FileMenuStrip
|
// FileMenuStrip
|
||||||
//
|
//
|
||||||
|
FileMenuStrip.ImageScalingSize = new Size(20, 20);
|
||||||
FileMenuStrip.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem });
|
FileMenuStrip.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem });
|
||||||
FileMenuStrip.Location = new Point(0, 0);
|
FileMenuStrip.Location = new Point(0, 0);
|
||||||
FileMenuStrip.Name = "FileMenuStrip";
|
FileMenuStrip.Name = "FileMenuStrip";
|
||||||
FileMenuStrip.Size = new Size(951, 24);
|
FileMenuStrip.Padding = new Padding(7, 3, 0, 3);
|
||||||
|
FileMenuStrip.Size = new Size(1087, 30);
|
||||||
FileMenuStrip.TabIndex = 2;
|
FileMenuStrip.TabIndex = 2;
|
||||||
FileMenuStrip.Text = "FileMenuStrip";
|
FileMenuStrip.Text = "FileMenuStrip";
|
||||||
//
|
//
|
||||||
@@ -173,20 +188,20 @@
|
|||||||
//
|
//
|
||||||
FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||||
FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||||
FileToolStripMenuItem.Size = new Size(40, 20);
|
FileToolStripMenuItem.Size = new Size(49, 24);
|
||||||
FileToolStripMenuItem.Text = "FILE";
|
FileToolStripMenuItem.Text = "FILE";
|
||||||
//
|
//
|
||||||
// SaveToolStripMenuItem
|
// SaveToolStripMenuItem
|
||||||
//
|
//
|
||||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
SaveToolStripMenuItem.Size = new Size(105, 22);
|
SaveToolStripMenuItem.Size = new Size(130, 26);
|
||||||
SaveToolStripMenuItem.Text = "SAVE";
|
SaveToolStripMenuItem.Text = "SAVE";
|
||||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// LoadToolStripMenuItem
|
// LoadToolStripMenuItem
|
||||||
//
|
//
|
||||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
LoadToolStripMenuItem.Size = new Size(105, 22);
|
LoadToolStripMenuItem.Size = new Size(130, 26);
|
||||||
LoadToolStripMenuItem.Text = "LOAD";
|
LoadToolStripMenuItem.Text = "LOAD";
|
||||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@@ -201,13 +216,14 @@
|
|||||||
//
|
//
|
||||||
// FormLinerCollection
|
// FormLinerCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(951, 568);
|
ClientSize = new Size(1087, 757);
|
||||||
Controls.Add(FileMenuStrip);
|
Controls.Add(FileMenuStrip);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
MainMenuStrip = FileMenuStrip;
|
MainMenuStrip = FileMenuStrip;
|
||||||
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
Name = "FormLinerCollection";
|
Name = "FormLinerCollection";
|
||||||
Text = "Liner Collection";
|
Text = "Liner Collection";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Liner.Exceptions;
|
||||||
|
using System.Xml.Linq;
|
||||||
namespace Liner
|
namespace Liner
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -23,12 +25,17 @@ namespace Liner
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly LinersGenericStorage _storage;
|
private readonly LinersGenericStorage _storage;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Логер
|
||||||
|
/// </summary>
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormLinerCollection()
|
public FormLinerCollection(ILogger<FormLinerCollection> logger)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_storage = new LinersGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new LinersGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@@ -39,6 +46,7 @@ namespace Liner
|
|||||||
{
|
{
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Добавление лайнера не удалось (индекс вне границ)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var formLinerConfig = new FormLinerConfig();
|
var formLinerConfig = new FormLinerConfig();
|
||||||
@@ -50,16 +58,21 @@ namespace Liner
|
|||||||
{
|
{
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Добавление лайнера не удалось (индекс вне границ)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Добавление лайнера не удалось (нет хранилища)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
if ((obj + liner) != -1)
|
if ((obj + liner) != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
|
_logger.LogInformation($"Добавление лайнера успешно {listBoxStorages.SelectedItem.ToString()}");
|
||||||
pictureBoxCollection.Image = obj.ShowLiners();
|
pictureBoxCollection.Image = obj.ShowLiners();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -67,6 +80,12 @@ namespace Liner
|
|||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ApplicationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning($"Добавление лайнера в {listBoxStorages.SelectedItem.ToString()} не удалось (переполнение коллекции)");
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора
|
/// Удаление объекта из набора
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -74,41 +93,58 @@ namespace Liner
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveLiner_Click(object sender, EventArgs e)
|
private void ButtonRemoveLiner_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos = 0; //фикс недосмотра
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Удаление лайнера не удалось (индекс вне границ)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Удаление лайнера не удалось (нет хранилища)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Удаление лайнера не удалось (выбран вариант 'Нет')");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (textBoxNumber.Text != "")
|
if (textBoxNumber.Text != "") //улучшил проверку
|
||||||
{
|
{
|
||||||
pos = Convert.ToInt32(textBoxNumber.Text);
|
if(!int.TryParse(textBoxNumber.Text, out pos))
|
||||||
|
{
|
||||||
|
_logger.LogWarning($"Удаление лайнера не удалось (неверный формат)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Удаление лайнера не удалось (пустое поле ввода)");
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pos = 0;
|
try
|
||||||
|
{
|
||||||
if (obj - pos)
|
if (obj - pos)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation($"Удаление лайнера успешно {listBoxStorages.SelectedItem.ToString()} {pos}");
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = obj.ShowLiners();
|
pictureBoxCollection.Image = obj.ShowLiners();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Удаление лайнера не удалось(обьект не найден)");
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (LinerNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning($"Удаление лайнера не удалось {ex.Message}");
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление набора в коллекцию
|
/// Добавление набора в коллекцию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -118,11 +154,13 @@ namespace Liner
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Обновление набора не удалось (не все данные заполнены)");
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_storage.AddSet(textBoxStorageName.Text);
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text} ");
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -144,12 +182,15 @@ namespace Liner
|
|||||||
{
|
{
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Удаление набора не удалось (индекс вне границ)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление",
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление",
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
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();
|
ReloadObjects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,13 +203,16 @@ namespace Liner
|
|||||||
{
|
{
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Обновление объектов не удалось (индекс вне границ)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning($"Обновление объектов не удалось (нет хранилища)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_logger.LogInformation($"Обновление объектов успешно");
|
||||||
pictureBoxCollection.Image = obj.ShowLiners();
|
pictureBoxCollection.Image = obj.ShowLiners();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -195,15 +239,17 @@ namespace Liner
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storage.SaveData(saveFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
|
_logger.LogInformation($"Cохранение успешно");
|
||||||
MessageBox.Show("Сохранение прошло успешно",
|
MessageBox.Show("Сохранение прошло успешно",
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
else
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не сохранилось", "Результат",
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
_logger.LogWarning($"Сохранение не удалось {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,16 +257,18 @@ namespace Liner
|
|||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storage.LoadData(openFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
|
_logger.LogInformation($"Загрузка успешна");
|
||||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не загрузилось", "Результат",
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning($"Загрузка не удалась {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, 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="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">
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ namespace Liner.Generics
|
|||||||
/// Сохранение информации по лайнерам в хранилище в файл
|
/// Сохранение информации по лайнерам в хранилище в файл
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
public void SaveData(string filename)
|
||||||
public bool SaveData(string filename)
|
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@@ -112,7 +111,7 @@ namespace Liner.Generics
|
|||||||
}
|
}
|
||||||
if (data.Length == 0)
|
if (data.Length == 0)
|
||||||
{
|
{
|
||||||
return false;
|
throw new InvalidOperationException("Невалиданя операция, нет данных для сохранения");
|
||||||
}
|
}
|
||||||
string dataStr = data.ToString();
|
string dataStr = data.ToString();
|
||||||
using (StreamWriter writer = new StreamWriter(filename))
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
@@ -120,42 +119,36 @@ namespace Liner.Generics
|
|||||||
writer.WriteLine("LinerStorage");
|
writer.WriteLine("LinerStorage");
|
||||||
writer.WriteLine(dataStr);
|
writer.WriteLine(dataStr);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Загрузка информации по автомобилям в хранилище из файла
|
/// Загрузка информации по автомобилям в хранилище из файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
public void LoadData(string filename)
|
||||||
public bool LoadData(string filename)
|
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
throw new FileNotFoundException("Файл не найден");
|
||||||
}
|
}
|
||||||
using (StreamReader reader = new StreamReader(filename))
|
using (StreamReader reader = new StreamReader(filename))
|
||||||
{
|
{
|
||||||
string checker = reader.ReadLine();
|
string checker = reader.ReadLine();
|
||||||
if (checker == null)
|
if (checker == null)
|
||||||
{
|
{
|
||||||
return false;
|
throw new NullReferenceException("Нет данных для загрузки");
|
||||||
}
|
}
|
||||||
if (!checker.StartsWith("LinerStorage"))
|
if (!checker.StartsWith("LinerStorage"))
|
||||||
{
|
{
|
||||||
return false;
|
throw new FormatException("Неверный формат данных");
|
||||||
}
|
}
|
||||||
_linerStorages.Clear();
|
_linerStorages.Clear();
|
||||||
string strs;
|
string strs;
|
||||||
bool firstinit = true;
|
while ((strs = reader.ReadLine()) != null) //переделал ужасную логику
|
||||||
while ((strs = reader.ReadLine()) != null)
|
|
||||||
{
|
{
|
||||||
if (strs == null && firstinit)
|
|
||||||
return false;
|
|
||||||
if (strs == null)
|
if (strs == null)
|
||||||
break;
|
break;
|
||||||
if (strs == string.Empty)
|
if (strs == string.Empty)
|
||||||
break;
|
break;
|
||||||
firstinit = false;
|
|
||||||
string name = strs.Split('|')[0];
|
string name = strs.Split('|')[0];
|
||||||
LinerGenericCollection<DrawingLiner, DrawingObjectLiner> collection = new(_pictureWidth, _pictureHeight);
|
LinerGenericCollection<DrawingLiner, DrawingObjectLiner> collection = new(_pictureWidth, _pictureHeight);
|
||||||
foreach (string data in strs.Split('|')[1].Split(';').Reverse())
|
foreach (string data in strs.Split('|')[1].Split(';').Reverse())
|
||||||
@@ -164,16 +157,18 @@ namespace Liner.Generics
|
|||||||
data?.CreateDrawingLiner(_separatorForObject, _pictureWidth, _pictureHeight);
|
data?.CreateDrawingLiner(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
if (liner != null)
|
if (liner != null)
|
||||||
{
|
{
|
||||||
if (collection + liner == -1)
|
try
|
||||||
{
|
{
|
||||||
return false;
|
int? tmp = collection + liner;
|
||||||
|
}
|
||||||
|
catch (ApplicationException ex)
|
||||||
|
{
|
||||||
|
throw new ApplicationException($"Ошибка добавления в коллекцию: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
_linerStorages.Add(name, collection);
|
_linerStorages.Add(name, collection);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Liner.Exceptions;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -41,12 +42,13 @@ namespace Liner.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T liner)
|
public int Insert(T liner)
|
||||||
{
|
{
|
||||||
if (_places.Count + 1 <= _maxCount)
|
if (_places.Count >= _maxCount)
|
||||||
{
|
{
|
||||||
|
throw new StorageOverflowException(_places.Count);
|
||||||
|
}
|
||||||
_places.Insert(0, liner);
|
_places.Insert(0, liner);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
@@ -56,13 +58,17 @@ namespace Liner.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T liner, int position)
|
public int Insert(T liner, int position)
|
||||||
{
|
{
|
||||||
if (_places.Count + 1 <= _maxCount && _places.Count >= position)
|
if(_places.Count >= _maxCount)
|
||||||
{
|
{
|
||||||
|
throw new StorageOverflowException(_places.Count);
|
||||||
|
}
|
||||||
|
if(position < 0 || position > _places.Count)
|
||||||
|
{
|
||||||
|
throw new LinerNotFoundException(position);
|
||||||
|
}
|
||||||
_places.Insert(position, liner);
|
_places.Insert(position, liner);
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -75,7 +81,7 @@ namespace Liner.Generics
|
|||||||
_places.RemoveAt(position);
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
throw new LinerNotFoundException(position);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта из набора по позиции
|
/// Получение объекта из набора по позиции
|
||||||
@@ -94,9 +100,13 @@ namespace Liner.Generics
|
|||||||
}
|
}
|
||||||
set
|
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\**" />
|
<None Remove="MovingStrategy\**" />
|
||||||
</ItemGroup>
|
</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>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<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
|
namespace Liner
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@@ -11,7 +18,28 @@ namespace Liner
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
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