using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Phares.Shared; using System.Diagnostics; using System.Reflection; using View_by_Distance.Date.Group.Models; using View_by_Distance.Shared.Models.Stateless.Methods; namespace View_by_Distance.Date.Group; public class Program { public static void Secondary(ILogger logger, List args) { Assembly assembly = Assembly.GetExecutingAssembly(); bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug"); IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero); IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() .AddEnvironmentVariables() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true) .AddUserSecrets(); IConfigurationRoot configurationRoot = configurationBuilder.Build(); AppSettings appSettings = Models.Binder.AppSettings.Get(configurationRoot); if (appSettings.MaxDegreeOfParallelism > Environment.ProcessorCount) throw new Exception("MaxDegreeOfParallelism must be =< Environment.ProcessorCount!"); if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) throw new Exception("Working directory name must have a value!"); string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName); Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory); int silentIndex = args.IndexOf("s"); if (silentIndex > -1) args.RemoveAt(silentIndex); try { if (args is null) throw new Exception("args is null!"); #nullable disable if (IProperty.IsWrongYear("-".Split(' '), "2021").Item1.HasValue) throw new Exception("-"); if (IProperty.IsWrongYear("Christmass".Split(' '), "2021").Item1.HasValue) throw new Exception("Christmass"); if (IProperty.IsWrongYear("Christmass 2021".Split(' '), "2021").Item1.Value) throw new Exception("Christmass"); if (IProperty.IsWrongYear("Christmass ~2021".Split(' '), "2021").Item1.Value) throw new Exception("Christmass"); if (IProperty.IsWrongYear("Christmass ~2021.4".Split(' '), "2021").Item1.Value) throw new Exception("Christmass"); if (!IProperty.IsWrongYear("Christmass 2021".Split(' '), "2025").Item1.Value) throw new Exception("Christmass"); if (!IProperty.IsWrongYear("Christmass ~2021".Split(' '), "2025").Item1.Value) throw new Exception("Christmass"); if (!IProperty.IsWrongYear("Christmass ~2021.4".Split(' '), "2025").Item1.Value) throw new Exception("Christmass"); if (IProperty.IsWrongYear("England 2017".Split(' '), "2017").Item1.Value) throw new Exception("England"); if (IProperty.IsWrongYear("Logan Michael".Split(' '), "2021").Item1.HasValue) throw new Exception("Logan Michael"); if (IProperty.IsWrongYear("Logan Michael 2021".Split(' '), "2021").Item1.Value) throw new Exception("Logan Michael"); if (IProperty.IsWrongYear("Logan Michael ~2021".Split(' '), "2021").Item1.Value) throw new Exception("Logan Michael"); if (IProperty.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2021").Item1.Value) throw new Exception("Logan Michael"); if (!IProperty.IsWrongYear("Logan Michael 2021".Split(' '), "2025").Item1.Value) throw new Exception("Logan Michael"); if (!IProperty.IsWrongYear("Logan Michael ~2021".Split(' '), "2025").Item1.Value) throw new Exception("Logan Michael"); if (!IProperty.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2025").Item1.Value) throw new Exception("Logan Michael"); if (IProperty.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2021").Item2[0] != "~2021.4") throw new Exception("Logan Michael"); if (IProperty.IsWrongYear("Chelsea's 2nd Birthday =2014".Split(' '), "2014").Item1.Value) throw new Exception("Chelsea"); #nullable restore Shared.Models.Console console = new(); DateGroup _ = new(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console); } catch (Exception ex) { logger?.LogError(ex, "Error!"); } if (silentIndex > -1) logger?.LogDebug("Done. Bye"); else { logger?.LogDebug("Done. Press 'Enter' to end"); _ = Console.ReadLine(); } } public static void Main(string[] args) { ILogger? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService>(); if (args is not null) Secondary(logger, args.ToList()); else Secondary(logger, []); } }