Compare commits
No commits in common. "3f65961713e6f89900488d2e6892eb3e38524eeb" and "7f15f74c84aae140c658a95bbab7357ab199abf5" have entirely different histories.
3f65961713
...
7f15f74c84
@ -1,6 +1,4 @@
|
|||||||
using Serilog;
|
using System;
|
||||||
using Serilog.Formatting.Compact;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -23,8 +21,6 @@ namespace Locomotive
|
|||||||
};
|
};
|
||||||
/// Объект от коллекции карт
|
/// Объект от коллекции карт
|
||||||
private readonly MapsCollection _mapsCollection;
|
private readonly MapsCollection _mapsCollection;
|
||||||
|
|
||||||
|
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
public FormMapWithSetLocomotives()
|
public FormMapWithSetLocomotives()
|
||||||
{
|
{
|
||||||
@ -68,14 +64,12 @@ namespace Locomotive
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
Log.Information($"Map {textBoxNewMapName.Text} added");
|
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
}
|
}
|
||||||
/// Выбор карты
|
/// Выбор карты
|
||||||
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();
|
||||||
Log.Information($"Map switched to {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}");
|
|
||||||
}
|
}
|
||||||
/// Удаление карты
|
/// Удаление карты
|
||||||
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
||||||
@ -87,7 +81,6 @@ namespace Locomotive
|
|||||||
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?","Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?","Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
Log.Information($"Map {listBoxMaps.SelectedItem?.ToString() ?? string.Empty} deleted");
|
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,27 +99,15 @@ namespace Locomotive
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive) != -1)
|
||||||
{
|
{
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive) != -1)
|
MessageBox.Show("Object added");
|
||||||
{
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
MessageBox.Show("Object added");
|
}
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
Log.Information($"Object {locomotive} added");
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
MessageBox.Show("Failed to add object");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(StorageOverflowException ex)
|
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Storage overflow error: {ex.Message}");
|
MessageBox.Show("Failed to add object");
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Unknown error: {ex.Message}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -147,28 +128,15 @@ namespace Locomotive
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
try
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
{
|
{
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
MessageBox.Show("Object removed");
|
||||||
{
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
MessageBox.Show("Object removed");
|
|
||||||
Log.Information($"Locomotive at {pos} deleted");
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Failed to remove object");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(LocomotiveNotFoundException ex)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Delete error: {ex.Message}");
|
MessageBox.Show("Failed to remove object");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Unknown error: {ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/// Вывод набора
|
/// Вывод набора
|
||||||
private void buttonShowStorage_Click(object sender, EventArgs e)
|
private void buttonShowStorage_Click(object sender, EventArgs e)
|
||||||
@ -222,15 +190,13 @@ namespace Locomotive
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
try
|
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
||||||
{
|
{
|
||||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
MessageBox.Show("Saved successfully", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
MessageBox.Show("Saving success", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
Log.Information($"Saved to {saveFileDialog.FileName}");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Saving error: {ex.Message}", "Result",MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Saving failed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,19 +205,16 @@ namespace Locomotive
|
|||||||
{
|
{
|
||||||
if (loadFileDialog.ShowDialog() == DialogResult.OK)
|
if (loadFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
|
if (_mapsCollection.LoadData(loadFileDialog.FileName))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
_mapsCollection.LoadData(loadFileDialog.FileName);
|
|
||||||
MessageBox.Show("Loaded successfully", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Loaded successfully", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
Log.Information($"Loaded from {loadFileDialog.FileName}");
|
|
||||||
ReloadMaps();
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Loading failed + {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Loading failed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
ReloadMaps();
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,6 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.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,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Locomotive
|
|
||||||
{
|
|
||||||
internal class LocomotiveNotFoundException : ApplicationException
|
|
||||||
{
|
|
||||||
public LocomotiveNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
|
||||||
public LocomotiveNotFoundException() : base() { }
|
|
||||||
public LocomotiveNotFoundException(string message) : base(message) { }
|
|
||||||
public LocomotiveNotFoundException(string message, Exception exception) :
|
|
||||||
base(message, exception) { }
|
|
||||||
protected LocomotiveNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,9 +15,9 @@ namespace Locomotive
|
|||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
/// Размер занимаемого объектом места (ширина)
|
/// Размер занимаемого объектом места (ширина)
|
||||||
private readonly int _placeSizeWidth = 150;
|
private readonly int _placeSizeWidth = 210;
|
||||||
/// Размер занимаемого объектом места (высота)
|
/// Размер занимаемого объектом места (высота)
|
||||||
private readonly int _placeSizeHeight = 150;
|
private readonly int _placeSizeHeight = 90;
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
private readonly SetLocomotivesGeneric<T> _setLocomotives;
|
private readonly SetLocomotivesGeneric<T> _setLocomotives;
|
||||||
/// Карта
|
/// Карта
|
||||||
@ -138,8 +138,8 @@ namespace Locomotive
|
|||||||
/// Метод прорисовки объектов
|
/// Метод прорисовки объектов
|
||||||
private void DrawLocomotives(Graphics g)
|
private void DrawLocomotives(Graphics g)
|
||||||
{
|
{
|
||||||
int width = _pictureWidth / _placeSizeWidth - 1;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int height = _pictureHeight / _placeSizeHeight - 1;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
int curWidth = 0;
|
int curWidth = 0;
|
||||||
int curHeight = 0;
|
int curHeight = 0;
|
||||||
@ -147,7 +147,7 @@ namespace Locomotive
|
|||||||
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||||
{
|
{
|
||||||
// установка позиции
|
// установка позиции
|
||||||
locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 80, _pictureWidth, _pictureHeight);
|
locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
||||||
locomotive?.DrawningObject(g);
|
locomotive?.DrawningObject(g);
|
||||||
if (curWidth < width) curWidth++;
|
if (curWidth < width) curWidth++;
|
||||||
else
|
else
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Serilog;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -55,7 +54,7 @@ namespace Locomotive
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Сохранение информации по локомотивам в хранилище в файл
|
/// Сохранение информации по локомотивам в хранилище в файл
|
||||||
public void SaveData(string filename)
|
public bool SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -73,14 +72,14 @@ namespace Locomotive
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
/// Загрузка нформации по локомотивам в депо из файла
|
/// Загрузка нформации по локомотивам в депо из файла
|
||||||
public void LoadData(string filename)
|
public bool LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
Log.Warning($"FileNotFoundException {filename}");
|
return false;
|
||||||
throw new FileNotFoundException("Файл не найден");
|
|
||||||
}
|
}
|
||||||
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))
|
||||||
@ -89,8 +88,7 @@ namespace Locomotive
|
|||||||
|
|
||||||
if (!curLine.Contains("MapsCollection"))
|
if (!curLine.Contains("MapsCollection"))
|
||||||
{
|
{
|
||||||
Log.Warning($"FileFormatException");
|
return false;
|
||||||
throw new FileFormatException("Формат данных в файле неправильный");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mapStorages.Clear();
|
_mapStorages.Clear();
|
||||||
@ -115,6 +113,8 @@ namespace Locomotive
|
|||||||
_mapStorages.Add(elems[0], new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
_mapStorages.Add(elems[0], new MapWithSetLocomotivesGeneric<IDrawningObject, 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,5 +1,3 @@
|
|||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -12,9 +10,6 @@ namespace Locomotive
|
|||||||
{
|
{
|
||||||
// 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.
|
||||||
|
|
||||||
|
|
||||||
Log.Logger = new LoggerConfiguration().WriteTo.File(new Serilog.Formatting.Compact.CompactJsonFormatter(), "C:\\secondCourse\\OOP\\ProjectLomotive\\Locomotive\\log.clef").CreateLogger();
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormMapWithSetLocomotives());
|
Application.Run(new FormMapWithSetLocomotives());
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Serilog;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -31,11 +30,7 @@ namespace Locomotive
|
|||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
public int Insert(T locomotive, int position)
|
public int Insert(T locomotive, int position)
|
||||||
{
|
{
|
||||||
if (position < 0) return -1;
|
if (position >= _maxCount|| position < 0) return -1;
|
||||||
if (Count >= _maxCount) {
|
|
||||||
Log.Warning("StorageOverflowException");
|
|
||||||
throw new StorageOverflowException(_maxCount);
|
|
||||||
}
|
|
||||||
_places.Insert(position, locomotive);
|
_places.Insert(position, locomotive);
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
@ -44,13 +39,8 @@ namespace Locomotive
|
|||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= _maxCount || position < 0) return null;
|
if (position >= _maxCount || position < 0) return null;
|
||||||
if (_places[position] is null)
|
|
||||||
{
|
|
||||||
Log.Warning($"LocomotiveNotFoundException at {position}");
|
|
||||||
throw new LocomotiveNotFoundException(position);
|
|
||||||
}
|
|
||||||
T result = _places[position];
|
T result = _places[position];
|
||||||
_places[position] = null; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! РАНЬШЕ REMOVE
|
_places.RemoveAt(position);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// Индексатор
|
// Индексатор
|
||||||
@ -72,10 +62,14 @@ namespace Locomotive
|
|||||||
{
|
{
|
||||||
foreach (var locomotive in _places)
|
foreach (var locomotive in _places)
|
||||||
{
|
{
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! РАНЬШЕ ВОЗВРАЩАЛОСЬ ТОЛЬКО ЕСЛИ НЕ НУЛЛ
|
if (locomotive != null)
|
||||||
|
{
|
||||||
yield return locomotive;
|
yield return locomotive;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Locomotive
|
|
||||||
{
|
|
||||||
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 context) : base(info, context) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user