Ejemplo n.º 1
0
        internal void NotifyValueChangeToOwner(string changedProperty, string calledFromEndId)
        {
            IElementEventsHandler eventsHandler = owner as IElementEventsHandler;

            if (eventsHandler != null)
            {
                ElementEventArgs arg = new ElementEventArgs(this, changedProperty, calledFromEndId);
                eventsHandler.HandleEvent(arg);
            }
        }
Ejemplo n.º 2
0
        public void HandleEvent(ElementEventArgs args)
        {
            if (args.EventType == ElementEventType.ElementPropertyChanged)
            {
                Func <Tuple <OrmAssociationEnd, OrmAssociationEnd> > getAssocEnd = () =>
                {
                    PersistentType currentOwner = this.PersistentTypeOfNavigationProperty;
                    bool           isSource     = this.PersistentTypeHasAssociations.SourcePersistentType == currentOwner;

                    OrmAssociationEnd assocEnd1 = isSource
                                                     ? this.PersistentTypeHasAssociations.End2
                                                     : this.PersistentTypeHasAssociations.End1;
                    OrmAssociationEnd assocEnd2 = isSource
                                                     ? this.PersistentTypeHasAssociations.End1
                                                     : this.PersistentTypeHasAssociations.End2;
                    return(new Tuple <OrmAssociationEnd, OrmAssociationEnd>(assocEnd1, assocEnd2));
                };

                var e = args.ElementPropertyChangedEventArgs;
                if (e.DomainProperty.Id == MultiplicityDomainPropertyId)
                {
                    if (this.PersistentTypeHasAssociations != null)
                    {
                        var assocEnds = getAssocEnd();
                        assocEnds.Item1.Multiplicity = (MultiplicityKind)e.NewValue;
                    }
                }
                else if (e.DomainProperty.Id == NameDomainPropertyId)
                {
                    if (this.PersistentTypeHasAssociations != null)
                    {
                        var assocEnds = getAssocEnd();
                        assocEnds.Item2.PairTo.SetAsCustom(e.NewValue as string);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void HandleEvent(ElementEventArgs args)
        {
            if (args.EventType == ElementEventType.CustomEvent)
            {
                object            customEventArgs   = args.CustomEventArgs[0];
                OrmAssociationEnd eventFromAssocEnd = customEventArgs as OrmAssociationEnd;
                string            changedProperty   = (string)args.CustomEventArgs[1];
                string            calledFromEndId   = (string)args.CustomEventArgs[2];

                if (eventFromAssocEnd != null)
                {
                    bool changeAll             = string.IsNullOrEmpty(changedProperty);
                    bool canChangeMultiplicity = changeAll || Util.StringEqual(changedProperty, "Multiplicity", true);
                    bool canChangePairTo       = changeAll || Util.StringEqual(changedProperty, "PairTo", true);

                    bool eventFromEnd1 = Util.StringEqual(calledFromEndId, "End1", true);

                    Func <bool, Tuple <NavigationProperty, OrmAssociationEnd> > getDefinitions = delegate(bool revert)
                    {
                        PersistentType persistentToFind = eventFromEnd1
                                                              ? (revert
                                                                     ? this.SourcePersistentType
                                                                     : this.TargetPersistentType)
                                                              : (revert
                                                                     ? this.TargetPersistentType
                                                                     : this.SourcePersistentType);

                        OrmAssociationEnd otherAssocEnd = eventFromEnd1
                                                              ? (revert
                                                                    ? this.End2
                                                                    : eventFromAssocEnd)
                                                              : (revert
                                                                    ? eventFromAssocEnd
                                                                    : this.End2);

                        NavigationProperty navigationProperty = this.NavigationProperties.SingleOrDefault(
                            navProperty => navProperty.PersistentTypeOfNavigationProperty == persistentToFind);

                        return(new Tuple <NavigationProperty, OrmAssociationEnd>(navigationProperty, otherAssocEnd));
                    };


                    {
                        if (canChangeMultiplicity)
                        {
                            bool revert             = false;
                            var  definitions        = getDefinitions(revert);
                            var  navigationProperty = definitions.Item1;
                            var  otherAssocEnd      = definitions.Item2;

                            if (navigationProperty != null)
                            {
                                this.Store.MakeActionWithinTransaction(
                                    string.Format("Updating multiplicity on navigation property '{0}' to value '{1}'",
                                                  navigationProperty.Name, eventFromAssocEnd.Multiplicity),
                                    () =>
                                {
                                    navigationProperty.Multiplicity = otherAssocEnd.Multiplicity;
                                });
                            }
                        }

                        if (canChangePairTo && !eventFromAssocEnd.PairTo.IsDefault())
                        {
                            string newName = eventFromAssocEnd.PairTo.Value;

                            bool revert             = true;
                            var  definitions        = getDefinitions(revert);
                            var  navigationProperty = definitions.Item1;

                            if (navigationProperty != null)
                            {
                                this.Store.MakeActionWithinTransaction(
                                    string.Format("Updating name on navigation property '{0}' to value '{1}'",
                                                  navigationProperty.Name, newName),
                                    () =>
                                {
                                    navigationProperty.Name = newName;
                                });
                            }
                        }
                    }
                }
            }
        }