Beispiel #1
0
        public void OpenOutputFile(string file)
        {
            long siz = LocalDirectory.GetFileSize(file);

            if (siz <= 1)
            {
                return;
            }

            if (OpenedOutput != file)
            {
                outputTextBox.Clear();
                progOutputTextBox.Clear();
            }

            //do not open very large files
            if (siz > MaxFileSIZ)
            {
                _ShowMaxExceedMessage(outputTextBox);
            }
            else
            {
                outputTextBox.Text = File.ReadAllText(file);
            }

            progOutputTextBox.Text = outputTextBox.Text;
        }
Beispiel #2
0
        //
        // File Open
        //
        public void OpenCodeFile(string file)
        {
            long siz = LocalDirectory.GetFileSize(file);

            if (siz <= 1)
            {
                return;
            }

            //do not open very large files
            if (siz > MaxFileSIZ)
            {
                _ShowMaxExceedMessage(codeTextBox);
            }
            else
            {
                if (file.CompareTo(codeTextBox.Tag) == 0)
                {
                    codeTextBox.Text = File.ReadAllText(file);
                }
                else
                {
                    codeTextBox.Clear();
                    codeTextBox.Text = File.ReadAllText(file);
                    codeTextBox.ClearUndo();
                    codeTextBox.Tag = file;
                }
            }
        }
Beispiel #3
0
        private void DownloadFinished(DownloadTask task)
        {
            if (task.Error != null)
            {
                Logger.Add(task.Error.Message, "ProblemViewer | DownloadFinished()");
                return;
            }

            /*
             * this.BeginInvoke((MethodInvoker)delegate
             * {
             *  problemWebBrowser.Refresh();
             * });
             */

            bool finish = false;
            long pnum   = (long)task.Token;

            if (current == null || current.pnum != pnum)
            {
                finish = true;
            }

            if (!finish) //if no error occured
            {
                string ext = Path.GetExtension(task.FileName);
                if (ext == ".pdf")
                {
                    if (LocalDirectory.GetFileSize(task.FileName) > 200)
                    {
                        setPdfFile(task.FileName);
                        finish = true;
                    }
                }

                /*
                 * else if (ext == ".html")
                 * {
                 *  if (LocalDirectory.GetFileSize(task.FileName) > 100)
                 *  {
                 *      problemWebBrowser.Navigate(task.FileName);
                 *      int cnt = DownloadContents(pnum);
                 *      if (cnt == 0) finish = true;
                 *  };
                 *
                 * }
                 * else
                 * {
                 *  finish = true;
                 * }
                 */
            }

            if (finish)
            {
                reloadButton.Enabled = true;
            }
        }
Beispiel #4
0
        private void ShowCurrent()
        {
            if (current == null)
            {
                return;
            }

            //unload previous data first
            setPdfFile(null);
            problemWebBrowser.Navigate(string.Empty);

            //load meta info
            LoadTopBar();
            markButton.Checked = current.Marked;

            //check pdf and html description files
            string pdf       = LocalDirectory.GetProblemPdf(current.pnum);
            string html      = LocalDirectory.GetProblemHtml(current.pnum);
            bool   htmlAvail = LocalDirectory.GetFileSize(html) > 100;
            bool   pdfAvail  = LocalDirectory.GetFileSize(pdf) > 200;

            //show data
            if (htmlAvail && this.tabControl1.SelectedTab == htmlTab)
            {
                problemWebBrowser.Navigate(html);
            }
            else if (pdfAvail && this.tabControl1.SelectedTab == pdfTab)
            {
                setPdfFile(pdf);
            }
            else if (htmlAvail)
            {
                this.tabControl1.SelectedTab = htmlTab;
            }
            else if (pdfAvail)
            {
                this.tabControl1.SelectedTab = pdfTab;
            }

            //download if necessary
            if (!pdfAvail)
            {
                DownloadPdf(current.pnum);
            }
            if (!htmlAvail)
            {
                DownloadHtml(current.pnum);
            }
        }
Beispiel #5
0
        private void pdfToolButton_Click(object sender, EventArgs e)
        {
            if (current == null)
            {
                MessageBox.Show("Select a problem first.");
                return;
            }
            string pdf = LocalDirectory.GetProblemPdf(current.pnum);

            if (LocalDirectory.GetFileSize(pdf) > 200)
            {
                System.Diagnostics.Process.Start(pdf);
            }
            else
            {
                DownloadPdf(current.pnum);
            }
        }
Beispiel #6
0
 private void DownloadHtml(long pnum)
 {
     try
     {
         string format = "http://uva.onlinejudge.org/external/{0}/{1}.html"; // 0 = vol; 1 = pnum
         string url    = string.Format(format, pnum / 100, pnum);
         string file   = LocalDirectory.GetProblemHtml(pnum);
         if (!reloadButton.Enabled || LocalDirectory.GetFileSize(file) < 100)
         {
             Downloader.DownloadFileAsync(url, file, pnum,
                                          Internet.Priority.Normal, ProgressChanged, DownloadFinished);
         }
     }
     catch (Exception ex)
     {
         Logger.Add(ex.Message, "Problem Viewer | DownloadHtml()");
     }
 }
Beispiel #7
0
        private void ShowCurrent()
        {
            if (current == null)
            {
                return;
            }

            LoadTopBar();
            markButton.Checked      = current.marked;
            tabControl1.SelectedTab = descriptionTab;

            string path = LocalDirectory.GetProblemHtml(current.pnum);

            if (LocalDirectory.GetFileSize(path) < 100)
            {
                problemWebBrowser.Navigate("about:tabs");
                DownloadHtml(current.pnum);
            }
            else
            {
                problemWebBrowser.Navigate(path);
                DownloadContents(current.pnum);
            }
        }
Beispiel #8
0
        public void LoadDeepSearch(object state)
        {
            if (LocalDatabase.problemList == null)
            {
                return;
            }

            _InDeepSearch = true;

            //clear data
            _deepSearchRes.Clear();
            _DeepSearchProgress = 0;

            //set data
            this.BeginInvoke((MethodInvoker) delegate
            {
                allProbButton.Checked            = false;
                markedButton.Checked             = false;
                plistLabel.Text                  = "Deep Search Result";
                problemListView.AdditionalFilter = null;

                searchBox1.search_text.ReadOnly          = true;
                cancelDeepSearchButton.Visible           = true;
                problemViewSplitContainer.Panel1.Enabled = false;

                _SetObjects(_deepSearchRes);
                problemListView.Sort(priorityProb, SortOrder.Descending);
            });

            //search string
            string src = (string)state;

            if (!src.StartsWith("*"))
            {
                src = "\\b" + src;
            }
            if (!src.EndsWith("*"))
            {
                src += "\\b";
            }
            var regex = new System.Text.RegularExpressions.Regex(src,
                                                                 System.Text.RegularExpressions.RegexOptions.Compiled |
                                                                 System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //search
            foreach (ProblemInfo prob in LocalDatabase.problemList)
            {
                if (_CancelSearch)
                {
                    break;
                }
                prob.Priority = 0;

                //search in problem data
                prob.Priority += regex.Matches(prob.ToString()).Count;

                //search in problem description
                try
                {
                    string file = LocalDirectory.GetProblemHtml(prob.pnum);
                    if (LocalDirectory.GetFileSize(file) > 100)
                    {
                        var hdoc = new HtmlAgilityPack.HtmlDocument();
                        hdoc.Load(file);
                        string dat = hdoc.DocumentNode.Element("body").InnerText;
                        //string dat = System.IO.File.ReadAllText(file);
                        prob.Priority += regex.Matches(dat).Count;
                    }
                }
                catch { }

                //add to list
                if (prob.Priority > 0)
                {
                    _deepSearchRes.Add(prob);
                }
                _DeepSearchProgress++;
            }

            //complete
            _InDeepSearch = false;
            this.BeginInvoke((MethodInvoker) delegate
            {
                _SetObjects(_deepSearchRes);

                searchBox1.search_text.ReadOnly          = false;
                cancelDeepSearchButton.Visible           = false;
                problemViewSplitContainer.Panel1.Enabled = true;

                if (_CancelSearch) //if canceled
                {
                    ClearSearch();
                }
            });
        }
Beispiel #9
0
        public static bool ParseInputOutput(long pnum, string inpfile, string outfile, bool replace = false)
        {
            try
            {
                //get HTML
                string file = LocalDirectory.GetProblemHtml(pnum);
                if (LocalDirectory.GetFileSize(file) < 100)
                {
                    return(false);
                }

                int    start, stop = 0, indx;
                string html, low, data;
                var    xdoc  = new System.Xml.XmlDocument();
                char[] white = { ' ', '\r', '\n' };

                html = File.ReadAllText(file);
                low  = html.ToLower();

                bool ok = false;

                //get input
                while (true)
                {
                    if (LocalDirectory.GetFileSize(inpfile) > 2 && !replace)
                    {
                        break;
                    }
                    indx = low.IndexOf("sample input");
                    if (indx < 0)
                    {
                        break;
                    }
                    start = low.IndexOf("<pre>", indx);
                    if (start < 0)
                    {
                        break;
                    }
                    stop = low.IndexOf("</pre>", start);
                    if (stop <= start)
                    {
                        break;
                    }

                    xdoc.LoadXml(html.Substring(start, stop - start + 6));
                    data = xdoc.DocumentElement.InnerText.TrimStart(white);
                    data = data.Replace("\n\r", "\n");
                    File.WriteAllText(inpfile, data);
                    ok = true;
                    break;
                }

                //get output
                while (true)
                {
                    if (LocalDirectory.GetFileSize(outfile) > 2 && !replace)
                    {
                        break;
                    }
                    indx = low.IndexOf("sample output", stop);
                    if (indx < 0)
                    {
                        break;
                    }
                    start = low.IndexOf("<pre>", indx);
                    if (start < 0)
                    {
                        break;
                    }
                    stop = low.IndexOf("</pre>", start);
                    if (stop <= start)
                    {
                        break;
                    }

                    xdoc.LoadXml(html.Substring(start, stop - start + 6));
                    data = xdoc.DocumentElement.InnerText.TrimStart(white);
                    data = data.Replace("\n\r", "\n");
                    if (!data.EndsWith("\n"))
                    {
                        data += "\n";
                    }
                    File.WriteAllText(outfile, data);
                    ok = true;
                    break;
                }

                return(ok);
            }
            catch (Exception ex)
            {
                Logger.Add("Failed to write Input/Output data. Error: " + ex.Message, "CODES| ParseInputOutput()");
                return(false);
            }
        }