Exemplo n.º 1
0
 public ContestCdt(Contest contest)
 {
     c            = contest;
     CheckCommand = new IDelegateCommand((object obj) =>
     {
         MainWindow.Instance.Dispatcher.InvokeAsync(() =>
         {
             var cs                 = ContestsViewModel.Instance;
             cs.Status              = "checking for problems ...";
             CheckCommand.CanExec   = false;
             bool exception_accured = false;
             try
             {
                 List <Problem> probs = WebReader.ReadProblemsAll(c);
                 var col = ProblemsViewModel.Instance.Problems;
                 col.Clear();
                 for (int i = 0; i < probs.Count; ++i)
                 {
                     col.Add(new ProblemCdt(probs[i], c));
                 }
             }
             catch (Exception e)
             {
                 cs.Status = e.Message;
             }
             CheckCommand.CanExec = true;
             if (!exception_accured)
             {
                 cs.Status = "checking problems finished :)";
                 ProblemsViewModel.Instance.Status = "problems for " + c.Name;
             }
         });
     });
 }
Exemplo n.º 2
0
 public ContestsViewModel()
 {
     Instance     = this;
     Contests     = new ObservableCollection <ContestCdt>();
     CheckCommand = new IDelegateCommand((obj) =>
     {
         MainWindow.Instance.Dispatcher.InvokeAsync(() =>
         {
             Status                 = "checking contests ...";
             CheckBtnContent        = "checking ...";
             bool exception_occured = false;
             try
             {
                 CheckCommand.CanExec = false;
                 var contests         = WebReader.ReadContestsAll("http://codeforces.com/contests");
                 var collection       = ContestsViewModel.Instance.Contests;
                 collection.Clear();
                 for (int i = 0; i < contests.Count; ++i)
                 {
                     collection.Add(new ContestCdt(contests[i]));
                 }
             }
             catch (Exception e)
             {
                 Status            = e.Message;
                 exception_occured = true;
             }
             if (!exception_occured)
             {
                 Status = "checking contests finished :)";
             }
             CheckBtnContent      = "check !";
             CheckCommand.CanExec = true;
         });
     });
 }
Exemplo n.º 3
0
 public CodeTemplateViewModel()
 {
     ChangeCommand = new IDelegateCommand((obj) =>
     {
         bool exception_auccered = false;
         try
         {
             if (!Directory.Exists(path))
             {
                 Directory.CreateDirectory(path);
             }
             if (!File.Exists(template))
             {
                 File.Create(template).Close();
             }
             System.Diagnostics.Process.Start(template);
         }
         catch (Exception e)
         {
             Status             = e.Message;
             exception_auccered = true;
         }
         if (!exception_auccered)
         {
             Status = "edit and save this file !";
         }
     });
     DeleteCommand = new IDelegateCommand((obj) =>
     {
         if (File.Exists(template))
         {
             try
             {
                 File.Delete(template);
                 string msg = "default code template is back !";
                 if (Status.Contains(msg))
                 {
                     Status = Status + "!";
                 }
                 else
                 {
                     Status = msg;
                 }
             }
             catch (Exception e)
             {
                 Status = e.Message;
             }
         }
         else
         {
             string msg = "you have not set a code template !";
             if (Status.Contains(msg))
             {
                 Status = Status + "!";
             }
             else
             {
                 Status = msg;
             }
         }
     });
 }
Exemplo n.º 4
0
        public ProblemCdt(Problem problem, Contest contest)
        {
            p = problem;
            c = contest;

            GenerateCommand = new IDelegateCommand((obj) =>
            {
                //var app = Connect.applicationObject;
                var ps = ProblemsViewModel.Instance;
                //var proj = app.GetActiveProject();
                //if (proj == null)
                //{
                //    string msg = "first open a project please !";
                //    if (ps.Status.Contains(msg))
                //        ps.Status = ps.Status + "!";
                //    else
                //        ps.Status = msg;
                //    return;
                //}
                string folder = Database.Instance.WorkingDirectory;
                folder        = System.IO.Path.Combine(folder, c.Name.SafePath());
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                //foreach (ProjectItem pi in proj.ProjectItems)
                //    if (pi.Name == p.Name.SafePath())
                //        pi.Remove();


                string cpp = System.IO.Path.Combine(folder, p.Name.SafePath() + extension);
                if (!File.Exists(cpp) || MessageBox.Show("Overwrite File?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    StreamWriter sw = new StreamWriter(cpp, false);
                    WriteTemplate(sw);
                    sw.Close();
                }

                //proj.ProjectItems.AddFromFile(cpp).Open();
            });

            ShowInBrowser = new IDelegateCommand((obj) =>
            {
                bool exception_accured = false;
                string browser         = string.Empty;
                try
                {
                    browser = "chrome";
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("chrome.exe", c.Url + "/problem/" + p.Name.First()));
                }
                catch (Exception e)
                {
                    ProblemsViewModel.Instance.Status = e.Message;
                    try
                    {
                        browser = "ie";
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("explorer.exe", c.Url + "/problem/" + p.Name.First()));
                    }
                    catch (Exception e2)
                    {
                        ProblemsViewModel.Instance.Status = e2.Message;
                        exception_accured = true;
                    }
                }
                if (!exception_accured)
                {
                    ProblemsViewModel.Instance.Status = p.Name + " launched in " + browser + " .";
                }
            });


            TestCommand = new IDelegateCommand((obj) =>
            {
                try
                {
                    string folder = Database.Instance.WorkingDirectory;
                    folder        = System.IO.Path.Combine(folder, c.Name.SafePath());
                    string exe    = System.IO.Path.Combine(folder, p.Name.SafePath() + ".exe");
                    string cpp    = System.IO.Path.Combine(folder, p.Name.SafePath() + extension);

                    bool run = true;
                    {
                        string cmdarg = $"/C g++.exe -Wl,--stack=268435456 -O2 -std=c++17 -o \"{exe}\" \"{cpp}\"";
                        var psi       = new System.Diagnostics.ProcessStartInfo("cmd", cmdarg);
                        psi.RedirectStandardOutput = true;
                        psi.RedirectStandardError  = true;
                        psi.UseShellExecute        = false;
                        var proc = System.Diagnostics.Process.Start(psi);
                        proc.WaitForExit();
                        var compilelog  = proc.StandardOutput.ReadToEnd().Replace(folder, ""); // remove useless information
                        var compilelog2 = proc.StandardError.ReadToEnd().Replace(folder, "");
                        if (compilelog != string.Empty || compilelog2 != string.Empty)
                        {
                            run = MessageBox.Show(compilelog + "\r\n" + compilelog2 + "\r\n Would you like to try and run anyway?", "Compile Log", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.No;
                        }
                    }
                    if (run)
                    {
                        var psi = new System.Diagnostics.ProcessStartInfo("cmd", $"/C \"{exe}\" & pause");
                        psi.WorkingDirectory = folder;
                        System.Diagnostics.Process.Start(psi);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Exception");
                }
            });
        }