Ejemplo n.º 1
0
 void addProblem()
 {
     if (node.problems == null) return;
     int start = (int)start1.Value;
     int stop = (int)stop1.Value;
     int step = (int)step1.Value;
     for (int i = start; i <= stop; i += step)
     {
         var v = new CategoryProblem(i);
         v.setParent(node);
         node.problems.Add(v);
     }
 }
Ejemplo n.º 2
0
        private bool AddAll()
        {
            string probs = "";
            foreach(string line in fastColoredTextBox1.Lines)
            {
                if (string.IsNullOrEmpty(line.Trim())) continue;
                string[] other = line.Trim().Split(',');

                int pnum;
                if (!int.TryParse(other[0], out pnum))
                {
                    probs += line + "\n";
                    continue;
                }

                CategoryProblem cp = new CategoryProblem(pnum);
                if (other.Length > 1)
                {
                    cp.star = other[1] == "0" ? false : true;
                }
                if(other.Length > 2)
                {
                    cp.note = other[2];
                }

                if(!node.hasProblem(pnum)) //check if exist before adding
                {
                    node.problems.Add(cp);
                }
                else
                {
                    probs += line + ", [info: alrady exist]\n";
                }
            }
            fastColoredTextBox1.Text = probs;
            return (probs.Length == 0);
        }
Ejemplo n.º 3
0
 private void addProbButton_Click(object sender, EventArgs e)
 {
     try
     {
         branchEdited = true;
         CategoryProblem cp = new CategoryProblem();
         cp.setParent(editingNode);
         editingNode.problems.Add(cp);
         problemListView.SetObjects(editingNode.problems);
         int last = problemListView.GetItemCount() - 1;
         problemListView.EnsureVisible(last);
         problemListView.StartCellEdit(problemListView.GetItem(last), 0);
     }
     catch (Exception ex)
     {
         Console.Write("Error : " + ex.Message);
     }
 }
Ejemplo n.º 4
0
        static void downloadCPBook(int ed)
        {
            string url = "http://uhunt.felix-halim.net/api/cpbook/" + ed.ToString();
            string path = @"J:\Projects\GitHub\uva-problem-category\data\CP Book" + ed.ToString() + ".cat";

            //download data
            Console.WriteLine("Downloading \"" + url + "\" ...");
            var client = new System.Net.WebClient();
            byte[] data = client.DownloadData(url);

            //parse data
            Console.WriteLine("Parsing ...");
            string json = System.Text.Encoding.UTF8.GetString(data);
            object alldat = Newtonsoft.Json.JsonConvert.DeserializeObject(json);

            //build category branch
            Console.WriteLine("Building ...");
            CategoryNode cb = new CategoryNode();
            cb.name = "Context Programming Book " + ed.ToString();
            cb.note = "Contains category description from uHunt server";
            cb.branches = new System.Collections.Generic.List<CategoryNode>();

            //getting top branches
            foreach (var o in (Newtonsoft.Json.Linq.JArray)alldat)
            {
                //add new branch
                CategoryNode b1 = new CategoryNode();
                b1.branches = new System.Collections.Generic.List<CategoryNode>();
                cb.branches.Add(b1);
                //extract name of the branch
                b1.name = o.Value<string>("title");
                //get sub branches
                foreach (var o2 in o.Value<Newtonsoft.Json.Linq.JArray>("arr"))
                {
                    //add new branch
                    CategoryNode b2 = new CategoryNode();
                    b2.branches = new System.Collections.Generic.List<CategoryNode>();
                    b1.branches.Add(b2);
                    //extract name of the branch
                    b2.name = o2.Value<string>("title");
                    //get sub branches
                    foreach (var o3 in o2.Value<Newtonsoft.Json.Linq.JArray>("arr"))
                    {
                        //add new branch
                        CategoryNode b3 = new CategoryNode();
                        b3.problems = new System.Collections.Generic.List<CategoryProblem>();
                        b2.branches.Add(b3);
                        //extract name
                        var o4 = (Newtonsoft.Json.Linq.JArray)o3;
                        b3.name = o4[0].ToString();
                        for (int i = 1; i < o4.Count; ++i)
                        {
                            //add category problem
                            CategoryProblem p1 = new CategoryProblem();
                            b3.problems.Add(p1);
                            //extract values
                            int pn = (int)o4[i].ToObject(typeof(int));
                            p1.pnum = (pn < 0 ? -pn : pn);
                            p1.star = (pn < 0);
                        }
                    }

                }
            }

            Console.WriteLine("Saving Data...");
            json = Newtonsoft.Json.JsonConvert.SerializeObject(cb, Newtonsoft.Json.Formatting.Indented);
            System.IO.File.WriteAllText(path, json);
            Console.WriteLine("Process completed.\n");
        }