diff --git a/lainer/Lainer1/Program.cs b/lainer/Lainer1/Program.cs index 0116f3f..2b21cbc 100644 --- a/lainer/Lainer1/Program.cs +++ b/lainer/Lainer1/Program.cs @@ -1,17 +1,48 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; +using Microsoft.Extensions.Configuration; + namespace ProjectLainer { internal static class Program { - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormLainerCollection()); + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = services.BuildServiceProvider()) + { + Application.Run(serviceProvider.GetRequiredService()); + } + } + private static void ConfigureServices(ServiceCollection services) + { + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true) + .Build(); + services.AddSingleton().AddLogging(option => + { + services.AddSingleton(); + var serilogLogger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + services.AddLogging(x => + { + x.SetMinimumLevel(LogLevel.Debug); + x.AddSerilog(logger: serilogLogger, dispose: true); + }); + + }); } } -} +} \ No newline at end of file diff --git a/lainer/Lainer1/SetGeneric.cs b/lainer/Lainer1/SetGeneric.cs index fd73178..fb87cfb 100644 --- a/lainer/Lainer1/SetGeneric.cs +++ b/lainer/Lainer1/SetGeneric.cs @@ -1,4 +1,5 @@ -using System.Numerics; +using ProjectLainer.Exceptions; +using System.Numerics; namespace ProjectLainer.Generics { @@ -13,32 +14,38 @@ namespace ProjectLainer.Generics _maxCount = count; _places = new List(count); } - public bool Insert(T lainer) + + public void Insert(T lainer) { if (_places.Count == _maxCount) { - return false; + throw new StorageOverflowException(_maxCount); } Insert(lainer, 0); - return true; } - public bool Insert(T lainer, int position) + + public void Insert(T lainer, int position) { - if (position < 0 || position > Count || _places.Count >= _maxCount) + if (position >= 0 && position <= Count) { - return false; + _places.Insert(position, lainer); + } + else + { + throw new Exception("Неверная позиция для вставки"); } - _places.Insert(position, lainer); - return true; } - public bool Remove(int position) + + public void Remove(int position) { - if (position < 0 || position >= Count) + if (position < Count && position >= 0) { - return false; + _places.RemoveAt(position); + } + else + { + throw new LainerNotFoundException(position); } - _places.RemoveAt(position); - return true; } public T? this[int position] { diff --git a/lainer/Lainer1/appsettings.json b/lainer/Lainer1/appsettings.json new file mode 100644 index 0000000..0941bdd --- /dev/null +++ b/lainer/Lainer1/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "log.log" } + } + ], + "Properties": { + "Application": "Sample" + } + } + } \ No newline at end of file