Compare commits
2 Commits
f8ce47bbd3
...
28b59aba44
Author | SHA1 | Date | |
---|---|---|---|
|
28b59aba44 | ||
|
dc45fbd65d |
@ -1,11 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using DoubleDeckerBus.DrawningObjects;
|
|
||||||
|
|
||||||
namespace DoubleDeckerBus
|
|
||||||
{
|
|
||||||
public delegate void BusDelegate(DrawningBus bus);
|
|
||||||
}
|
|
@ -8,4 +8,10 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class BusNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public BusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public BusNotFoundException() : base() { }
|
||||||
|
public BusNotFoundException(string message) : base(message) { }
|
||||||
|
public BusNotFoundException(string message, Exception exception) : base(message, exception){ }
|
||||||
|
protected BusNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus.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) { }
|
||||||
|
}
|
||||||
|
}
|
@ -39,10 +39,11 @@
|
|||||||
ButtonDelObject = new Button();
|
ButtonDelObject = new Button();
|
||||||
ButtonAddObject = new Button();
|
ButtonAddObject = new Button();
|
||||||
menuStrip = new MenuStrip();
|
menuStrip = new MenuStrip();
|
||||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
openFileDialog = new OpenFileDialog();
|
openFileDialog = new OpenFileDialog();
|
||||||
saveFileDialog = new SaveFileDialog();
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
panel.SuspendLayout();
|
panel.SuspendLayout();
|
||||||
menuStrip.SuspendLayout();
|
menuStrip.SuspendLayout();
|
||||||
@ -155,26 +156,25 @@
|
|||||||
//
|
//
|
||||||
// menuStrip
|
// menuStrip
|
||||||
//
|
//
|
||||||
menuStrip.Items.AddRange(new ToolStripItem[] { SaveToolStripMenuItem });
|
menuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem });
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Size = new Size(168, 24);
|
menuStrip.Size = new Size(168, 24);
|
||||||
menuStrip.TabIndex = 10;
|
menuStrip.TabIndex = 10;
|
||||||
menuStrip.Text = "menuStrip1";
|
menuStrip.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
// SaveToolStripMenuItem
|
// ToolStripMenuItem
|
||||||
//
|
//
|
||||||
SaveToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { LoadToolStripMenuItem });
|
ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { LoadToolStripMenuItem, SaveToolStripMenuItem });
|
||||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
ToolStripMenuItem.Name = "ToolStripMenuItem";
|
||||||
SaveToolStripMenuItem.Size = new Size(144, 20);
|
ToolStripMenuItem.Size = new Size(48, 20);
|
||||||
SaveToolStripMenuItem.Text = "SaveToolStripMenuItem";
|
ToolStripMenuItem.Text = "файл";
|
||||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
|
||||||
//
|
//
|
||||||
// LoadToolStripMenuItem
|
// LoadToolStripMenuItem
|
||||||
//
|
//
|
||||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
LoadToolStripMenuItem.Size = new Size(201, 22);
|
LoadToolStripMenuItem.Size = new Size(180, 22);
|
||||||
LoadToolStripMenuItem.Text = "LoadToolStripMenuItem";
|
LoadToolStripMenuItem.Text = "Загрузить";
|
||||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// openFileDialog
|
// openFileDialog
|
||||||
@ -186,6 +186,13 @@
|
|||||||
//
|
//
|
||||||
saveFileDialog.Filter = "«txt file | *.txt»";
|
saveFileDialog.Filter = "«txt file | *.txt»";
|
||||||
//
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
SaveToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
SaveToolStripMenuItem.Text = "Сохранить";
|
||||||
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// FormBusCollection
|
// FormBusCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -219,7 +226,8 @@
|
|||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
private MenuStrip menuStrip;
|
private MenuStrip menuStrip;
|
||||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
private ToolStripMenuItem ToolStripMenuItem;
|
||||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,13 +12,18 @@ using DoubleDeckerBus.Generics;
|
|||||||
using DoubleDeckerBus.MovementStrategy;
|
using DoubleDeckerBus.MovementStrategy;
|
||||||
using static System.Windows.Forms.DataFormats;
|
using static System.Windows.Forms.DataFormats;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using DoubleDeckerBus.Exceptions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Serilog;
|
||||||
|
using Log = Serilog.Log;
|
||||||
|
|
||||||
namespace DoubleDeckerBus
|
namespace DoubleDeckerBus
|
||||||
{
|
{
|
||||||
public partial class FormBusCollection : Form
|
public partial class FormBusCollection : Form
|
||||||
{
|
{
|
||||||
private readonly BusesGenericStorage _storage;
|
private readonly BusesGenericStorage _storage;
|
||||||
public FormBusCollection()
|
public FormBusCollection(ILogger<FormBusCollection> logger)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_storage = new BusesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new BusesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
@ -32,13 +37,12 @@ namespace DoubleDeckerBus
|
|||||||
{
|
{
|
||||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||||
{
|
{
|
||||||
listBoxStorages.SelectedIndex = 0;
|
listBoxStorages.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||||
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
index < listBoxStorages.Items.Count)
|
||||||
{
|
{
|
||||||
listBoxStorages.SelectedIndex = index;
|
listBoxStorages.SelectedIndex = index;
|
||||||
}
|
}
|
||||||
@ -49,7 +53,6 @@ namespace DoubleDeckerBus
|
|||||||
}
|
}
|
||||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
@ -57,6 +60,7 @@ namespace DoubleDeckerBus
|
|||||||
}
|
}
|
||||||
_storage.AddSet(textBoxStorageName.Text);
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
|
Log.Information($"Добавлен набор:{textBoxStorageName.Text}");
|
||||||
}
|
}
|
||||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -64,15 +68,47 @@ namespace DoubleDeckerBus
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show($"Удалить объект {name}?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
_storage.DelSet(name);
|
||||||
?? string.Empty);
|
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
|
Log.Information($"Удален набор: {name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void buttonAddBus_Click(object sender, EventArgs e)
|
private void buttonAddBus_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormBusConfig form = new();
|
||||||
|
form.Show();
|
||||||
|
Action<DrawningBus>? busDelegate = new((m) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool q = obj + m;
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
Log.Information($"Добавлен объект в коллекцию {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||||
|
pictureBoxCollection.Image = obj.ShowBuses();
|
||||||
|
}
|
||||||
|
catch (StorageOverflowException ex)
|
||||||
|
{
|
||||||
|
Log.Warning($"Коллекция {listBoxStorages.SelectedItem.ToString() ?? string.Empty} переполнена");
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
form.AddEvent(busDelegate);
|
||||||
|
}
|
||||||
|
private void buttonRemoveBus_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
@ -83,51 +119,33 @@ namespace DoubleDeckerBus
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FormBusConfig form = new FormBusConfig();
|
if (MessageBox.Show("Удалить объект?", "Удалить", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
form.AddEvent(AddBus);
|
|
||||||
form.Show();
|
|
||||||
}
|
|
||||||
private void AddBus(DrawningBus boat)
|
|
||||||
{
|
|
||||||
boat._pictureWidth = pictureBoxCollection.Width;
|
|
||||||
boat._pictureHeight = pictureBoxCollection.Height; if (listBoxStorages.SelectedIndex == -1) return;
|
|
||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) return;
|
|
||||||
if (obj + boat)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Объект добавлен");
|
|
||||||
pictureBoxCollection.Image = obj.ShowBuses();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void buttonRemoveBus_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
try
|
||||||
string.Empty];
|
|
||||||
if (obj == null)
|
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (obj - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = obj.ShowBuses();
|
pictureBoxCollection.Image = obj.ShowBuses();
|
||||||
|
Log.Information($"лодка удалена из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Объект не удален");
|
||||||
|
Log.Warning($"лодка не удалена из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (BusNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
Log.Warning($"BoatNotFound: {ex.Message} in set {listBoxStorages.SelectedItem.ToString()}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект не добавлен"); Log.Warning("Not input");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
@ -136,8 +154,7 @@ namespace DoubleDeckerBus
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
string.Empty];
|
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -148,31 +165,41 @@ namespace DoubleDeckerBus
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storage.SaveData(saveFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Сохранение прошло успешно","Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
Log.Information($"Файл {saveFileDialog.FileName} успешно сохранен");
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
Log.Warning("Не удалось сохранить");
|
||||||
|
MessageBox.Show($"Не сохранилось: {ex.Message}","Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storage.LoadData(openFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
|
MessageBox.Show("Загрузка прошла успешно","Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
Log.Information($"Файл {openFileDialog.FileName} успешно загружен");
|
||||||
foreach (var collection in _storage.Keys)
|
foreach (var collection in _storage.Keys)
|
||||||
{
|
{
|
||||||
listBoxStorages.Items.Add(collection);
|
listBoxStorages.Items.Add(collection);
|
||||||
}
|
}
|
||||||
|
ReloadObjects();
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
Log.Warning("Не удалось загрузить");
|
||||||
|
MessageBox.Show($"Не загрузилось: {ex.Message}","Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,9 @@
|
|||||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>11, 17</value>
|
<value>11, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>11, 17</value>
|
||||||
|
</metadata>
|
||||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>132, 17</value>
|
<value>132, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
@ -23,87 +23,6 @@ namespace DoubleDeckerBus.Generics
|
|||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
public bool SaveData(string filename)
|
|
||||||
{
|
|
||||||
if (File.Exists(filename))
|
|
||||||
{
|
|
||||||
File.Delete(filename);
|
|
||||||
}
|
|
||||||
StringBuilder data = new();
|
|
||||||
foreach (KeyValuePair<string, BusesGenericCollection<DrawningBus, DrawningObjectBus>> record in _busStorages)
|
|
||||||
{
|
|
||||||
StringBuilder records = new();
|
|
||||||
foreach (DrawningBus? elem in record.Value.GetTheBuses)
|
|
||||||
{
|
|
||||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
|
||||||
}
|
|
||||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.Length == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
string toWrite = $"BusStorage{Environment.NewLine}{data}";
|
|
||||||
var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
|
|
||||||
using (StreamWriter sw = new(filename))
|
|
||||||
{
|
|
||||||
foreach (var str in strs)
|
|
||||||
{
|
|
||||||
sw.WriteLine(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public bool LoadData(string filename)
|
|
||||||
{
|
|
||||||
if (!File.Exists(filename))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
using (StreamReader sr = new(filename))
|
|
||||||
{
|
|
||||||
string str = sr.ReadLine();
|
|
||||||
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (strs == null || strs.Length == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!strs[0].StartsWith("BusStorage"))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_busStorages.Clear();
|
|
||||||
do
|
|
||||||
{
|
|
||||||
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (record.Length != 2)
|
|
||||||
{
|
|
||||||
str = sr.ReadLine();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
BusesGenericCollection<DrawningBus, DrawningObjectBus> collection = new(_pictureWidth, _pictureHeight);
|
|
||||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
foreach (string elem in set)
|
|
||||||
{
|
|
||||||
DrawningBus? bus =
|
|
||||||
elem?.CreateDrawningBus(_separatorForObject, _pictureWidth, _pictureHeight);
|
|
||||||
if (bus != null)
|
|
||||||
{
|
|
||||||
if (!(collection + bus))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_busStorages.Add(record[0], collection);
|
|
||||||
|
|
||||||
str = sr.ReadLine();
|
|
||||||
} while (str != null);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
_busStorages.Add(name, new BusesGenericCollection<DrawningBus, DrawningObjectBus>(_pictureWidth, _pictureHeight));
|
_busStorages.Add(name, new BusesGenericCollection<DrawningBus, DrawningObjectBus>(_pictureWidth, _pictureHeight));
|
||||||
@ -117,8 +36,7 @@ namespace DoubleDeckerBus.Generics
|
|||||||
|
|
||||||
_busStorages.Remove(name);
|
_busStorages.Remove(name);
|
||||||
}
|
}
|
||||||
public BusesGenericCollection<DrawningBus, DrawningObjectBus>?
|
public BusesGenericCollection<DrawningBus, DrawningObjectBus>?this[string ind]
|
||||||
this[string ind]
|
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -130,5 +48,90 @@ namespace DoubleDeckerBus.Generics
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<string,
|
||||||
|
BusesGenericCollection<DrawningBus, DrawningObjectBus>> record in _busStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawningBus? elem in record.Value.GetTheBuses)
|
||||||
|
{
|
||||||
|
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($"BusStorage{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("BusStorage"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
throw new Exception("Неверный формат данных");
|
||||||
|
}
|
||||||
|
_busStorages.Clear();
|
||||||
|
foreach (string data in strs)
|
||||||
|
{
|
||||||
|
string[] record = data.Split(_separatorForKeyValue,
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BusesGenericCollection<DrawningBus, DrawningObjectBus>
|
||||||
|
collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords,
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawningBus? car =
|
||||||
|
elem?.CreateDrawningBus(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (car != null)
|
||||||
|
{
|
||||||
|
if (!(collection + car))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка добавления в коллекцию");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_busStorages.Add(record[0], collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using DoubleDeckerBus.Exceptions;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
@ -21,30 +22,23 @@ namespace DoubleDeckerBus.Generics
|
|||||||
public bool Insert(T bus)
|
public bool Insert(T bus)
|
||||||
{
|
{
|
||||||
if (_places.Count == _maxCount)
|
if (_places.Count == _maxCount)
|
||||||
{
|
throw new StorageOverflowException(_maxCount);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Insert(bus, 0);
|
Insert(bus, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public bool Insert(T bus, int position)
|
public bool Insert(T bus, int position)
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
if (_places.Count == _maxCount)
|
||||||
{
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
if (!(position >= 0 && position <= Count))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
_places.Insert(position, bus);
|
_places.Insert(position, bus);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (!(position >= 0 && position < Count))
|
||||||
{
|
throw new BusNotFoundException(position);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_places.RemoveAt(position);
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -52,20 +46,14 @@ namespace DoubleDeckerBus.Generics
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _maxCount)
|
if (!(position >= 0 && position < Count))
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_places.Insert(position, value);
|
_places.Insert(position, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
namespace DoubleDeckerBus
|
namespace DoubleDeckerBus
|
||||||
{
|
{
|
||||||
@ -8,7 +11,22 @@ namespace DoubleDeckerBus
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormBusCollection());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider =
|
||||||
|
services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormBusCollection>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormBusCollection>()
|
||||||
|
.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
14
DoubleDeckerBus/DoubleDeckerBus/nlog.config
Normal file
14
DoubleDeckerBus/DoubleDeckerBus/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>
|
Loading…
Reference in New Issue
Block a user