Example #1
0
        /// <summary>
        ///     Do the following when an Entity changes:
        ///     - Update roles in related Associations
        /// </summary>
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            base.ElementAdded(e);

            var addedProperty = e.ModelElement as NavigationProperty;

            Debug.Assert(addedProperty != null);
            Debug.Assert(addedProperty.EntityType != null && addedProperty.EntityType.EntityDesignerViewModel != null);

            if (addedProperty != null &&
                addedProperty.EntityType != null &&
                addedProperty.EntityType.EntityDesignerViewModel != null)
            {
                var tx = ModelUtils.GetCurrentTx(e.ModelElement.Store);
                Debug.Assert(tx != null);
                if (tx != null &&
                    !tx.IsSerializing)
                {
                    ViewModelChangeContext.GetNewOrExistingContext(tx).ViewModelChanges.Add(new NavigationPropertyAdd(addedProperty));
                }
            }
        }
Example #2
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>
        ///     Do the following when an Entity changes:
        ///     - Update roles in related Associations
        /// </summary>
        /// <param name="e"></param>
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            var changedNavigationProperty = e.ModelElement as NavigationProperty;

            Debug.Assert(changedNavigationProperty != null);
            Debug.Assert(
                changedNavigationProperty.EntityType != null && changedNavigationProperty.EntityType.EntityDesignerViewModel != null);

            if ((changedNavigationProperty != null) &&
                (changedNavigationProperty.EntityType != null) &&
                (changedNavigationProperty.EntityType.EntityDesignerViewModel != null))
            {
                var tx = ModelUtils.GetCurrentTx(e.ModelElement.Store);
                Debug.Assert(tx != null);
                // don't do the auto update stuff if we are in the middle of deserialization
                if (tx != null &&
                    !tx.IsSerializing)
                {
                    var viewModel = changedNavigationProperty.EntityType.EntityDesignerViewModel;

                    if (e.DomainProperty.Id == NameableItem.NameDomainPropertyId)
                    {
                        // if we are creating this, the old name will be empty so there is no 'change' to do
                        if (String.IsNullOrEmpty((string)e.OldValue))
                        {
                            return;
                        }

                        if (!EscherAttributeContentValidator.IsValidCsdlNavigationPropertyName(changedNavigationProperty.Name))
                        {
                            throw new InvalidOperationException(
                                      String.Format(
                                          CultureInfo.CurrentCulture, Resources.Error_NavigationPropertyNameInvalid,
                                          changedNavigationProperty.Name));
                        }

                        var modelEntityType =
                            viewModel.ModelXRef.GetExisting(changedNavigationProperty.EntityType) as Model.Entity.EntityType;
                        Debug.Assert(modelEntityType != null, "modelEntityType is null");

                        // ensure name is unique
                        if (modelEntityType.LocalName.Value.Equals(changedNavigationProperty.Name, StringComparison.Ordinal))
                        {
                            var msg = string.Format(
                                CultureInfo.CurrentCulture, Model.Resources.Error_MemberNameSameAsParent, changedNavigationProperty.Name,
                                modelEntityType.LocalName.Value);
                            throw new InvalidOperationException(msg);
                        }
                        else if (!EDMModelUtils.IsUniquePropertyName(modelEntityType, changedNavigationProperty.Name, true))
                        {
                            var msg = string.Format(
                                CultureInfo.CurrentCulture, Model.Resources.Error_MemberNameNotUnique, changedNavigationProperty.Name,
                                modelEntityType.LocalName.Value);
                            throw new InvalidOperationException(msg);
                        }

                        ViewModelChangeContext.GetNewOrExistingContext(tx)
                        .ViewModelChanges.Add(new NavigationPropertyChange(changedNavigationProperty));
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        ///     Do the following when an Entity changes:
        ///     - Update roles in related Associations
        /// </summary>
        /// <param name="e"></param>
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            var changedProperty = e.ModelElement as Property;

            Debug.Assert(changedProperty != null);

            // this rule will fire if a PropertyRef gets deleted (this happens if a keyed property that has a sibling keyed property is deleted),
            // in which case we ignore this change.
            if (changedProperty.IsDeleted)
            {
                return;
            }

            Debug.Assert(changedProperty.EntityType != null && changedProperty.EntityType.EntityDesignerViewModel != null);

            if (changedProperty != null &&
                changedProperty.EntityType != null &&
                changedProperty.EntityType.EntityDesignerViewModel != null)
            {
                var diagram = changedProperty.EntityType.EntityDesignerViewModel.GetDiagram();
                Debug.Assert(diagram != null, "EntityDesignerDiagram is null");

                // if EntityType property was changed and EntityDesignerDiagram's DisplayNameAndType flag is set to true, we need to refresh the entity shape diagram.
                if (e.DomainProperty.Id == Property.TypeDomainPropertyId &&
                    null != diagram &&
                    diagram.DisplayNameAndType)
                {
                    foreach (var pe in PresentationViewsSubject.GetPresentation(changedProperty.EntityType))
                    {
                        var entityShape = pe as EntityTypeShape;
                        if (entityShape != null)
                        {
                            entityShape.PropertiesCompartment.Invalidate(true);
                        }
                    }
                }

                var tx = ModelUtils.GetCurrentTx(e.ModelElement.Store);
                Debug.Assert(tx != null);
                // don't do the auto update stuff if we are in the middle of deserialization
                if (tx != null &&
                    !tx.IsSerializing)
                {
                    var viewModel = changedProperty.EntityType.EntityDesignerViewModel;
                    // ensure name is unique and valid if the name has changed
                    if (e.DomainProperty.Id == NameableItem.NameDomainPropertyId)
                    {
                        // if we are creating this, the old name will be empty so there is no 'change' to do
                        if (String.IsNullOrEmpty((string)e.OldValue))
                        {
                            return;
                        }

                        var modelProperty = viewModel.ModelXRef.GetExisting(changedProperty) as Model.Entity.Property;
                        Debug.Assert(modelProperty != null, "modelProperty is null");

                        string errorMessage;
                        if (!EDMModelUtils.ValidatePropertyName(modelProperty, changedProperty.Name, true, out errorMessage))
                        {
                            throw new InvalidOperationException(errorMessage);
                        }

                        ViewModelChangeContext.GetNewOrExistingContext(tx).ViewModelChanges.Add(new PropertyChange(changedProperty));
                    }
                }
            }
        }