Example #1
0
        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");
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     This is called before a transaction has committed,
        ///     This tests to see if the transaction was a drag & drop, and if
        ///     so the new elements can be auto-arranged before the transaction has finished.
        ///     See Also: ShapeAddedToDiagramRule
        /// </summary>
        public override void OnTransactionCommitting(TransactionCommitEventArgs e)
        {
            base.OnTransactionCommitting(e);

            Arranger.TransactionCommit(this);
        }
        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");
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     This is called whenever there is a change that originates from the the DSL surface.  The
        ///     changes are packaged up and the ModelController is used to make the changes to the model.
        /// </summary>
        /// <param name="e"></param>
        internal void OnTransactionCommited(TransactionCommitEventArgs e)
        {
            if (_reloading)
            {
                return;
            }

            var changeContext = ViewModelChangeContext.GetExistingContext(e.Transaction);
            if (changeContext != null
                && changeContext.ViewModelChanges.Count > 0)
            {
                var context = EditingContext;
                var service = context.GetEFArtifactService();
                var viewModelChanges = changeContext.ViewModelChanges.OfType<ViewModelChange>().ToList();

                Debug.Assert(
                    changeContext.ViewModelChanges.Count == viewModelChanges.Count,
                    "Not all changes from the view model were of type ViewModleChange");

                try
                {
                    SortAndOptimizeViewModelChanges(viewModelChanges);

                    // these changes will now be invoked, which will create the appropriate EFObjects
                    // and push changes down to the XLinq tree
                    ProcessViewModelChanges(e.Transaction.Name, viewModelChanges);
                }
                catch (Exception ex)
                {
                    ClearAndReloadDiagram();
                    if (ex is FileNotEditableException)
                    {
                        service.Artifact.IsDirty = false;
                    }
                    throw;
                }
            }
        }