Example #1
0
        private void ReAttachCommandClicked(object sender, EventArgs e)
        {
            var command = sender as OleMenuCommand;

            if (command == null)
            {
                ReAttachUtils.ShowError("ReAttach failed.", "Click was sent from non-ole command.");
                return;
            }

            var index             = command.CommandID.ID - ReAttachConstants.ReAttachCommandId;
            var unAttachedTargets = _history.GetUnAttached();
            var target            = index < unAttachedTargets.Length ? unAttachedTargets[index] : null;

            if (target == null)
            {
                return;
            }

            if (_options.BuildBeforeReAttach)
            {
                TryBuildSolution();
            }

            if (!EnsureDebuggerService())
            {
                ReAttachUtils.ShowError("ReAttach failed.", "Unable to obtain ref to debugger service.");
                return;
            }

            var result = _debugger.ReAttach(target);

            if (result == ReAttachResult.NotStarted)
            {
                var dialog = new WaitingDialog(_debugger, target);
                dialog.ShowModal();
                result = dialog.Result;
            }

            switch (result)
            {
            case ReAttachResult.Success:
                break;

            case ReAttachResult.ElevationRequired:
                ReAttachUtils.ShowElevationDialog();
                break;

            case ReAttachResult.NotStarted:
                ReAttachUtils.ShowError("ReAttach failed.", "Process not started.");
                break;

            case ReAttachResult.Cancelled:
                break;

            case ReAttachResult.Failed:
                ReAttachUtils.ShowError("ReAttach failed.", "Failed reattaching to process.");
                break;
            }
        }
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            ReAttachUtils.SetUp(this);
            _history = new ReAttachHistory(this);

            AddService(typeof(ReAttachDebugger), CreateReAttachDebuggerAsync);
            AddService(typeof(ReAttachUi), CreateReAttachUiAsync);

            // This might be questionable, but time is short and initialization needed.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            _ = await GetServiceAsync(typeof(ReAttachDebugger));

            var ui = (await GetServiceAsync(typeof(ReAttachUi))) as ReAttachUi;

            ui.Update();
        }
Example #3
0
 private void TryBuildSolution()
 {
     ThreadHelper.JoinableTaskFactory.Run(async() =>
     {
         await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
         var dte = await _package.GetServiceAsync(typeof(SDTE)) as DTE2;
         if (dte == null)
         {
             ReAttachUtils.ShowError("ReAttach failed", "Unable to rebuild solution before build.");
             return;
         }
         try
         {
             dte.Solution.SolutionBuild.Build(true);
         }
         catch (Exception) { }
     });
 }
Example #4
0
        public async Task InitializeAsync(ReAttachPackage package, ReAttachHistory history, CancellationToken cancellationToken)
        {
            _package = package;
            _history = history;

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            _menu = (await package.GetServiceAsync(typeof(IMenuCommandService))) as IMenuCommandService;
            if (_menu == null)
            {
                ReAttachUtils.ShowStartupError("Unable to obtain reference to menu service.");
                return;
            }

            _options = new ReAttachOptions(package);

            for (var i = 0; i < ReAttachConstants.ReAttachHistorySize; i++)
            {
                var commandId = new CommandID(ReAttachConstants.ReAttachPackageCmdSet, ReAttachConstants.ReAttachCommandId + i);
                var command   = new OleMenuCommand(ReAttachCommandClicked, commandId);
                _menu.AddCommand(command);

                if (i > 0) // Hide all items except first one initially.
                {
                    command.Visible = false;
                }

                _commands[i] = command;
            }

            var buildToggleCommandId = new CommandID(ReAttachConstants.ReAttachPackageCmdSet,
                                                     ReAttachConstants.BuildBeforeReAttachCommandId);
            var buildCommand = new OleMenuCommand(ReAttachToggleBuildClicked, buildToggleCommandId);

            buildCommand.Visible = true;
            buildCommand.Checked = _options.BuildBeforeReAttach;
            _menu.AddCommand(buildCommand);
            _buildToggleCommand = buildCommand;
        }