public static bool RenameElement(this IProductElement element, IToolkitElement toolkitElement, IUriReferenceService uriService, RefactoringManager refactoringManager, EnvDTE.Documents EnvDTEDocuments = null) { using (new MouseCursor(System.Windows.Input.Cursors.Wait)) { var renameRefactoring = toolkitElement as IRenameRefactoring; if (renameRefactoring != null) { element.CloseDocuments(uriService, EnvDTEDocuments); refactoringManager.RenameClass(renameRefactoring.Namespace, renameRefactoring.OriginalInstanceName, renameRefactoring.InstanceName); element.RenameArtifactLinks(uriService, renameRefactoring.OriginalInstanceName, renameRefactoring.InstanceName); var additionalRenameRefactorings = toolkitElement as IAdditionalRenameRefactorings; if (additionalRenameRefactorings != null) { for (int i = 0; i < additionalRenameRefactorings.AdditionalInstanceNames.Count; i++) { refactoringManager.RenameClass(renameRefactoring.Namespace, additionalRenameRefactorings.AdditionalOriginalInstanceNames[i], additionalRenameRefactorings.AdditionalInstanceNames[i]); element.RenameArtifactLinks(uriService, additionalRenameRefactorings.AdditionalOriginalInstanceNames[i], additionalRenameRefactorings.AdditionalInstanceNames[i]); } } return(true); } var renameRefactoringNamespace = toolkitElement as IRenameRefactoringNamespace; if (renameRefactoringNamespace != null && toolkitElement.InstanceName != "" && toolkitElement is IService) { var service = toolkitElement as IService; service.Rename(uriService, refactoringManager); //MessageBox.Show("The Service renaming is almost done. Please, re-open the solution to finish with the renaming.", "ServiceMatrix - Rename Service", MessageBoxButton.OK); return(true); } var renameRefactoringNotSupported = toolkitElement as IRenameRefactoringNotSupported; if (renameRefactoringNotSupported != null && toolkitElement.InstanceName != "") { var result = MessageBox.Show("This element doesn't support code refactoring, you will need to update your code manually. Do you want to do the renaming anyway?", "ServiceMatrix - Rename element", MessageBoxButton.YesNo); return(result == MessageBoxResult.Yes); } return(true); } }
public static void CloseDocuments(this IProductElement element, IUriReferenceService uriService, EnvDTE.Documents EnvDTEDocuments) { var documents = EnvDTEDocuments.OfType <EnvDTE.Document>(); foreach (var referenceLink in element.References) { var item = default(IItemContainer); try { item = uriService.ResolveUri <IItemContainer>(new Uri(referenceLink.Value)); } catch { } if (item != null && item.Kind == ItemKind.Item && documents.Any(x => x.FullName == item.PhysicalPath)) { documents.First(x => x.FullName == item.PhysicalPath).Close(vsSaveChanges.vsSaveChangesYes); } } }