コード例 #1
0
ファイル: FPSListBinder.cs プロジェクト: ii0/EasyFPSViewer
 public void CloseEditForm(FPSItem fpsItem)
 {
     if (EditFormDic.ContainsKey(fpsItem) && !EditFormDic[fpsItem].IsDisposed)
     {
         EditFormDic[fpsItem].Close();
     }
 }
コード例 #2
0
ファイル: FPSListBinder.cs プロジェクト: ii0/EasyFPSViewer
        public int Search(string title, string description)
        {
            ClearSelectStatus();
            var quary = from n in FPSItemList
                        where n.Title.ToLower().Contains(title.ToLower())
                        where n.Description.ToLower().Contains(description.ToLower())
                        select n;

            FPSItem firstItem = null;

            foreach (var fpsItem in quary)
            {
                if (firstItem == null)
                {
                    firstItem = fpsItem;
                }
                ViewItemDic[fpsItem].Selected = true;
            }

            if (firstItem != null)
            {
                ViewItemDic[firstItem].EnsureVisible();
                ViewItemDic[firstItem].Focused = true;
            }

            return(quary.Count());
        }
コード例 #3
0
ファイル: FPSListBinder.cs プロジェクト: ii0/EasyFPSViewer
 public void CloseProblemForm(FPSItem fpsItem)
 {
     if (ProblemFormDic.ContainsKey(fpsItem) && !ProblemFormDic[fpsItem].IsDisposed)
     {
         ProblemFormDic[fpsItem].Close();
     }
 }
コード例 #4
0
        public ProblemForm(FPSItem item) : this()
        {
            this.Text = item.Title;

            fpsItem = item;
            tempDir = GetTempDirectory();

            ReleaseFPSResources();
            webBrowser_Main.Url = new Uri(@"file:\\" + Path.Combine(tempDir, "index.html"));
        }
コード例 #5
0
ファイル: FPSListBinder.cs プロジェクト: ii0/EasyFPSViewer
 public void CreateEditForm(FPSItem fpsItem)
 {
     if (!EditFormDic.ContainsKey(fpsItem) || EditFormDic[fpsItem].IsDisposed)
     {
         EditFormDic[fpsItem] = new EditForm(fpsItem);
         EditFormDic[fpsItem].Show();
     }
     else
     {
         EditFormDic[fpsItem].Focus();
     }
 }
コード例 #6
0
ファイル: FPSListBinder.cs プロジェクト: ii0/EasyFPSViewer
 public void CreatePorblemForm(FPSItem fpsItem)
 {
     if (!ProblemFormDic.ContainsKey(fpsItem) || ProblemFormDic[fpsItem].IsDisposed)
     {
         ProblemFormDic[fpsItem] = new ProblemForm(fpsItem);
         ProblemFormDic[fpsItem].Show();
     }
     else
     {
         ProblemFormDic[fpsItem].Focus();
     }
 }
コード例 #7
0
ファイル: FPSListBinder.cs プロジェクト: ii0/EasyFPSViewer
        public void Remove(FPSItem fpsItem)
        {
            CloseProblemForm(fpsItem);
            CloseEditForm(fpsItem);

            ListView.Items.Remove(ViewItemDic[fpsItem]);
            ViewItemDic.Remove(fpsItem);
            ProblemFormDic.Remove(fpsItem);
            EditFormDic.Remove(fpsItem);

            FPSItemList.Remove(fpsItem);

            GC.Collect();
        }
コード例 #8
0
        public static string Build(FPSItem item)
        {
            StringBuilder sb = new StringBuilder(Properties.Resources.FPSWebView);

            sb.Replace("[[[Title]]]", item.Title);
            sb.Replace("[[[Description]]]", item.Description);
            sb.Replace("[[[TimeLimit]]]", item.TimeLimit + item.TimeLimitUnit);
            sb.Replace("[[[MemoryLimit]]]", item.MemoryLimit + item.MemoryLimitUnit);
            sb.Replace("[[[Input]]]", item.Input);
            sb.Replace("[[[Output]]]", item.Output);
            sb.Replace("[[[Sample Input]]]", item.SampleInput);
            sb.Replace("[[[Sample Output]]]", item.SampleOutput);
            sb.Replace("[[[Hint]]]", item.Hint);
            sb.Replace("[[[Source]]]", item.Source);
            return(sb.ToString());
        }
コード例 #9
0
ファイル: FPSListBinder.cs プロジェクト: ii0/EasyFPSViewer
        public void Add(FPSItem fpsItem)
        {
            ListViewItem viewItem = ListView.Items.Add(fpsItem.Title);

            viewItem.SubItems.Add(fpsItem.TimeLimit + fpsItem.TimeLimitUnit);
            viewItem.SubItems.Add(fpsItem.MemoryLimit + fpsItem.MemoryLimitUnit);

            int casesCount = fpsItem.TestOutput.Length;

            if (!string.IsNullOrEmpty(fpsItem.SampleOutput))
            {
                casesCount++;
            }
            viewItem.SubItems.Add(casesCount.ToString());
            viewItem.SubItems.Add((Math.Max(fpsItem.TestDataSize / 1024, 1)).ToString() + "KB");

            FPSItemList.Add(fpsItem);
            ViewItemDic[fpsItem] = viewItem;
        }
コード例 #10
0
        public FPSItem ParseItem(XmlNode itemNode)
        {
            List <FPSItemSolution> solutionsList = new List <FPSItemSolution>();

            foreach (XmlNode node in itemNode.ChildNodes)
            {
                if (node.Name == "solution")
                {
                    solutionsList.Add(new FPSItemSolution
                    {
                        Language   = node.Attributes[0].Value,
                        SourceCode = node.InnerText
                    });
                }
            }

            List <string> testInputList = new List <string>();

            foreach (XmlNode node in itemNode.ChildNodes)
            {
                if (node.Name == "test_input")
                {
                    testInputList.Add(node.InnerText);
                }
            }

            List <string> testOutputList = new List <string>();

            foreach (XmlNode node in itemNode.ChildNodes)
            {
                if (node.Name == "test_output")
                {
                    testOutputList.Add(node.InnerText);
                }
            }

            List <FPSItemImage> imagesList = new List <FPSItemImage>();

            foreach (XmlNode node in itemNode.ChildNodes)
            {
                try
                {
                    if (node.Name == "img")
                    {
                        string src = node.ChildNodes[0].InnerText;
                        byte[] img = Convert.FromBase64String(node.ChildNodes[1].InnerText);
                        imagesList.Add(new FPSItemImage
                        {
                            Path  = src,
                            Image = img
                        });
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }

            List <FPSItemSpecialJudge> spjList = new List <FPSItemSpecialJudge>();

            foreach (XmlNode node in itemNode.ChildNodes)
            {
                if (node.Name == "spj")
                {
                    spjList.Add(new FPSItemSpecialJudge
                    {
                        Language   = node.Attributes[0].Value,
                        SourceCode = node.InnerText
                    });
                }
            }

            int    timeLimit       = Int32.Parse(TryGetChildValue(itemNode, "time_limit", "1"));
            string timeLimitUnit   = TryGetChildAttrValue(itemNode, "time_limit", "unit", "s");
            int    memoryLimit     = Int32.Parse(TryGetChildValue(itemNode, "memory_limit", "1"));
            string memoryLimitUnit = TryGetChildAttrValue(itemNode, "memory_limit", "unit", "s");

            string title        = TryGetChildValue(itemNode, "title", "No Title");
            string description  = TryGetChildValue(itemNode, "description", "Description");
            string input        = TryGetChildValue(itemNode, "input", "");
            string output       = TryGetChildValue(itemNode, "output", "");
            string sampleInput  = TryGetChildValue(itemNode, "sample_input", "");
            string sampleOutput = TryGetChildValue(itemNode, "sample_output", "");
            string hint         = TryGetChildValue(itemNode, "hint", "");
            string source       = TryGetChildValue(itemNode, "source", "");

            int size = 0;

            size += Encoding.UTF8.GetByteCount(sampleInput);
            size += Encoding.UTF8.GetByteCount(sampleOutput);
            foreach (string data in testInputList)
            {
                size += Encoding.UTF8.GetByteCount(data);
            }
            foreach (string data in testOutputList)
            {
                size += Encoding.UTF8.GetByteCount(data);
            }

            FPSItem fpsItem = new FPSItem
            {
                Title           = title,
                Description     = description,
                TimeLimit       = timeLimit,
                TimeLimitUnit   = timeLimitUnit,
                MemoryLimit     = memoryLimit,
                MemoryLimitUnit = memoryLimitUnit,
                Hint            = hint,
                Source          = source,
                Input           = input,
                Output          = output,
                SampleInput     = sampleInput,
                SampleOutput    = sampleOutput,
                TestInput       = testInputList.ToArray(),
                TestOutput      = testOutputList.ToArray(),
                Solutions       = solutionsList.ToArray(),
                Images          = imagesList.ToArray(),
                SpecialJudge    = spjList.ToArray(),
                TestDataSize    = size
            };

            return(fpsItem);
        }
コード例 #11
0
        private void ConvertAndAddToXmlNode(XmlDocument doc, XmlNode node, FPSItem fpsItem)
        {
            XmlNode itemRoot = doc.CreateElement("item");

            node.AppendChild(itemRoot);

            XmlElement title = doc.CreateElement("title");

            title.InnerXml = GetCDATAString(fpsItem.Title);
            itemRoot.AppendChild(title);

            XmlElement timeLimit = doc.CreateElement("time_limit");

            timeLimit.InnerXml = GetCDATAString(fpsItem.TimeLimit);
            timeLimit.SetAttribute("unit", fpsItem.TimeLimitUnit);
            itemRoot.AppendChild(timeLimit);

            XmlElement memoryLimit = doc.CreateElement("memory_limit");

            memoryLimit.InnerXml = GetCDATAString(fpsItem.MemoryLimit);
            memoryLimit.SetAttribute("unit", fpsItem.MemoryLimitUnit);
            itemRoot.AppendChild(memoryLimit);

            foreach (FPSItemImage fpsImg in fpsItem.Images)
            {
                XmlElement imgNode = doc.CreateElement("img");
                XmlElement src     = doc.CreateElement("src");
                src.InnerXml = GetCDATAString(fpsImg.Path);
                XmlElement base64 = doc.CreateElement("base64");
                base64.InnerXml = GetCDATAString(Convert.ToBase64String(fpsImg.Image));
                imgNode.AppendChild(src);
                imgNode.AppendChild(base64);

                itemRoot.AppendChild(imgNode);
            }

            XmlElement description = doc.CreateElement("description");

            description.InnerXml = GetCDATAString(fpsItem.Description);
            itemRoot.AppendChild(description);

            XmlElement input = doc.CreateElement("input");

            input.InnerXml = GetCDATAString(fpsItem.Input);
            itemRoot.AppendChild(input);

            XmlElement output = doc.CreateElement("output");

            output.InnerXml = GetCDATAString(fpsItem.Output);
            itemRoot.AppendChild(output);

            XmlElement sampleInput = doc.CreateElement("sample_input");

            sampleInput.InnerXml = GetCDATAString(fpsItem.SampleInput);
            itemRoot.AppendChild(sampleInput);

            XmlElement sampleOutput = doc.CreateElement("sample_output");

            sampleOutput.InnerXml = GetCDATAString(fpsItem.SampleOutput);
            itemRoot.AppendChild(sampleOutput);

            int inIndex  = 0;
            int outIndex = 0;

            while (inIndex < fpsItem.TestInput.Length || outIndex < fpsItem.TestOutput.Length)
            {
                if (inIndex < fpsItem.TestInput.Length)
                {
                    XmlElement testInput = doc.CreateElement("test_input");
                    testInput.InnerXml = GetCDATAString(fpsItem.TestInput[inIndex++]);
                    itemRoot.AppendChild(testInput);
                }

                if (outIndex < fpsItem.TestOutput.Length)
                {
                    XmlElement testOutput = doc.CreateElement("test_output");
                    testOutput.InnerXml = GetCDATAString(fpsItem.TestOutput[outIndex++]);
                    itemRoot.AppendChild(testOutput);
                }
            }

            XmlElement hint = doc.CreateElement("hint");

            hint.InnerXml = GetCDATAString(fpsItem.Hint);
            itemRoot.AppendChild(hint);

            XmlElement source = doc.CreateElement("source");

            source.InnerXml = GetCDATAString(fpsItem.Source);
            itemRoot.AppendChild(source);

            foreach (FPSItemSolution solu in fpsItem.Solutions)
            {
                XmlElement soluNode = doc.CreateElement("solution");
                soluNode.SetAttribute("language", solu.Language);
                soluNode.InnerXml = GetCDATAString(solu.SourceCode);
                itemRoot.AppendChild(soluNode);
            }

            foreach (FPSItemSpecialJudge spj in fpsItem.SpecialJudge)
            {
                XmlElement spjNode = doc.CreateElement("spj");
                spjNode.SetAttribute("language", spj.Language);
                spjNode.InnerXml = GetCDATAString(spj.SourceCode);
            }
        }
コード例 #12
0
 private void CloseItemForm(FPSItem fpsItem)
 {
     FPSListBinder.CloseProblemForm(fpsItem);
 }
コード例 #13
0
ファイル: EditForm.cs プロジェクト: ii0/EasyFPSViewer
 public EditForm(FPSItem fpsItem) : this()
 {
     this.Text = this.Text + " - " + fpsItem.Title;
     _fpsItem  = fpsItem;
 }