This commit is contained in:
Daniya_Youdakova 2022-12-25 17:22:08 +04:00
parent c3e9768e3e
commit f0436685a8
3 changed files with 39 additions and 8 deletions

View File

@ -184,8 +184,10 @@ namespace AircraftCarrier
{ {
int yNumOfPlaces = _pictureHeight / _placeSizeHeight; int yNumOfPlaces = _pictureHeight / _placeSizeHeight;
int xNumOfPlaces = _pictureWidth / _placeSizeWidth; int xNumOfPlaces = _pictureWidth / _placeSizeWidth;
int rowNum = yNumOfPlaces - 1; int rowNum = yNumOfPlaces - 1;
int columnNum = 0; int columnNum = 0;
for (int i = 0; i < _setAircraftCarriers.Count; i++) for (int i = 0; i < _setAircraftCarriers.Count; i++)
{ {
if (_setAircraftCarriers[i] != null) if (_setAircraftCarriers[i] != null)

View File

@ -34,7 +34,7 @@ namespace AircraftCarrier
private readonly char separatorData = ';'; private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight) public MapsCollection(int pictureWidth, int pictureHeight)
{ {
_mapStorages = new Dictionary<string,MapWithSetAircraftCarriersGeneric<IDrawningObject, AbstractMap>>(); _mapStorages = new Dictionary<string, MapWithSetAircraftCarriersGeneric<IDrawningObject, AbstractMap>>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
} }
@ -94,7 +94,7 @@ namespace AircraftCarrier
/// </summary> /// </summary>
/// <param name="filename">Путь и имя файла</param> /// <param name="filename">Путь и имя файла</param>
/// <returns></returns> /// <returns></returns>
public bool SaveData(string filename) public void SaveData(string filename)
{ {
if (File.Exists(filename)) if (File.Exists(filename))
{ {
@ -108,18 +108,18 @@ namespace AircraftCarrier
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}"); sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
} }
} }
return true;
} }
/// <summary> /// <summary>
/// Загрузка нформации по автомобилям на парковках из файла /// Загрузка нформации по автомобилям на парковках из файла
/// </summary> /// </summary>
/// <param name="filename"></param> /// <param name="filename"></param>
/// <returns></returns> /// <returns></returns>
public bool LoadData(string filename) public void LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ {
return false; throw new FileNotFoundException("Файл не найден");
} }
using (StreamReader sr = new(filename)) using (StreamReader sr = new(filename))
{ {
@ -127,7 +127,7 @@ namespace AircraftCarrier
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection")) if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
{ {
//если нет такой записи, то это не те данные //если нет такой записи, то это не те данные
return false; throw new FileFormatException("Формат данных в файле неправильный");
} }
//очищаем записи //очищаем записи
_mapStorages.Clear(); _mapStorages.Clear();
@ -148,7 +148,6 @@ namespace AircraftCarrier
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
} }
} }
return true;
} }
} }
} }

View File

@ -1,3 +1,9 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using AircraftCarrier;
using Serilog;
namespace AircraftCarrier namespace AircraftCarrier
{ {
internal static class Program internal static class Program
@ -11,7 +17,31 @@ namespace AircraftCarrier
// 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.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormMapWithSetAircraftCarriers()); var services = new ServiceCollection();
ConfigureServices(services);
//Application.Run(new FormMapWithSetAircraftCarriers());
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetAircraftCarriers>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormMapWithSetAircraftCarriers>()
.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);
});
} }
} }
} }