Beispiel #1
0
        private void HandleSolutionOpened()
        {
            _scriptExecutor.Reset();

            // Solution opened event is raised on the UI thread
            // Go off the UI thread before calling likely expensive call of ExecuteInitScriptsAsync
            // Also, it uses semaphores, do not call it from the UI thread
            Task.Run(async() =>
            {
                UpdateWorkingDirectory();

                var retries = 0;

                while (retries < ExecuteInitScriptsRetriesLimit)
                {
                    if (await _solutionManager.IsAllProjectsNominatedAsync())
                    {
                        await ExecuteInitScriptsAsync();
                        break;
                    }

                    await Task.Delay(ExecuteInitScriptsRetryDelay);
                    retries++;
                }
            });
        }
Beispiel #2
0
        public object Execute(IScriptExecutor repl, object[] args)
        {
            Guard.AgainstNullArgument("repl", repl);

            repl.Reset();
            return null;
        }
Beispiel #3
0
        public object Execute(IScriptExecutor repl, object[] args)
        {
            Guard.AgainstNullArgument("repl", repl);

            repl.Reset();
            return(null);
        }
Beispiel #4
0
        public void Initialize(IConsole console)
        {
            NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                ActiveConsole = console;
                if (_initialized.HasValue)
                {
                    if (_initialized.Value &&
                        console.ShowDisclaimerHeader)
                    {
                        DisplayDisclaimerAndHelpText();
                    }
                }
                else
                {
                    try
                    {
                        var result = _runspaceManager.GetRunspace(console, _name);
                        Runspace   = result.Item1;
                        _nugetHost = result.Item2;

                        _initialized = true;

                        if (console.ShowDisclaimerHeader)
                        {
                            DisplayDisclaimerAndHelpText();
                        }

                        UpdateWorkingDirectory();
                        await ExecuteInitScriptsAsync();

                        // check if PMC console is actually opened, then only hook to solution load/close events.
                        if (console is IWpfConsole)
                        {
                            // Hook up solution events
                            _solutionManager.SolutionOpened += (o, e) =>
                            {
                                _scriptExecutor.Reset();

                                // Solution opened event is raised on the UI thread
                                // Go off the UI thread before calling likely expensive call of ExecuteInitScriptsAsync
                                // Also, it uses semaphores, do not call it from the UI thread
                                Task.Run(delegate
                                {
                                    UpdateWorkingDirectory();
                                    return(ExecuteInitScriptsAsync());
                                });
                            };
                            _solutionManager.SolutionClosed += (o, e) => UpdateWorkingDirectory();
                        }
                        _solutionManager.NuGetProjectAdded   += (o, e) => UpdateWorkingDirectoryAndAvailableProjects();
                        _solutionManager.NuGetProjectRenamed += (o, e) => UpdateWorkingDirectoryAndAvailableProjects();
                        _solutionManager.NuGetProjectUpdated += (o, e) => UpdateWorkingDirectoryAndAvailableProjects();
                        _solutionManager.NuGetProjectRemoved += (o, e) =>
                        {
                            UpdateWorkingDirectoryAndAvailableProjects();
                            // When the previous default project has been removed, _solutionManager.DefaultNuGetProjectName becomes null
                            if (_solutionManager.DefaultNuGetProjectName == null)
                            {
                                // Change default project to the first one in the collection
                                SetDefaultProjectIndex(0);
                            }
                        };
                        // Set available private data on Host
                        SetPrivateDataOnHost(false);
                    }
                    catch (Exception ex)
                    {
                        // catch all exception as we don't want it to crash VS
                        _initialized     = false;
                        IsCommandEnabled = false;
                        ReportError(ex);

                        ExceptionHelper.WriteErrorToActivityLog(ex);
                    }
                }
            });
        }