/// <summary> /// Called when the reference count goes to zero. /// </summary> protected override void _cleanup() { try { this._closeAllViews(); if (true == _commands.Valid) { _commands.Value.clear(); _commands.Value = null; } if (null != _gui) { _gui.Document = null; _gui = null; } if (null != _views) { _views.Clear(); // Not setting to null here is a work-around for a bug related to // the fact that the views, documents, and document-manager are // too tightly coupled. _views = new DocViews(); } base._cleanup(); } catch (System.Exception e) { System.Console.WriteLine("Error 3201769786: {0}", e.Message); } }
/// <summary> /// Close all doc-view windows. /// </summary> public void CloseAllDiagrams() { foreach (var docView in DocViews.ToList()) { CloseDocViewWindow(docView as MicrosoftDataEntityDesignDocView); } }
public override void OpenView(global::System.Guid logicalView, object viewContext) { MexModeling::ViewContext modelingViewContext = viewContext as MexModeling::ViewContext; if (modelingViewContext == null) { base.OpenView(logicalView, viewContext); return; } if (string.IsNullOrEmpty(modelingViewContext.DiagramName)) { throw new global::System.ArgumentException("the name of the diagram to open cannot be empty."); } DslDiagrams::Diagram diagram = this.GetDiagram(modelingViewContext); if (diagram == null) { if (modelingViewContext.DiagramType == null) { throw new global::System.ArgumentException("the type of the diagram to open must be specified."); } if (!(modelingViewContext.DiagramType.IsSubclassOf(typeof(DslDiagrams::Diagram)))) { throw new global::System.ArgumentException("the type of the diagram to open must inherit from Microsoft.VisualStudio.Modeling.Diagrams.Diagram class."); } // No diagram associated with specified name, so create and set the name DslModeling::ModelElement rootElement = modelingViewContext.RootElement ?? this.RootElement; using (DslModeling::Transaction t1 = this.Store.TransactionManager.BeginTransaction("DocData:OpenView:CreateDiagram", true)) { diagram = (DslDiagrams::Diagram)global::System.Activator.CreateInstance(modelingViewContext.DiagramType, this.PartitionMapper.PartitionForClass(this.Store.DefaultPartition, DslDiagrams::Diagram.DomainClassId), new DslModeling::PropertyAssignment(DslDiagrams::Diagram.NameDomainPropertyId, modelingViewContext.DiagramName)); // Set the ModelElement associated with the newly created diagram. diagram.ModelElement = rootElement; Store.GetAll <ModelDiagramData>().FirstOrDefault(d => d.Name == diagram.Name)?.SetDiagram((EFModelDiagram)diagram); t1.Commit(); } } EFModelDocView existingView = DocViews.OfType <EFModelDocView>().FirstOrDefault(v => v.Diagram.Name == diagram.Name); if (existingView != null) { existingView.Show(); } else { base.OpenView(logicalView, viewContext); } }
protected override void Save(string fileName) { // Make sure that we set the root element to the current active view's root element before we save. IServiceProvider serviceProvider = PackageManager.Package; var selectionService = serviceProvider.GetService(typeof(IMonitorSelectionService)) as IMonitorSelectionService; var dataEntityDesignDocView = selectionService.CurrentDocumentView as MicrosoftDataEntityDesignDocView; // if the current active view is not Entity designer or the view belongs to another document, just get the first view available. if (dataEntityDesignDocView == null || dataEntityDesignDocView.DocData != this) { dataEntityDesignDocView = DocViews.OfType <MicrosoftDataEntityDesignDocView>().FirstOrDefault(); } Debug.Assert(dataEntityDesignDocView != null, "There is no active DocView associated for the DocData."); if (dataEntityDesignDocView != null) { SetRootElement(dataEntityDesignDocView.Diagram.ModelElement); } base.Save(fileName); ProcessDependentTTFiles(); }
protected void OnTransactionCommitted(Object sender, TransactionCommitEventArgs e) { MicrosoftDataEntityDesignDocView dataEntityDesignDocView = null; // Need to figure the diagram view where the transaction originates. // First we look at transaction context for diagram id information. // If this information is not available then we are going to look at the current active window. var diagramId = string.Empty; if (e.TransactionContext.TryGetValue(EfiTransactionOriginator.TransactionOriginatorDiagramId, out diagramId)) { foreach (var view in DocViews.OfType <MicrosoftDataEntityDesignDocView>()) { if (view.Diagram.DiagramId == diagramId) { dataEntityDesignDocView = view; break; } } } else { // look at the current selection // Note: must use CurrentDocumentView rather than CurrentWindow, CurrentWindow can be e.g. the MappingDetailsWindow IServiceProvider serviceProvider = PackageManager.Package; var selectionService = serviceProvider.GetService(typeof(IMonitorSelectionService)) as IMonitorSelectionService; dataEntityDesignDocView = selectionService.CurrentDocumentView as MicrosoftDataEntityDesignDocView; } // When a new diagram is created, the doc view is not created yet when transaction is committed. // In that situation, we just skip delegating the transaction to DSL view model because there is none. if (dataEntityDesignDocView != null && dataEntityDesignDocView.IsLoading == false) { var viewModel = dataEntityDesignDocView.Diagram.ModelElement as EntityDesignerViewModel; if (viewModel != null) { viewModel.OnTransactionCommited(e); // now set the isDirty flag on Shell's UndoManager so diagram layout changes can // also get persisted; if there isn't one of our context's in the xact, then this // change didn't involve changing any items, just position or size var changeContext = ViewModelChangeContext.GetExistingContext(e.Transaction); if (changeContext == null) { if (IsHandlingDocumentReloaded == false) { SetDocDataDirty(1); } } else { // if we get here, there are changes that originated in the designer surface // so run our validation if (Store != null) { ValidationController.ValidateCustom(Store, "OnTransactionCommited"); } } } } }