static void Main(string[] args) { var logger = new LoggerConverter(NLog.Web.NLogBuilder .ConfigureNLog("nlog.config") .GetCurrentClassLogger()); Parser.Default.ParseArguments <Options>(args).WithParsed(opts => { List <ActivityDefinition> activitySchedule = ActivityDefinition.ReadScheduleFromCsvFile( opts.ActivityScheduleCsvPath, logger); if (activitySchedule == null) { Environment.Exit(-2); } // If activity definition is included, fold in the limit numbers into the schedule if (!String.IsNullOrEmpty(opts.ActivityDefinitionsPath)) { var activityDefinitions = ActivityDefinition.ReadActivityDefinitions( opts.ActivityDefinitionsPath, logger); if (activityDefinitions == null) { Environment.Exit(-2); } foreach (var activityDefinition in activityDefinitions) { var matchingSchedule = activitySchedule .First(activity => activity.Name.Equals(activityDefinition.Name)); if (matchingSchedule != null) { matchingSchedule.MaximumCapacity = activityDefinition.MaximumCapacity; matchingSchedule.OptimalCapacity = activityDefinition.OptimalCapacity; matchingSchedule.MinimumCapacity = activityDefinition.MinimumCapacity; } } } CreateWorkbook(opts, activitySchedule); Console.Out.Write($"Generated {opts.ScheduleExcelPath} " + $"from {opts.ActivityScheduleCsvPath}"); if (!String.IsNullOrEmpty(opts.ActivityDefinitionsPath)) { Console.Out.Write($" and {opts.ActivityDefinitionsPath}"); } Console.Out.WriteLine(); Environment.Exit(0); }).WithNotParsed(opts => { Environment.Exit(-1); }); }
static void Main(string[] args) { var logger = new LoggerConverter(NLog.Web.NLogBuilder .ConfigureNLog("nlog.config") .GetCurrentClassLogger()); Parser.Default.ParseArguments <Options>(args).WithParsed(opts => { var activityDefinitions = ActivityDefinition.ReadActivityDefinitions( opts.ActivityDefinitionsPath, logger); if (activityDefinitions == null) { Environment.Exit(-2); } logger.LogInformation($"Found {activityDefinitions.Count} activity definitions in the file: {opts.ActivityDefinitionsPath}"); var camperRequestsList = CamperRequests.ReadCamperRequests(opts.CamperRequestsPath, activityDefinitions, logger); if (camperRequestsList == null) { Environment.Exit(-2); } logger.LogInformation($"Found {camperRequestsList.Count} campers in the file: {opts.CamperRequestsPath}"); // Sort the campers by difficulty to resolve activity list. // Most difficult go first. camperRequestsList.Sort(); // Preload the activity blocks foreach (var activity in activityDefinitions) { activity.PreloadBlocks(); } List <CamperRequests> unsuccessfulCamperRequests = Scheduler.ScheduleActivities(camperRequestsList, opts.UseOptimalLimit, logger); if (opts.UseOptimalLimit && unsuccessfulCamperRequests.Any()) { logger.LogDebug($"Attempting to resolve {unsuccessfulCamperRequests.Count} " + $"unsuccessful camper requests using the activity maximum limits"); unsuccessfulCamperRequests = Scheduler.ScheduleActivities(unsuccessfulCamperRequests, false, logger); } foreach (var activity in activityDefinitions) { foreach (var activityBlock in activity.ScheduledBlocks) { logger.LogDebug($"Scheduled '{activity.Name}' " + $"in block {activityBlock.TimeSlot} " + $"with {activityBlock.AssignedCampers.Count} campers"); } } if (!String.IsNullOrWhiteSpace(opts.ActivityScheduleCsvPath)) { ActivityDefinition.WriteScheduleToCsvFile(activityDefinitions, opts.ActivityScheduleCsvPath, logger); logger.LogInformation($"Wrote the activity schedule file to '{opts.ActivityScheduleCsvPath}'"); } if (!String.IsNullOrWhiteSpace(opts.CamperScheduleCsvPath)) { Camper.WriteScheduleToCsvFile(camperRequestsList.Select(cr => cr.Camper), opts.CamperScheduleCsvPath, logger); logger.LogInformation($"Wrote the camper schedule file to '{opts.CamperScheduleCsvPath}'"); } Console.Out.WriteLine(); foreach (var unhappyCamper in unsuccessfulCamperRequests) { List <ActivityRequest> unscheduledActivities = unhappyCamper.UnscheduledActivities; if (unscheduledActivities.Any(ar => ar.Rank < 3)) { logger.LogInformation($"Failed to place {unhappyCamper.Camper} in {String.Join(',', unscheduledActivities.Select(ar => ar?.ToString()))} "); } else { logger.LogInformation($"Failed to place {unhappyCamper.Camper} in " + $"{String.Join(',', unscheduledActivities.Select(ar => ar?.ToString()))} " + $"or alternate '{unhappyCamper.AlternateActivity?.Name}'"); } } if (unsuccessfulCamperRequests.Count == 0) { logger.LogInformation($"Successfully scheduled {camperRequestsList.Count} " + $"campers into {activityDefinitions.Count} activities"); Environment.Exit(0); } else { logger.LogInformation($"Failed to schedule {unsuccessfulCamperRequests.Count} " + $"of {camperRequestsList.Count} campers into " + $"{activityDefinitions.Count} activities"); Environment.Exit(-4); } }).WithNotParsed(opts => { Environment.Exit(-1); }); }