protected void LoadData(string filePath, string key) { Records = new List <InterviewProblem>(); if (!filePath.EndsWith(".json")) { Console.WriteLine("[DEBUG] The passed file is not json."); return; } string jsonString = File.ReadAllText(filePath); JObject jsonObject = JObject.Parse(jsonString); foreach (int id in jsonObject[key]) { try { InterviewProblem interviewProblem = InterviewProblemsDB.GetProblem(id); if (interviewProblem != null) { Records.Add(interviewProblem); } } catch (Exception ex) { Console.WriteLine($"[DEBUG] Not able to get problem id: {id}: " + ex.Message); } } }
public InterviewProblem GetRandomProblem() { List <int> keys = InterviewProblemsDB.GetKeys(); Random rand = new Random(); while (true) { int idx = rand.Next(keys.Count); int key = keys[idx]; return(InterviewProblemsDB.GetProblem(key)); } }