コード例 #1
0
ファイル: TestWorkspace.cs プロジェクト: pentp/roslyn
        protected override void Dispose(bool finalize)
        {
            var metadataAsSourceService = ExportProvider.GetExportedValues <IMetadataAsSourceFileService>().FirstOrDefault();

            if (metadataAsSourceService != null)
            {
                metadataAsSourceService.CleanupGeneratedFiles();
            }

            this.ClearSolutionData();

            foreach (var document in Documents)
            {
                document.CloseTextView();
            }

            foreach (var document in AdditionalDocuments)
            {
                document.CloseTextView();
            }

            foreach (var document in ProjectionDocuments)
            {
                document.CloseTextView();
            }

            var exceptions = Flatten(ExportProvider.GetExportedValue <TestExtensionErrorHandler>().GetExceptions());

            if (exceptions.Count > 0)
            {
                var messageBuilder = new StringBuilder();
                messageBuilder.AppendLine(
                    $@"{exceptions.Count} exception(s) were thrown during test.
Note: exceptions may have been thrown by another test running concurrently with
this test.  This can happen with any tests that share the same ExportProvider.
Examining individual exception stacks may help reveal the original test and source 
of the problem.");

                messageBuilder.AppendLine();
                for (int i = 0; i < exceptions.Count; i++)
                {
                    var exception = exceptions[i];
                    messageBuilder.AppendLine($"Exception {i}:");
                    messageBuilder.AppendLine(exception.ToString());
                    messageBuilder.AppendLine();
                }

                var message = messageBuilder.ToString();
                if (exceptions.Count == 1)
                {
                    throw new Exception(message, exceptions[0]);
                }
                else
                {
                    throw new AggregateException(message, exceptions);
                }
            }

            if (SynchronizationContext.Current != null)
            {
                Dispatcher.CurrentDispatcher.DoEvents();
            }

            base.Dispose(finalize);
        }
コード例 #2
0
ファイル: MockVs.cs プロジェクト: PeezoSlug/PTVS
 IEnumerable <T> IComponentModel.GetExtensions <T>()
 {
     return(_container.GetExportedValues <T>());
 }
コード例 #3
0
 protected override IEnumerable <object> DoGetAllInstances(Type serviceType)
 {
     return(_provider.GetExportedValues <object>(AttributedModelServices.GetContractName(serviceType)));
 }
コード例 #4
0
ファイル: MockVs.cs プロジェクト: PeezoSlug/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();

                    _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);
            }
        }