Compare commits

..

No commits in common. "1721b0d06091be808ba131aa8eba28a2d7b8f987" and "ec836fb5268a00eee2d2869269e35b3ca8794d90" have entirely different histories.

8 changed files with 23 additions and 133 deletions

View File

@ -16,23 +16,6 @@
<LangVersion>preview</LangVersion>
</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.1.0" />
</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 AirBomber
{
[Serializable]
internal class AirBomberNotFoundException : ApplicationException
{
public AirBomberNotFoundException() : base() { }
public AirBomberNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
public AirBomberNotFoundException(string message) : base(message) { }
public AirBomberNotFoundException(string message, Exception exception) : base (message, exception) { }
protected AirBomberNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -24,12 +23,9 @@ namespace AirBomber
private readonly MapsCollection _mapsCollection;
private readonly ILogger _logger;
public FormMapWithSetAirBomber(ILogger<FormMapWithSetAirBomber> logger)
public FormMapWithSetAirBomber()
{
InitializeComponent();
_logger = logger;
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
@ -97,25 +93,14 @@ namespace AirBomber
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("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
catch(AirBomberNotFoundException ex)
else
{
MessageBox.Show($"Ошибка удаления: {ex.Message}");
}
catch (Exception ex)
{
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
MessageBox.Show("Не удалось удалить объект");
}
}
@ -177,7 +162,6 @@ namespace AirBomber
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
_logger.LogInformation($"Добавлена карта: {textBoxNewMapName.Text}");
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
@ -203,14 +187,13 @@ namespace AirBomber
{
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);
}
}
}
@ -219,16 +202,15 @@ namespace AirBomber
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
if (_mapsCollection.LoadData(openFileDialog.FileName))
{
_mapsCollection.LoadData(openFileDialog.FileName);
MessageBox.Show("Загрузка прошла успешно", "Результат",
MessageBox.Show("Загрузка прошла успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
catch(Exception ex)
else
{
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
MessageBox.Show("Не загрузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

View File

@ -45,7 +45,7 @@ namespace AirBomber
}
}
public void SaveData(string filename)
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
@ -60,13 +60,14 @@ namespace AirBomber
separatorData)}{Environment.NewLine}");
}
}
return true;
}
public void LoadData(string filename)
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
throw new Exception("Файл не найден");
return false;
}
string bufferTextFromFile = "";
using (StreamReader sr = new(filename))
@ -79,7 +80,7 @@ namespace AirBomber
{
if (!str.Contains("MapsCollection"))
{
throw new Exception("Формат данных в файлен не правильный");
return false;
}
else
{
@ -110,6 +111,7 @@ namespace AirBomber
}
}
}
return true;
}
}
}

View File

@ -1,8 +1,3 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System.ServiceProcess;
namespace AirBomber
{
internal static class Program
@ -16,22 +11,7 @@ namespace AirBomber
// 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<FormMapWithSetAirBomber>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormMapWithSetAirBomber>()
.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
Application.Run(new FormMapWithSetAirBomber());
}
}
}

View File

@ -30,7 +30,7 @@ namespace AirBomber
{
if (position < 0 || position > _maxCount)
{
throw new StorageOverflowException(_maxCount);
return -1;
}
_places.Insert(position, airBomber);
return position;
@ -40,16 +40,10 @@ namespace AirBomber
{
if (position < 0 || position > _maxCount)
{
throw new StorageOverflowException(_maxCount);
return null;
}
T elem = _places[position];
_places[position] = null;
if (elem == null)
{
throw new AirBomberNotFoundException(position);
}
return elem;
}

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 AirBomber
{
[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 innerException) : base(message, innerException) { }
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -1,13 +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>