コード例 #1
0
 /// <summary>
 /// Adds a reference to the source object on the specified target object
 /// </summary>
 /// <param name="sourceObject">The object to add a reference to</param>
 /// <param name="targetObject">The object to add the reference on</param>
 private void AddReference(MAObjectHologram sourceObject, MAObjectHologram targetObject)
 {
     if (this.BackLinkAttribute.IsMultivalued)
     {
         if (!targetObject.HasAttributeValue(this.BackLinkAttribute, sourceObject.ObjectID))
         {
             targetObject.UpdateAttributeValue(this.BackLinkAttribute, new List <ValueChange>()
             {
                 ValueChange.CreateValueAdd(sourceObject.ObjectID)
             });
         }
     }
     else
     {
         targetObject.SetAttributeValue(this.BackLinkAttribute, sourceObject.ObjectID);
     }
 }
コード例 #2
0
        /// <summary>
        /// Constructs a target attribute value based on the rules in the constructor
        /// </summary>
        /// <param name="hologram">The object to construct the value for</param>
        internal override void Execute(MAObjectHologram hologram)
        {
            List <ValueChange>            valueChanges = new List <ValueChange>();
            AcmaAttributeModificationType modificationType;

            if (this.ModificationType == AcmaAttributeModificationType.Conditional)
            {
                if (!this.HasPresenceConditions)
                {
                    throw new InvalidOperationException("The constructor has a conditional modification type, but no presence conditions were present");
                }

                if (this.PresenceConditions.Evaluate(hologram))
                {
                    if (this.Attribute.IsMultivalued)
                    {
                        modificationType = AcmaAttributeModificationType.Add;
                    }
                    else
                    {
                        modificationType = AcmaAttributeModificationType.Replace;
                    }

                    Logger.WriteLine("Presence conditions met", LogLevel.Debug);
                }
                else
                {
                    modificationType = AcmaAttributeModificationType.Delete;
                    Logger.WriteLine("Presence conditions not met", LogLevel.Debug);
                }
            }
            else
            {
                modificationType = this.ModificationType;
            }

            foreach (ValueDeclaration declaration in this.ValueDeclarations)
            {
                IList <object> returnValue = declaration.Expand(hologram);

                if (returnValue == null)
                {
                    continue;
                }
                else
                {
                    foreach (object value in returnValue)
                    {
                        object newValue = TypeConverter.ConvertData(value, this.Attribute.Type);
                        if (newValue != null && !(newValue is string && string.IsNullOrWhiteSpace((string)newValue)))
                        {
                            if (modificationType == AcmaAttributeModificationType.Delete)
                            {
                                if (hologram.HasAttributeValue(this.Attribute, newValue))
                                {
                                    valueChanges.Add(this.CreateValueChange(newValue, ValueModificationType.Delete));
                                }
                            }
                            else if (modificationType == AcmaAttributeModificationType.Add)
                            {
                                if (this.Attribute.IsMultivalued)
                                {
                                    if (!hologram.HasAttributeValue(this.Attribute, newValue))
                                    {
                                        valueChanges.Add(this.CreateValueChange(newValue, ValueModificationType.Add));
                                    }
                                }
                                else
                                {
                                    valueChanges.Add(this.CreateValueChange(newValue, ValueModificationType.Add));
                                }
                            }
                            else if (modificationType == AcmaAttributeModificationType.Replace)
                            {
                                valueChanges.Add(this.CreateValueChange(newValue, ValueModificationType.Add));
                            }
                            else
                            {
                                throw new InvalidOperationException("The modification type was unexpected at this location");
                            }
                        }
                    }
                }
            }

            valueChanges = valueChanges.Distinct(this.ValueChangeComparer).ToList();

            this.ApplyValueChanges(hologram, valueChanges, modificationType);
            this.RaiseCompletedEvent();
        }