예제 #1
0
        internal VsMachineWideSettings(DTE dte)
        {
            var baseDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

            _settings = new Lazy <IEnumerable <Settings> >(
                () =>
            {
                return(NuGet.Configuration.Settings.LoadMachineWideSettings(
                           baseDirectory,
                           "VisualStudio",
                           dte.Version,
                           VSVersionHelper.GetSKU()));
            });
        }
        internal VsMachineWideSettings(DTE dte)
        {
            var baseDirectory = Common.NuGetEnvironment.GetFolderPath(Common.NuGetFolderPath.MachineWideConfigDirectory);

            _settings = new AsyncLazy <IEnumerable <Configuration.Settings> >(async() =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                return(Configuration.Settings.LoadMachineWideSettings(
                           baseDirectory,
                           "VisualStudio",
                           dte.Version,
                           VSVersionHelper.GetSKU()));
            }, ThreadHelper.JoinableTaskFactory);
        }
예제 #3
0
        public VSSolutionManager()
        {
            _dte                = ServiceLocator.GetInstance <DTE>();
            _vsSolution         = ServiceLocator.GetGlobalService <SVsSolution, IVsSolution>();
            _vsMonitorSelection = ServiceLocator.GetGlobalService <SVsShellMonitorSelection, IVsMonitorSelection>();

            // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events.
            _solutionEvents = _dte.Events.SolutionEvents;

            // can be null in unit tests
            if (_vsMonitorSelection != null)
            {
                Guid solutionLoadedGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid;
                _vsMonitorSelection.GetCmdUIContextCookie(ref solutionLoadedGuid, out _solutionLoadedUICookie);

                uint cookie;
                int  hr = _vsMonitorSelection.AdviseSelectionEvents(this, out cookie);
                ErrorHandler.ThrowOnFailure(hr);
            }

            // Allow this constructor to be invoked from either the UI or a worker thread. This JTF call should be
            // cheap (minimal context switch cost) when we are already on the UI thread.
            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                UserAgent.SetUserAgentString(
                    new UserAgentStringBuilder().WithVisualStudioSKU(VSVersionHelper.GetFullVsVersionString()));
            });

            _solutionEvents.BeforeClosing  += OnBeforeClosing;
            _solutionEvents.AfterClosing   += OnAfterClosing;
            _solutionEvents.ProjectAdded   += OnEnvDTEProjectAdded;
            _solutionEvents.ProjectRemoved += OnEnvDTEProjectRemoved;
            _solutionEvents.ProjectRenamed += OnEnvDTEProjectRenamed;

            var vSStd97CmdIDGUID = VSConstants.GUID_VSStandardCommandSet97.ToString("B");
            var solutionSaveID   = (int)VSConstants.VSStd97CmdID.SaveSolution;
            var solutionSaveAsID = (int)VSConstants.VSStd97CmdID.SaveSolutionAs;

            _solutionSaveEvent   = _dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveID];
            _solutionSaveAsEvent = _dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveAsID];

            _solutionSaveEvent.BeforeExecute   += SolutionSaveAs_BeforeExecute;
            _solutionSaveEvent.AfterExecute    += SolutionSaveAs_AfterExecute;
            _solutionSaveAsEvent.BeforeExecute += SolutionSaveAs_BeforeExecute;
            _solutionSaveAsEvent.AfterExecute  += SolutionSaveAs_AfterExecute;
        }
예제 #4
0
        public VSSolutionManager()
        {
            _dte                = ServiceLocator.GetInstance <DTE>();
            _vsSolution         = ServiceLocator.GetGlobalService <SVsSolution, IVsSolution>();
            _vsMonitorSelection = ServiceLocator.GetGlobalService <SVsShellMonitorSelection, IVsMonitorSelection>();

            // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events.
            _solutionEvents = _dte.Events.SolutionEvents;

            // can be null in unit tests
            if (_vsMonitorSelection != null)
            {
                Guid solutionLoadedGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid;
                _vsMonitorSelection.GetCmdUIContextCookie(ref solutionLoadedGuid, out _solutionLoadedUICookie);

                uint cookie;
                int  hr = _vsMonitorSelection.AdviseSelectionEvents(this, out cookie);
                ErrorHandler.ThrowOnFailure(hr);
            }

            UserAgent.SetUserAgentString(
                new UserAgentStringBuilder().WithVisualStudioSKU(VSVersionHelper.GetFullVsVersionString()));

            _solutionEvents.BeforeClosing  += OnBeforeClosing;
            _solutionEvents.AfterClosing   += OnAfterClosing;
            _solutionEvents.ProjectAdded   += OnEnvDTEProjectAdded;
            _solutionEvents.ProjectRemoved += OnEnvDTEProjectRemoved;
            _solutionEvents.ProjectRenamed += OnEnvDTEProjectRenamed;

            var vSStd97CmdIDGUID = VSConstants.GUID_VSStandardCommandSet97.ToString("B");
            var solutionSaveID   = (int)VSConstants.VSStd97CmdID.SaveSolution;
            var solutionSaveAsID = (int)VSConstants.VSStd97CmdID.SaveSolutionAs;

            _solutionSaveEvent   = _dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveID];
            _solutionSaveAsEvent = _dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveAsID];

            _solutionSaveEvent.BeforeExecute   += SolutionSaveAs_BeforeExecute;
            _solutionSaveEvent.AfterExecute    += SolutionSaveAs_AfterExecute;
            _solutionSaveAsEvent.BeforeExecute += SolutionSaveAs_BeforeExecute;
            _solutionSaveAsEvent.AfterExecute  += SolutionSaveAs_AfterExecute;
        }