Compare commits

..

No commits in common. "86398dc418093e2140de93fda16e53895fa1d67e" and "2ede363766753b5ba1d019e0ae4d99cf6cc44235" have entirely different histories.

8 changed files with 21 additions and 138 deletions

View File

@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -27,18 +26,12 @@ namespace WarmlyShip
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary>
/// Логер
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetWarmlyShip(ILogger<FormMapWithSetWarmlyShip> logger)
public FormMapWithSetWarmlyShip()
{
InitializeComponent();
_logger = logger;
_mapsCollection = new MapsCollection(pictureBox1.Width, pictureBox1.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
@ -85,7 +78,6 @@ namespace WarmlyShip
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
_logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
}
/// <summary>
/// Выбор карты
@ -163,27 +155,15 @@ namespace WarmlyShip
return;
}
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("Объект удален");
pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); ;
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
MessageBox.Show("Объект удален");
pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); ;
}
catch (WarmlyShipNotFoundException ex)
else
{
MessageBox.Show($"Ошибка удаления : {ex.Message}");
MessageBox.Show("Не удалось удалить объект");
}
catch (Exception ex)
{
MessageBox.Show($"Неизвестная ошибка : {ex.Message}");
}
}
/// <summary>
@ -257,15 +237,13 @@ namespace WarmlyShip
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
if (_mapsCollection.SaveData(saveFileDialog.FileName))
{
_mapsCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
else
{
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
@ -279,16 +257,14 @@ namespace WarmlyShip
// TODO продумать логику
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
if (_mapsCollection.LoadData(openFileDialog.FileName))
{
_mapsCollection.LoadData(openFileDialog.FileName);
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
catch (Exception ex)
else
{
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

View File

@ -98,7 +98,7 @@ namespace WarmlyShip
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns></returns>
public void SaveData(string filename)
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
@ -112,24 +112,25 @@ namespace WarmlyShip
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
}
}
return true;
}
/// <summary>
/// Загрузка нформации по автомобилям на парковках из файла
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public void LoadData(string filename)
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
throw new Exception("Файл не найден");
return false;
}
using (StreamReader sr = new(filename))
{
if (!sr.ReadLine().Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
throw new Exception("Формат данных в файле не правильный");
return false;
}
//очищаем записи
@ -151,6 +152,7 @@ namespace WarmlyShip
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
}
return true;
}
}
}

View File

@ -1,7 +1,3 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace WarmlyShip
{
internal static class Program
@ -15,24 +11,7 @@ namespace WarmlyShip
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetWarmlyShip>());
}
Application.Run(new FormMapWithSetWarmlyShip());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormMapWithSetWarmlyShip>()
.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
}
}
}

View File

@ -51,7 +51,6 @@ namespace WarmlyShip
/// <returns></returns>
public int Insert(T ship, int position)
{
//
if (position < 0 || position > Count)
{
return -1;
@ -70,9 +69,6 @@ namespace WarmlyShip
return null;
var result = _places[position];
_places.RemoveAt(position);
//throw new WarmlyShipNotFoundException(position);
return result;
}

View File

@ -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 WarmlyShip
{
[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) { }
}
}

View File

@ -8,23 +8,6 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="nlog.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" 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="NLog.Extensions.Logging" Version="5.2.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@ -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 WarmlyShip
{
[Serializable]
internal class WarmlyShipNotFoundException : ApplicationException
{
public WarmlyShipNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
public WarmlyShipNotFoundException() : base() { }
public WarmlyShipNotFoundException(string message) : base(message) { }
public WarmlyShipNotFoundException(string message, Exception exception) : base(message, exception) { }
protected WarmlyShipNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -1,15 +0,0 @@
<?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>