internal static void DoMigrate(CommandProcessorContext cpc, EntityDesignArtifact artifact) { var xmlModelProvider = artifact.XmlModelProvider as VSXmlModelProvider; Debug.Assert(xmlModelProvider != null, "Artifact's model provider is not type of VSXmlModelProvider."); if ((xmlModelProvider != null) && (xmlModelProvider.UndoManager != null)) { var undoManager = xmlModelProvider.UndoManager; try { // We need to temporarily disable the Undo Manager because this operation is not undoable. if (undoManager != null) { undoManager.Enable(0); } var command = new MigrateDiagramInformationCommand(artifact); var processor = new CommandProcessor(cpc, shouldNotifyObservers: false); processor.EnqueueCommand(command); processor.Invoke(); Debug.Assert(artifact.DiagramArtifact != null, "Diagram artifact should have been created by now."); if (artifact.DiagramArtifact != null) { // Ensure that diagram file is added to the project. var service = PackageManager.Package.GetService(typeof(DTE)) as DTE; service.ItemOperations.AddExistingItem(artifact.DiagramArtifact.Uri.LocalPath); // Reload the artifacts. artifact.ReloadArtifact(); artifact.IsDirty = true; // The code below ensures mapping window and model-browser window are refreshed. Debug.Assert( PackageManager.Package.DocumentFrameMgr != null, "Could not find the DocumentFrameMgr for this package"); if (PackageManager.Package.DocumentFrameMgr != null) { PackageManager.Package.DocumentFrameMgr.SetCurrentContext(cpc.EditingContext); } } } finally { if (undoManager != null) { undoManager.Enable(1); } } } }