private bool TryLoadPriorityMap() { try { PriorityMap.Clear(); Log.InfoV($"Reading {Options.PriorityFile}..."); using (TextFieldParser p = new TextFieldParser(Options.PriorityFile)) { p.CommentTokens = new string[] { "#" }; p.SetDelimiters(new string[] { "," }); while (!p.EndOfData) { bool hasPriority = false; bool hasIndex = false; int priority = -1; int index = -1; long line = p.LineNumber; string[] fields = p.ReadFields(); if (fields.Length >= 2) { hasPriority = int.TryParse(fields[0], out priority); hasIndex = int.TryParse(fields[1], out index); } if (!hasPriority || !hasIndex || index < 0) { Log.Info($"Warning: {Path.GetFileName(Options.PriorityFile)}:{line}: Line is malformatted."); continue; } if (index >= MaxCapacity) { Log.Info($"Warning: {Path.GetFileName(Options.PriorityFile)}:{line}: Index exceeds maximum value of {MaxCapacity - 1}."); continue; } if (!PriorityMap.ContainsKey(priority)) { PriorityMap[priority] = new List <int>(); } PriorityMap[priority].Add(index); } } return(true); } catch (Exception e) { if (e is IOException || e is UnauthorizedAccessException || e is SecurityException) { Result = ExitCode.BadIO; Log.Exception(e); return(false); } throw; } }
private void GeneratePriorityMap() { PriorityMap.Clear(); IEnumerable <int> carGenIndices = Enumerable.Range(0, MaxCapacity).OrderBy(e => RandGen.Next()); int i = 0; foreach (int index in carGenIndices) { PriorityMap[i++] = new List <int>() { index }; } }