public ContestCdt(Contest contest)
 {
     c            = contest;
     CheckCommand = new IDelegateCommand((object obj) =>
     {
         Menu.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;
             }
         });
     });
 }
 public ContestsViewModel()
 {
     Instance     = this;
     Contests     = new ObservableCollection <ContestCdt>();
     CheckCommand = new IDelegateCommand((obj) =>
     {
         Menu.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;
         });
     });
 }
 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;
             }
         }
     });
 }
        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 = System.IO.Path.GetDirectoryName(proj.FullName);
                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() + ".cpp");
                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 + " .";
                }
            });
        }