コード例 #1
0
        public MockVs()
        {
            TextManager = new MockVsTextManager(this);
            Container   = CreateCompositionContainer();
            var serviceProvider = _serviceProvider = Container.GetExportedValue <MockVsServiceProvider>();

            UIShell      = new MockVsUIShell(this);
            _monSel      = new MockVsMonitorSelection(this);
            _uiHierarchy = new MockVsUIHierarchyWindow(this);
            _rdt         = new MockVsRunningDocumentTable(this);
            _dte         = new MockDTE(this);
            _serviceProvider.AddService(typeof(SVsTextManager), TextManager);
            _serviceProvider.AddService(typeof(SVsActivityLog), ActivityLog);
            _serviceProvider.AddService(typeof(SVsSettingsManager), SettingsManager);
            _serviceProvider.AddService(typeof(SLocalRegistry), LocalRegistry);
            _serviceProvider.AddService(typeof(SComponentModel), this);
            _serviceProvider.AddService(typeof(IVsDebugger), Debugger);
            _serviceProvider.AddService(typeof(SVsSolution), Solution);
            _serviceProvider.AddService(typeof(SVsRegisterProjectTypes), Solution);
            _serviceProvider.AddService(typeof(SVsCreateAggregateProject), Solution);
            _serviceProvider.AddService(typeof(SVsTrackProjectDocuments), TrackDocs);
            _serviceProvider.AddService(typeof(SVsShell), Shell);
            _serviceProvider.AddService(typeof(SOleComponentManager), _compManager);
            _serviceProvider.AddService(typeof(SVsProfferCommands), _proferredCommands);
            _serviceProvider.AddService(typeof(SVsOutputWindow), _outputWindow);
            _serviceProvider.AddService(typeof(SVsBuildManagerAccessor), _buildManager);
            _serviceProvider.AddService(typeof(SVsUIHierWinClipboardHelper), _hierClipHelper);
            _serviceProvider.AddService(typeof(IVsUIShell), UIShell);
            _serviceProvider.AddService(typeof(IVsMonitorSelection), _monSel);
            _serviceProvider.AddService(typeof(SVsQueryEditQuerySave), _queryEditSave);
            _serviceProvider.AddService(typeof(SVsRunningDocumentTable), _rdt);
            _serviceProvider.AddService(typeof(SVsUIShellOpenDocument), _shellOpenDoc);
            _serviceProvider.AddService(typeof(SVsSolutionBuildManager), _slnBuildMgr);
            _serviceProvider.AddService(typeof(EnvDTE.IVsExtensibility), _extensibility);
            _serviceProvider.AddService(typeof(EnvDTE.DTE), _dte);

            UIShell.AddToolWindow(new Guid(ToolWindowGuids80.SolutionExplorer), new MockToolWindow(_uiHierarchy));

            uint dummy;

            ErrorHandler.ThrowOnFailure(
                _monSel.AdviseSelectionEvents(
                    new SelectionEvents(this),
                    out dummy
                    )
                );

            _throwExceptionsOn = Thread.CurrentThread;

            using (var e = new AutoResetEvent(false))
            {
                UIThread      = new Thread(UIThreadWorker);
                UIThread.Name = "Mock UI Thread";
                UIThread.Start((object)e);
                // Wait for UI thread to start before returning. This ensures that
                // any packages we have are loaded and have published their services
                e.WaitOne();
            }
            ThrowPendingException();
        }
コード例 #2
0
ファイル: MockVs.cs プロジェクト: xyongy/PTVS
        private void UIThreadWorker(object evt)
        {
            Console.WriteLine($"Started UIThreadWorker on {Thread.CurrentThread.ManagedThreadId}");
            try {
                try {
                    SynchronizationContext.SetSynchronizationContext(new MockSyncContext(this));

                    TextManager = new MockVsTextManager(this);
                    Container   = CreateCompositionContainer();
                    var serviceProvider = _serviceProvider = Container.GetExportedValue <MockVsServiceProvider>();
                    UIShell      = new MockVsUIShell(this);
                    _monSel      = new MockVsMonitorSelection(this);
                    _uiHierarchy = new MockVsUIHierarchyWindow(this);
                    _rdt         = new MockVsRunningDocumentTable(this);
                    _dte         = new MockDTE(this);
                    _serviceProvider.AddService(typeof(SVsTextManager), TextManager);
                    _serviceProvider.AddService(typeof(SVsActivityLog), ActivityLog);
                    _serviceProvider.AddService(typeof(SVsSettingsManager), SettingsManager);
                    _serviceProvider.AddService(typeof(SLocalRegistry), LocalRegistry);
                    _serviceProvider.AddService(typeof(SComponentModel), this);
                    _serviceProvider.AddService(typeof(IVsDebugger), Debugger);
                    _serviceProvider.AddService(typeof(SVsSolution), Solution);
                    _serviceProvider.AddService(typeof(SVsRegisterProjectTypes), Solution);
                    _serviceProvider.AddService(typeof(SVsCreateAggregateProject), Solution);
                    _serviceProvider.AddService(typeof(SVsTrackProjectDocuments), TrackDocs);
                    _serviceProvider.AddService(typeof(SVsShell), Shell);
                    _serviceProvider.AddService(typeof(SOleComponentManager), _compManager);
                    _serviceProvider.AddService(typeof(SVsProfferCommands), _proferredCommands);
                    _serviceProvider.AddService(typeof(SVsOutputWindow), _outputWindow);
                    _serviceProvider.AddService(typeof(SVsBuildManagerAccessor), _buildManager);
                    _serviceProvider.AddService(typeof(SVsUIHierWinClipboardHelper), _hierClipHelper);
                    _serviceProvider.AddService(typeof(IVsUIShell), UIShell);
                    _serviceProvider.AddService(typeof(IVsMonitorSelection), _monSel);
                    _serviceProvider.AddService(typeof(SVsQueryEditQuerySave), _queryEditSave);
                    _serviceProvider.AddService(typeof(SVsRunningDocumentTable), _rdt);
                    _serviceProvider.AddService(typeof(SVsUIShellOpenDocument), _shellOpenDoc);
                    _serviceProvider.AddService(typeof(SVsSolutionBuildManager), _slnBuildMgr);
                    _serviceProvider.AddService(typeof(EnvDTE.IVsExtensibility), _extensibility);
                    _serviceProvider.AddService(typeof(EnvDTE.DTE), _dte);

                    Shell.SetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, true);

                    UIShell.AddToolWindow(new Guid(ToolWindowGuids80.SolutionExplorer), new MockToolWindow(_uiHierarchy));

                    ErrorHandler.ThrowOnFailure(
                        _monSel.AdviseSelectionEvents(
                            new SelectionEvents(this),
                            out _monSelCookie
                            )
                        );

                    foreach (var package in Container.GetExportedValues <IMockPackage>())
                    {
                        _loadedPackages.Add(package);
                        package.Initialize();
                    }
                } finally {
                    ((AutoResetEvent)evt).Set();
                }
                RunMessageLoop();
            } catch (Exception ex) {
                Trace.TraceError("Captured exception on mock UI thread: {0}", ex);
                _edi = ExceptionDispatchInfo.Capture(ex);
            }
        }
コード例 #3
0
        public MockVs()
        {
            TextManager = new MockVsTextManager(this);
            Container   = CreateCompositionContainer();
            var serviceProvider = _serviceProvider = Container.GetExportedValue <MockVsServiceProvider>();

            UIShell      = new MockVsUIShell(this);
            _monSel      = new MockVsMonitorSelection(this);
            _uiHierarchy = new MockVsUIHierarchyWindow(this);
            _rdt         = new MockVsRunningDocumentTable(this);
            _dte         = new MockDTE(this);
            _serviceProvider.AddService(typeof(SVsTextManager), TextManager);
            _serviceProvider.AddService(typeof(SVsActivityLog), ActivityLog);
            _serviceProvider.AddService(typeof(SVsSettingsManager), SettingsManager);
            _serviceProvider.AddService(typeof(SLocalRegistry), LocalRegistry);
            _serviceProvider.AddService(typeof(SComponentModel), this);
            _serviceProvider.AddService(typeof(IVsDebugger), Debugger);
            _serviceProvider.AddService(typeof(SVsSolution), Solution);
            _serviceProvider.AddService(typeof(SVsRegisterProjectTypes), Solution);
            _serviceProvider.AddService(typeof(SVsCreateAggregateProject), Solution);
            _serviceProvider.AddService(typeof(SVsTrackProjectDocuments), TrackDocs);
            _serviceProvider.AddService(typeof(SVsShell), Shell);
            _serviceProvider.AddService(typeof(SOleComponentManager), _compManager);
            _serviceProvider.AddService(typeof(SVsProfferCommands), _proferredCommands);
            _serviceProvider.AddService(typeof(SVsOutputWindow), _outputWindow);
            _serviceProvider.AddService(typeof(SVsBuildManagerAccessor), _buildManager);
            _serviceProvider.AddService(typeof(SVsUIHierWinClipboardHelper), _hierClipHelper);
            _serviceProvider.AddService(typeof(IVsUIShell), UIShell);
            _serviceProvider.AddService(typeof(IVsMonitorSelection), _monSel);
            _serviceProvider.AddService(typeof(SVsQueryEditQuerySave), _queryEditSave);
            _serviceProvider.AddService(typeof(SVsRunningDocumentTable), _rdt);
            _serviceProvider.AddService(typeof(SVsUIShellOpenDocument), _shellOpenDoc);
            _serviceProvider.AddService(typeof(SVsSolutionBuildManager), _slnBuildMgr);
            _serviceProvider.AddService(typeof(EnvDTE.IVsExtensibility), _extensibility);
            _serviceProvider.AddService(typeof(EnvDTE.DTE), _dte);

            Shell.SetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, true);

            UIShell.AddToolWindow(new Guid(ToolWindowGuids80.SolutionExplorer), new MockToolWindow(_uiHierarchy));

            ErrorHandler.ThrowOnFailure(
                _monSel.AdviseSelectionEvents(
                    new SelectionEvents(this),
                    out _monSelCookie
                    )
                );

#if DEV15_OR_LATER
            // If we are not in Visual Studio, we need to set MSBUILD_EXE_PATH
            // to use any project support.
            if (!"devenv".Equals(Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location), StringComparison.OrdinalIgnoreCase))
            {
                var vsPath = Environment.GetEnvironmentVariable("VisualStudio_" + AssemblyVersionInfo.VSVersion);
                if (!Directory.Exists(vsPath))
                {
                    vsPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                    if (string.IsNullOrEmpty(vsPath))
                    {
                        vsPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                    }
                    vsPath = Path.Combine(vsPath, "Microsoft Visual Studio", AssemblyVersionInfo.VSVersionSuffix);
                }
                if (Directory.Exists(vsPath))
                {
                    var msbuildPath = Path.Combine(vsPath, "MSBuild");
                    var msbuildExe  = FileUtils.EnumerateFiles(msbuildPath, "msbuild.exe").OrderByDescending(k => k).FirstOrDefault();
                    if (File.Exists(msbuildExe))
                    {
                        // Set the variable. If we haven't set it, most tests
                        // should still work, but ones trying to load MSBuild's
                        // assemblies will fail.
                        Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", msbuildExe);
                    }
                }
            }
#endif

            _throwExceptionsOn = Thread.CurrentThread;

            using (var e = new AutoResetEvent(false)) {
                UIThread      = new Thread(UIThreadWorker);
                UIThread.Name = "Mock UI Thread";
                UIThread.Start((object)e);
                // Wait for UI thread to start before returning. This ensures that
                // any packages we have are loaded and have published their services
                e.WaitOne();
            }
            ThrowPendingException();
        }