Romanov E.V. LabWork7 #9
66
HoistingCrane/HoistingCrane/App.config
Normal file
66
HoistingCrane/HoistingCrane/App.config
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||||
|
</startup>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.5.1" newVersion="4.0.5.1" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
@ -121,7 +121,6 @@
|
|||||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(200, 28);
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(200, 28);
|
||||||
this.comboBoxSelectorMap.TabIndex = 0;
|
this.comboBoxSelectorMap.TabIndex = 0;
|
||||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
|
||||||
//
|
//
|
||||||
// textBoxNewMapName
|
// textBoxNewMapName
|
||||||
//
|
//
|
||||||
@ -155,7 +154,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 459);
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 436);
|
||||||
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.maskedTextBoxPosition.Mask = "00";
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
@ -165,7 +164,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveHoistingCrane
|
// buttonRemoveHoistingCrane
|
||||||
//
|
//
|
||||||
this.buttonRemoveHoistingCrane.Location = new System.Drawing.Point(20, 494);
|
this.buttonRemoveHoistingCrane.Location = new System.Drawing.Point(20, 471);
|
||||||
this.buttonRemoveHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonRemoveHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonRemoveHoistingCrane.Name = "buttonRemoveHoistingCrane";
|
this.buttonRemoveHoistingCrane.Name = "buttonRemoveHoistingCrane";
|
||||||
this.buttonRemoveHoistingCrane.Size = new System.Drawing.Size(199, 47);
|
this.buttonRemoveHoistingCrane.Size = new System.Drawing.Size(199, 47);
|
||||||
@ -176,7 +175,7 @@
|
|||||||
//
|
//
|
||||||
// buttonShowStorage
|
// buttonShowStorage
|
||||||
//
|
//
|
||||||
this.buttonShowStorage.Location = new System.Drawing.Point(20, 549);
|
this.buttonShowStorage.Location = new System.Drawing.Point(20, 526);
|
||||||
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
this.buttonShowStorage.Size = new System.Drawing.Size(199, 47);
|
this.buttonShowStorage.Size = new System.Drawing.Size(199, 47);
|
||||||
@ -239,10 +238,10 @@
|
|||||||
//
|
//
|
||||||
// buttonShowOnMap
|
// buttonShowOnMap
|
||||||
//
|
//
|
||||||
this.buttonShowOnMap.Location = new System.Drawing.Point(20, 604);
|
this.buttonShowOnMap.Location = new System.Drawing.Point(21, 584);
|
||||||
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
this.buttonShowOnMap.Size = new System.Drawing.Size(193, 47);
|
this.buttonShowOnMap.Size = new System.Drawing.Size(198, 47);
|
||||||
this.buttonShowOnMap.TabIndex = 5;
|
this.buttonShowOnMap.TabIndex = 5;
|
||||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
@ -250,7 +249,7 @@
|
|||||||
//
|
//
|
||||||
// buttonAddHoistingCrane
|
// buttonAddHoistingCrane
|
||||||
//
|
//
|
||||||
this.buttonAddHoistingCrane.Location = new System.Drawing.Point(20, 404);
|
this.buttonAddHoistingCrane.Location = new System.Drawing.Point(20, 381);
|
||||||
this.buttonAddHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonAddHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
|
this.buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
|
||||||
this.buttonAddHoistingCrane.Size = new System.Drawing.Size(199, 47);
|
this.buttonAddHoistingCrane.Size = new System.Drawing.Size(199, 47);
|
||||||
@ -286,7 +285,7 @@
|
|||||||
this.saveToolStripMenuItem,
|
this.saveToolStripMenuItem,
|
||||||
this.loadToolStripMenuItem});
|
this.loadToolStripMenuItem});
|
||||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 29);
|
this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
|
||||||
this.fileToolStripMenuItem.Text = "File";
|
this.fileToolStripMenuItem.Text = "File";
|
||||||
//
|
//
|
||||||
// saveToolStripMenuItem
|
// saveToolStripMenuItem
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -21,13 +22,16 @@ namespace HoistingCrane
|
|||||||
};
|
};
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Объект от коллекции карт
|
/// Объект от коллекции карт
|
||||||
|
/// Логер
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
/// <summary>
|
||||||
private readonly MapsCollection _mapsCollection;
|
private readonly MapsCollection _mapsCollection;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
private MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> _mapHoistingCraneCollectionGeneric;
|
public FormMapWithSetHoistingCrane(ILogger<FormMapWithSetHoistingCrane> logger)
|
||||||
public FormMapWithSetHoistingCrane()
|
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
comboBoxSelectorMap.Items.Clear();
|
comboBoxSelectorMap.Items.Clear();
|
||||||
foreach (var elem in _mapsDict)
|
foreach (var elem in _mapsDict)
|
||||||
@ -57,29 +61,6 @@ namespace HoistingCrane
|
|||||||
listBoxMaps.SelectedIndex = index;
|
listBoxMaps.SelectedIndex = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
AbstractMap map = null;
|
|
||||||
switch (comboBoxSelectorMap.Text)
|
|
||||||
{
|
|
||||||
case "Простая карта":
|
|
||||||
map = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Вторая карта":
|
|
||||||
map = new SecondMap();
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (map != null)
|
|
||||||
{
|
|
||||||
_mapHoistingCraneCollectionGeneric = new MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap>(
|
|
||||||
pictureBox.Width, pictureBox.Height, map);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_mapHoistingCraneCollectionGeneric = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление карты
|
/// Добавление карты
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -99,10 +80,12 @@ namespace HoistingCrane
|
|||||||
}
|
}
|
||||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
|
_logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
|
||||||
}
|
}
|
||||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
_logger.LogInformation($"Переход на карту {listBoxMaps.SelectedItem?.ToString()}");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление карты
|
/// Удаление карты
|
||||||
@ -119,6 +102,7 @@ namespace HoistingCrane
|
|||||||
{
|
{
|
||||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
|
_logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem?.ToString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonAddHoistingCrane_Click(object sender, EventArgs e)
|
private void ButtonAddHoistingCrane_Click(object sender, EventArgs e)
|
||||||
@ -133,15 +117,33 @@ namespace HoistingCrane
|
|||||||
}
|
}
|
||||||
private void AddHoistingCrane(DrawingHoistingCrane drawingHoistingCrane)
|
private void AddHoistingCrane(DrawingHoistingCrane drawingHoistingCrane)
|
||||||
{
|
{
|
||||||
DrawingObjectHoistingCrane hoistingCrane = new DrawingObjectHoistingCrane(drawingHoistingCrane);
|
try
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + hoistingCrane != -1)
|
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
{
|
||||||
|
MessageBox.Show("Перед добавлением объекта необходимо создать карту");
|
||||||
|
}
|
||||||
|
else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectHoistingCrane(drawingHoistingCrane) != -1)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Добавлен кран {drawingHoistingCrane}");
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Не удалось добавить кран");
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (StorageOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
_logger.LogWarning($"Ошибка переполнения хранилища: {ex.Message}");
|
||||||
|
MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning($"Неизвестная ошибка: {ex.Message}");
|
||||||
|
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e)
|
private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e)
|
||||||
@ -155,14 +157,28 @@ namespace HoistingCrane
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
try
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
_logger.LogInformation($"Удален объект {pos}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (HoistingCraneNotFoundException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
_logger.LogWarning($"Ошибка {ex.Message}");
|
||||||
|
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning($"Ошибка {ex.Message}");
|
||||||
|
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
@ -204,21 +220,24 @@ namespace HoistingCrane
|
|||||||
enums = Direction.Right;
|
enums = Direction.Right;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums);
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(enums);
|
||||||
}
|
}
|
||||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат",
|
MessageBox.Show("Сохранение прошло успешно", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation($"Сохранение данных");
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не сохранилось", "Результат",
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning($"Ошибка {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -227,16 +246,19 @@ namespace HoistingCrane
|
|||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_mapsCollection.LoadData(openFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||||
|
ReloadMaps();
|
||||||
MessageBox.Show("Открытие прошло успешно", "Результат",
|
MessageBox.Show("Открытие прошло успешно", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
ReloadMaps();
|
_logger.LogInformation($"Загрузка данных");
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось открыть", "Результат",
|
MessageBox.Show($"Не удалось открыть: {ex.Message}", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning($"Ошибка {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,18 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
|
||||||
|
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -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 HoistingCrane
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class HoistingCraneNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public HoistingCraneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public HoistingCraneNotFoundException() : base() { }
|
||||||
|
public HoistingCraneNotFoundException(string message) : base(message) { }
|
||||||
|
public HoistingCraneNotFoundException(string message, Exception exception) :
|
||||||
|
base(message, exception)
|
||||||
|
{ }
|
||||||
|
protected HoistingCraneNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
@ -81,7 +81,7 @@ namespace HoistingCrane
|
|||||||
/// Сохранение информации про лодки м в хранилище в файл
|
/// Сохранение информации про лодки м в хранилище в файл
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
public bool SaveData(string filename)
|
public void SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -99,15 +99,14 @@ namespace HoistingCrane
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Загрузка информации по локомотивам в депо из файла
|
/// Загрузка информации по локомотивам в депо из файла
|
||||||
public bool LoadData(string filename)
|
public void LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
throw new FileNotFoundException(filename);
|
||||||
}
|
}
|
||||||
using (FileStream fs = new(filename, FileMode.Open))
|
using (FileStream fs = new(filename, FileMode.Open))
|
||||||
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
|
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
|
||||||
@ -116,7 +115,7 @@ namespace HoistingCrane
|
|||||||
|
|
||||||
if (!curLine.Contains("MapsCollection"))
|
if (!curLine.Contains("MapsCollection"))
|
||||||
{
|
{
|
||||||
return false;
|
throw new FormatException(curLine);
|
||||||
}
|
}
|
||||||
_mapStorages.Clear();
|
_mapStorages.Clear();
|
||||||
while ((curLine = sr.ReadLine()) != null)
|
while ((curLine = sr.ReadLine()) != null)
|
||||||
@ -138,7 +137,6 @@ namespace HoistingCrane
|
|||||||
_mapStorages.Add(elems[0], new MapWithSetHoistingCraneGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
_mapStorages.Add(elems[0], new MapWithSetHoistingCraneGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
_mapStorages[elems[0]].LoadData(elems[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
_mapStorages[elems[0]].LoadData(elems[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace HoistingCrane
|
namespace HoistingCrane
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -8,10 +14,25 @@ namespace HoistingCrane
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
Application.EnableVisualStyles();
|
||||||
// see https://aka.ms/applicationconfiguration.
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
ApplicationConfiguration.Initialize();
|
var services = new ServiceCollection();
|
||||||
Application.Run(new FormMapWithSetHoistingCrane());
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetHoistingCrane>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormMapWithSetHoistingCrane>()
|
||||||
|
.AddLogging(option =>
|
||||||
|
{
|
||||||
|
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true).Build();
|
||||||
|
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(logger);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
30
HoistingCrane/HoistingCrane/Properties/Settings.Designer.cs
generated
Normal file
30
HoistingCrane/HoistingCrane/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace HoistingCrane.Properties
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
|
||||||
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
|
|
||||||
|
public static Settings Default
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,27 +19,52 @@ namespace HoistingCrane
|
|||||||
}
|
}
|
||||||
public int Insert(T hoistingCrane)
|
public int Insert(T hoistingCrane)
|
||||||
{
|
{
|
||||||
return Insert(hoistingCrane, 0);
|
for (int i = 0; i < _maxCount; i++)
|
||||||
|
{
|
||||||
|
if (i == Count)
|
||||||
|
{
|
||||||
|
_places.Insert(i, hoistingCrane);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
|
||||||
}
|
}
|
||||||
public int Insert(T hoistingCrane, int position)
|
public int Insert(T hoistingCrane, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position > Count || _maxCount == Count)
|
if (position < 0 || position >= _maxCount)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (position == Count)
|
||||||
|
{
|
||||||
|
_places.Insert(position, hoistingCrane);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = position + 1; i < _maxCount; i++)
|
||||||
|
{
|
||||||
|
if (i == Count)
|
||||||
|
{
|
||||||
|
for (int j = i - 1; j >= position; j--)
|
||||||
|
{
|
||||||
|
_places[j + 1] = _places[j];
|
||||||
|
}
|
||||||
|
_places.Insert(position, hoistingCrane);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
}
|
}
|
||||||
_places.Insert(position, hoistingCrane);
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < Count && position >= 0 && _places[position] != null)
|
if (position < 0 || position >= Count) throw new HoistingCraneNotFoundException();
|
||||||
{
|
var result = _places[position];
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
T removed = _places[position];
|
return result;
|
||||||
return removed;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public T this[int position]
|
public T this[int position]
|
||||||
{
|
{
|
||||||
|
21
HoistingCrane/HoistingCrane/StorageOverflowException.cs
Normal file
21
HoistingCrane/HoistingCrane/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 HoistingCrane
|
||||||
|
{
|
||||||
|
[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) { }
|
||||||
|
}
|
||||||
|
}
|
48
HoistingCrane/HoistingCrane/packages.config
Normal file
48
HoistingCrane/HoistingCrane/packages.config
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Azure.Core" version="1.20.0" targetFramework="net472" />
|
||||||
|
<package id="Azure.Data.AppConfiguration" version="1.2.0" targetFramework="net472" />
|
||||||
|
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="Microsoft.Extensions.Configuration" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.Configuration.Abstractions" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.Configuration.Binder" version="2.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.Configuration.FileExtensions" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.Configuration.Json" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.DependencyInjection" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="Microsoft.Extensions.DependencyModel" version="3.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.FileProviders.Abstractions" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.FileProviders.Physical" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.FileSystemGlobbing" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="Microsoft.Extensions.Logging" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="Microsoft.Extensions.Logging.Abstractions" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="Microsoft.Extensions.Options" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="Microsoft.Extensions.Primitives" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net48" />
|
||||||
|
<package id="NLog" version="5.0.5" targetFramework="net472" />
|
||||||
|
<package id="NLog.Extensions.Logging" version="5.1.0" targetFramework="net472" />
|
||||||
|
<package id="Serilog" version="2.10.0" targetFramework="net48" />
|
||||||
|
<package id="Serilog.Extensions.Logging" version="3.1.0" targetFramework="net472" />
|
||||||
|
<package id="Serilog.Settings.Configuration" version="3.4.0" targetFramework="net48" />
|
||||||
|
<package id="Serilog.Sinks.File" version="5.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
|
||||||
|
<package id="System.Configuration.ConfigurationManager" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Diagnostics.DiagnosticSource" version="7.0.0" targetFramework="net472" />
|
||||||
|
<package id="System.IO" version="4.3.0" targetFramework="net48" />
|
||||||
|
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
|
||||||
|
<package id="System.Memory.Data" version="1.0.2" targetFramework="net472" />
|
||||||
|
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||||
|
<package id="System.Runtime" version="4.3.0" targetFramework="net48" />
|
||||||
|
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
|
||||||
|
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Security.AccessControl" version="6.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net48" />
|
||||||
|
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net48" />
|
||||||
|
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net48" />
|
||||||
|
<package id="System.Security.Permissions" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Text.Encodings.Web" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Text.Json" version="7.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
|
||||||
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||||
|
</packages>
|
Loading…
Reference in New Issue
Block a user