コード例 #1
0
        protected override void QueryStatus()
        {
            Project project;

            this.Visible =
                ProjectHelper.TryGetActiveProject(this.Package, out project) &&
                ProjectHelper.IsObjectModelSupported(project);
            this.Enabled =
                this.Visible &&
                !VsShellUtilities.IsSolutionBuilding(this.Package);
        }
コード例 #2
0
        internal void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand command = sender as OleMenuCommand;

            if (command != null)
            {
                //System.Diagnostics.Trace.WriteLine("OnBeforeQueryStatus: " + command.ToString());
                command.Enabled = (_commandRunner.IsBusy != 1 && _applicationObject.Solution.IsOpen && !VsShellUtilities.IsSolutionBuilding(_pkg));
            }
        }
コード例 #3
0
 private bool InterceptCommand()
 {
     return(Options.Instance.DeleteOuputArtifactsOnClean &&
            !VsShellUtilities.IsSolutionBuilding(_serviceProvider));
 }
コード例 #4
0
        protected override void Execute()
        {
            if (VsShellUtilities.IsSolutionBuilding(this.Package))
            {
                return;
            }

            try
            {
                UIThreadInvoker.Invoke( // Use it to force the execution in the UI thread
                    delegate
                {
                    var EnvVars = new Dictionary <string, string>();

                    Project project;
                    string projectGuid;
                    if (!ProjectHelper.TryGetActiveProject(this.Package, out project) || !ProjectHelper.TryGetProjectGuid(this.Package, project, out projectGuid))
                    {
                        MessageBox.Show(
                            "Code Contracts could not detect the current project",
                            "Code Contracts: Could not detect the current project",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Exclamation);
                        return;
                    }

                    EnvVars["CodeContractsTargetProjectGuid"] = projectGuid;

                    string name;
                    if (ContextHelper.TryGetSelectedMemberFullNameMangled(this.Package, out name))
                    {
                        EnvVars["CodeContractsTargetMember"] = name;
                    }
                    else if (ContextHelper.TryGetSelectedTypeFullNameMangled(this.Package, out name))
                    {
                        EnvVars["CodeContractsTargetType"] = name;
                    }
                    else if (ContextHelper.TryGetSelectedNamespaceFullNameMangled(this.Package, out name))
                    {
                        EnvVars["CodeContractsTargetNamespace"] = name;
                    }
                    else
                    {
                        MessageBox.Show(
                            "Code Contracts could not detect the selected type, member or namespace. " +
                            "Please make sure that the editor caret is inside the member to test.",
                            "Code Contracts: Could not detect the code context",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Exclamation);
                        return;
                    }

                    ThreadPool.QueueUserWorkItem(o =>
                    {
                        try
                        {
                            foreach (var p in EnvVars)
                            {
                                Environment.SetEnvironmentVariable(p.Key, p.Value);
                            }

                            ProjectHelper.TryBuildProject(this.Package, project);
                        }
                        catch (Exception e)
                        {
                            ContractsVsPackage.ReportException(e);
                        }
                        finally
                        {
                            foreach (var p in EnvVars)
                            {
                                Environment.SetEnvironmentVariable(p.Key, null);
                            }
                        }
                    });
                });
            }
            catch (Exception ex)
            {
                ContractsVsPackage.ReportException(ex);
            }
        }