internal void StartupProject_Changed(IVsHierarchy newStartupProjectHierarchy)
        {
            if (newStartupProjectHierarchy == null)
            {
                return;
            }

            var projectName    = SolutionUtilities.GetProject(newStartupProjectHierarchy).Name;
            var currentProblem = (string)cbProblems.SelectedItem;

            if (currentProblem == null || currentProblem.Equals(projectName, StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            if (!IsCaideProblem(projectName))
            {
                // The project doesn't correspond to a problem
                return;
            }

            if (null == CaideExe.Run("checkout", projectName))
            {
                return;
            }
        }
        private void btnParseContest_Click(object sender, RoutedEventArgs e)
        {
            string url = PromptDialog.Prompt("Enter contest URL: ", "Parse contest");

            if (url == null)
            {
                return;
            }
            CaideExe.Run(new[] { "contest", url }, loud: Loudness.LOUD);
        }
 private void cbProgrammingLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!SkipLanguageChangedEvent)
     {
         var language = (string)cbProgrammingLanguage.SelectedItem;
         if (null == CaideExe.Run(new[] { "lang", language }, loud: Loudness.LOUD))
         {
             var previousLanguage = (string)e.RemovedItems[0];
             SetCurrentLanguage(previousLanguage);
             return;
         }
         UpdateCurrentProject();
     }
 }
        private void btnAddNewProblem_Click(object sender, RoutedEventArgs e)
        {
            var problemUrl = PromptDialog.Prompt("Input problem URL or name:", "New problem");

            if (problemUrl == null)
            {
                return;
            }

            if (null == CaideExe.Run(new[] { "problem", problemUrl }, loud: Loudness.LOUD))
            {
                return;
            }
        }
        public void Solution_Opened()
        {
            lock (ToDoAfterAllProjectsLoaded)
            {
                IsProjectsLoadingInProgress = true;
                ToDoAfterAllProjectsLoaded.Clear();
            }

            bool isCaideDirectory = SolutionUtilities.IsCaideSolution();

            EnableAll(isCaideDirectory);

            if (isCaideDirectory)
            {
                var windowFrame = (IVsWindowFrame)mainToolWindow.Frame;
                windowFrame.Show();
                ReloadProblemList();

                if (CHelperServer != null)
                {
                    CHelperServer.Stop();
                    CHelperServer = null;
                }

                string enableChelperServerStr =
                    CaideExe.Run(new[] { "getopt", "vscaide", "enable_http_server" }, loud: Loudness.QUIET) ?? "1";
                if (new[] { "yes", "1", "true" }.Contains(enableChelperServerStr.ToLowerInvariant().Trim()))
                {
                    CHelperServer = new CHelperServer();
                }
                else
                {
                    Logger.LogMessage("Disabling CHelper HTTP server due to a setting in caide.ini");
                }


                EnableFsWatcher(false);

                string path = Path.Combine(SolutionUtilities.GetSolutionDir(), ".caide");
                fsWatcher = new FileSystemWatcher(path, "config")
                {
                    EnableRaisingEvents   = false,
                    IncludeSubdirectories = false,
                    NotifyFilter          = NotifyFilters.LastWrite,
                };
                fsWatcher.Changed            += fsWatcher_Changed;
                fsWatcher.EnableRaisingEvents = true;
                AfterProjectsLoaded(() => projectManager.CreateCppLibProject());
            }
        }
        private void UpdateCurrentProject()
        {
            string selectedProblem = cbProblems.SelectedItem as string;

            if (string.IsNullOrEmpty(selectedProblem))
            {
                return;
            }

            try
            {
                if (fsWatcher != null)
                {
                    fsWatcher.EnableRaisingEvents = false;
                }
                if (null == CaideExe.Run("checkout", selectedProblem))
                {
                    return;
                }

                string stdout = CaideExe.Run("probgetstate", selectedProblem, "problem", "language");
                if (null == stdout)
                {
                    return;
                }

                string language = stdout.Trim();
                SetCurrentLanguage(language);

                string[] cppLanguages = new[] { "simplecpp", "cpp", "c++" };
                string[] csLanguages  = new[] { "c#", "csharp" };
                if (cppLanguages.Contains(language))
                {
                    AfterProjectsLoaded(() => projectManager.CreateAndActivateCppProject(selectedProblem, language));
                }
                else if (csLanguages.Contains(language))
                {
                    AfterProjectsLoaded(() => projectManager.CreateAndActivateCSharpProject(selectedProblem));
                }
            }
            finally
            {
                if (fsWatcher != null)
                {
                    fsWatcher.EnableRaisingEvents = true;
                }
            }
        }
        private void ReloadProblemList()
        {
            Logger.Trace("ReloadProblemList");
            try
            {
                EnableFsWatcher(false);
                string stdout         = CaideExe.Run("getstate", "core", "problem");
                string currentProblem = stdout == null ? null : stdout.Trim();

                var problemNames = new List <string>();

                if (string.Empty == currentProblem)
                {
                    problemNames.Add("");
                }

                foreach (var subdir in Directory.EnumerateDirectories(SolutionUtilities.GetSolutionDir()))
                {
                    if (Directory.Exists(Path.Combine(subdir, ".caideproblem")) &&
                        File.Exists(Path.Combine(subdir, "problem.ini")))
                    {
                        problemNames.Add(Path.GetFileName(subdir.TrimEnd(Path.DirectorySeparatorChar)));
                    }
                }

                problemNames.Sort(StringComparer.CurrentCultureIgnoreCase);
                cbProblems.Items.Clear();
                foreach (var problem in problemNames)
                {
                    cbProblems.Items.Add(problem);
                }

                if (currentProblem == null)
                {
                    return;
                }

                cbProblems.SelectedItem = currentProblem;
            }
            finally
            {
                EnableFsWatcher(true);
            }
        }
        private void btnCreateSolution_Click(object sender, RoutedEventArgs e)
        {
            if (SolutionUtilities.IsCaideSolution())
            {
                ReloadProblemList();
            }
            else
            {
                string solutionDir = SolutionUtilities.GetSolutionDir();
                bool   newSolution = solutionDir == null;
                if (newSolution)
                {
                    var folderBrowserDialog = new FolderBrowserDialog
                    {
                        Description         = "Select solution folder",
                        ShowNewFolderButton = true,
                        RootFolder          = Environment.SpecialFolder.Desktop,
                        SelectedPath        = recentFolder,
                    };
                    var result = folderBrowserDialog.ShowDialog();
                    if (result != DialogResult.OK)
                    {
                        return;
                    }
                    solutionDir = recentFolder = folderBrowserDialog.SelectedPath;
                }

                if (null == CaideExe.Run(new[] { "init" }, loud: Loudness.LOUD, solutionDir: solutionDir))
                {
                    return;
                }

                if (newSolution)
                {
                    ErrorHandler.ThrowOnFailure(
                        Services.Solution.CreateSolution(solutionDir, "VsCaide", 0)
                        );
                    File.Copy(Path.Combine(solutionDir, "templates", "vs_common.props"),
                              Path.Combine(solutionDir, "vs_common.props"), overwrite: true);
                    SolutionUtilities.SaveSolution();
                }
            }
        }
        private void btnArchive_Click(object sender, RoutedEventArgs e)
        {
            var currentProblem = (string)cbProblems.SelectedItem;

            if (string.IsNullOrEmpty(currentProblem))
            {
                return;
            }
            var solution = Services.DTE.Solution;
            var project  = solution.Projects.OfType <Project>().SingleOrDefault(p => p.Name == currentProblem);

            if (project == null)
            {
                // A problem not tracked by VsCaide
                CaideExe.Run(new[] { "archive", currentProblem }, loud: Loudness.LOUD);
            }
            else
            {
                solution.Remove(project);
                // The problem will be archived on Project_Removed event
            }
        }
Exemplo n.º 10
0
        internal void Project_Removed(IVsHierarchy projectHier)
        {
            Project project = SolutionUtilities.TryGetProject(projectHier);

            if (project == null)
            {
                return;
            }
            var projectName = project.Name;

            if (IsCaideProblem(projectName))
            {
                // Try to mitigate a mysterious error 'Unsatisified (sic!) constraints: folder not empty'.
                System.Threading.Thread.Sleep(500);
                CaideExe.Run("archive", projectName);
                string projectDirectory = Path.Combine(SolutionUtilities.GetSolutionDir(), projectName);
                if (Directory.Exists(projectDirectory))
                {
                    Directory.Delete(projectDirectory, recursive: true);
                }
                SolutionUtilities.SaveSolution();
            }
        }