/// <devdoc> /// Service provider implementation. We pass this to a QI on the native text buffer. /// </devdoc> object IServiceProvider.GetService(Type serviceType) { if (textStream != null) { if (serviceType == typeof(IVsCompoundAction)) { return(textStream as IVsCompoundAction); } if (serviceType.IsInstanceOfType(textStream)) { return(textStream); } if (serviceType == typeof(EnvDTE.TextDocument)) { if (textDocument == null) { IVsExtensibleObject vsExtObj = textStream as IVsExtensibleObject; if (vsExtObj != null) { textDocument = (EnvDTE.TextDocument)vsExtObj.GetAutomationObject("TextDocument"); } else { EnvDTE.IExtensibleObject extObj = textStream as EnvDTE.IExtensibleObject; if (extObj != null) { object doc; extObj.GetAutomationObject("TextDocument", null, out doc); textDocument = doc as EnvDTE.TextDocument; } } } return(textDocument); } } return(null); }
public static void ShowDialog(IServiceProvider serviceProvider, ORMDesignerDocData docData) { ExtensionManager extensionManager = new ExtensionManager(docData.Store); IWin32Window dialogOwner = Utility.GetDialogOwnerWindow(serviceProvider); if (extensionManager.ShowDialog(dialogOwner) == DialogResult.OK) { // TODO: Prompt the user to make sure they really want us to start deleting stuff... ListView.CheckedListViewItemCollection checkedItems = extensionManager.lvExtensions.CheckedItems; ExtensionLoader extensionLoader = ORMDesignerPackage.ExtensionLoader; IDictionary <string, ExtensionModelBinding> availableExtensions = extensionLoader.AvailableCustomExtensions; Dictionary <string, ExtensionModelBinding> checkedTypes = new Dictionary <string, ExtensionModelBinding>(availableExtensions.Count); foreach (ListViewItem listViewItem in checkedItems) { string extensionNamespace = (string)listViewItem.Tag; checkedTypes.Add(extensionNamespace, availableExtensions[extensionNamespace]); } // Make sure all required extensions are turned on. This will turn previously ignored // secondary extensions back on. extensionLoader.VerifyRequiredExtensions(ref checkedTypes); Stream currentStream = null; Stream newStream = null; Stream modifiedStream = null; try { Object streamObj; EnvDTE.IExtensibleObject docDataExtender = (EnvDTE.IExtensibleObject)docData; docDataExtender.GetAutomationObject("ORMXmlStream", null, out streamObj); currentStream = streamObj as Stream; Debug.Assert(currentStream != null); // Allow each domain model that is being removed to run custom code immediately before the // unload process. Transaction customUnloadTransaction = null; Store store = docData.Store; try { IDomainModelUnloading[] unloadingModels = ((IFrameworkServices)store).GetTypedDomainModelProviders <IDomainModelUnloading>(); if (unloadingModels != null) { for (int i = 0; i < unloadingModels.Length; ++i) { IDomainModelUnloading unloadingModel = unloadingModels[i]; ICustomSerializedDomainModel serializedModel; if (null != (serializedModel = unloadingModel as ICustomSerializedDomainModel)) { string[,] namespaceInfo = serializedModel.GetCustomElementNamespaces(); int namespaceCount = namespaceInfo.GetLength(0); int j = 0; for (; j < namespaceCount; ++j) { if (checkedTypes.ContainsKey(namespaceInfo[j, 1])) { break; } } if (j == namespaceCount) { // Extension domain model is not in the pending set, go ahead and run // the custom code to unload it cleanly. if (customUnloadTransaction == null) { customUnloadTransaction = store.TransactionManager.BeginTransaction("Domain Models Unloading"); // String not localized, won't be displayed on either success or failure } unloadingModel.DomainModelUnloading(store); } } } } } finally { if (customUnloadTransaction != null) { if (customUnloadTransaction.HasPendingChanges) { customUnloadTransaction.Commit(); // Get the modified stream docDataExtender.GetAutomationObject("ORMXmlStream", null, out streamObj); modifiedStream = streamObj as Stream; } customUnloadTransaction.Dispose(); } } newStream = ExtensionLoader.CleanupStream(modifiedStream ?? currentStream, extensionLoader.StandardDomainModels, checkedTypes.Values, null); docData.ReloadFromStream(newStream, currentStream); } finally { if (currentStream != null) { currentStream.Dispose(); } if (modifiedStream != null) { currentStream.Dispose(); } if (newStream != null) { newStream.Dispose(); } } } }