public CategoryNode(string name = "", string note = "", CategoryNode par = null) { this.name = name; this.note = note; this.Parent = par; this.problems = new List<CategoryProblem>(); this.branches = new List<CategoryNode>(); }
/// <summary> /// Gets the path to current category node /// </summary> string getPath(CategoryNode nod) { if (nod.Parent == null) { return nod.name; } else { string path = getPath(nod.Parent) + Environment.NewLine; for (int i = nod.Level; i > 0; --i) { path += " "; } path += "=> " + nod.name; return path; } }
/// <summary> /// Adds a name to Nodes or returns the CategoryNode if already exists /// </summary> /// <param name="title">Title of new CategoryNode to add</param> /// <returns></returns> public CategoryNode AddNode(string path) { //get path parts string _sub = path, _left = null; int _fin = path.IndexOf(SEPARATOR); if (_fin > 0) { _sub = path.Substring(0, _fin); _left = path.Substring(_fin + 1); } //get previous node CategoryNode _nod = null; int __i = IndexOfNode(_sub); if (__i < this.Nodes.Count && this.Nodes[__i].Title.CompareTo(_sub) == 0) { _nod = this.Nodes[__i]; } //create and new node if necessary if (_nod == null) { _nod = new CategoryNode(_sub); _nod.Parent = this; this.Nodes.Insert(__i, _nod); //__i as index is always rightly bounded } //add child node and return last child if (_left != null) { return(_nod.AddNode(_left)); } else { return(_nod); } }
private static void LoadList(List<List<object>> datalist) { SortedDictionary<int, List<ProblemInfo>> catData = new SortedDictionary<int, List<ProblemInfo>>(); //Load problem from list foreach (List<object> lst in datalist) { ProblemInfo plist = new ProblemInfo(lst); problemList.Add(plist); //set the file size string file = LocalDirectory.GetProblemHtml(plist.pnum); if (File.Exists(file)) plist.fileSize = (new System.IO.FileInfo(file)).Length; SetProblem(plist.pnum, plist); SetNumber(plist.pid, plist.pnum); //Categorize if (!catData.ContainsKey(plist.volume)) { catData.Add(plist.volume, new List<ProblemInfo>()); } catData[plist.volume].Add(plist); } //add volume category var volCat = new CategoryNode("Volumes", "Problem list by volumes"); categoryRoot.branches.Add(volCat); foreach (var data in catData.Values) { string vol = string.Format("Volume {0:000}", data[0].volume); var nod = new CategoryNode(vol, "", volCat); volCat.branches.Add(nod); foreach (var p in data) { nod.problems.Add(new CategoryProblem(p.pnum)); } } volCat.ProcessData(); }
public static void RunLoadAsync(object background) { if (!IsReady) return; if ((bool)background) { bool back = System.Threading.ThreadPool.QueueUserWorkItem(RunLoadAsync, false); if (back) return; } try { IsReady = false; //initialize global values problemList = new List<ProblemInfo>(); problemId = new SortedDictionary<long, long>(); problemNum = new SortedDictionary<long, ProblemInfo>(); categoryRoot = new CategoryNode("Root", "All Categories"); //get object data from json data string text = File.ReadAllText(LocalDirectory.GetProblemInfoFile()); var data = JsonConvert.DeserializeObject<List<List<object>>>(text); if (data == null || data.Count == 0) throw new NullReferenceException("Problem database was empty"); //load all lists from object data LoadList(data); LoadOthers(); data.Clear(); IsAvailable = true; } catch (Exception ex) { Logger.Add(ex.Message, "Problem Database|RunLoadAsync()"); if (!IsAvailable) Internet.Downloader.DownloadProblemDatabase(); } //load default user LoadDefaultUser(); //load categories LoadCategories(); IsReady = true; Interactivity.CategoryDataUpdated(); Interactivity.ProblemDatabaseUpdated(); }
public void AddProblemsFrom(CategoryNode nod) { foreach (var v in nod.allProbs.Values) { AddProblem(v); } }