/// <summary>
 /// Removes a reference to the source object on the specified target object
 /// </summary>
 /// <param name="sourceObject">The object to remove the reference to</param>
 /// <param name="targetObject">The object to remove the reference from</param>
 private void RemoveReference(MAObjectHologram sourceObject, MAObjectHologram targetObject)
 {
     if (this.BackLinkAttribute.IsMultivalued)
     {
         targetObject.UpdateAttributeValue(this.BackLinkAttribute, new List <ValueChange>()
         {
             ValueChange.CreateValueDelete(sourceObject.ObjectID)
         });
     }
     else
     {
         targetObject.DeleteAttribute(this.BackLinkAttribute);
     }
 }
Exemple #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 <MAObjectHologram> matchedObjects = ActiveConfig.DB.GetMAObjectsFromDBQuery(this.QueryGroup, hologram).ToList();

            if (matchedObjects.Count == 0)
            {
                hologram.DeleteAttribute(this.Attribute);
            }
            else
            {
                switch (this.MultipleResultAction)
                {
                case MultipleResultAction.UseAll:
                    if (!this.Attribute.IsMultivalued && matchedObjects.Count > 1)
                    {
                        throw new MultipleMatchException(string.Format("The reference lookup constructor for attribute {0} returned more than one result", this.Attribute));
                    }

                    hologram.SetAttributeValue(this.Attribute, matchedObjects.Select(t => (object)t.ObjectID).ToList());
                    break;

                case MultipleResultAction.UseFirst:
                    hologram.SetAttributeValue(this.Attribute, matchedObjects.First().ObjectID);
                    break;

                case MultipleResultAction.UseNone:
                    if (matchedObjects.Count > 1)
                    {
                        hologram.SetAttributeValue(this.Attribute, null);
                    }
                    else
                    {
                        hologram.SetAttributeValue(this.Attribute, matchedObjects.First().ObjectID);
                    }

                    break;

                case MultipleResultAction.Error:
                    throw new MultipleMatchException(string.Format("The reference lookup constructor for attribute {0} returned more than one result", this.Attribute));

                default:
                    throw new UnknownOrUnsupportedDataTypeException();
                }
            }

            this.RaiseCompletedEvent();
        }
        /// <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>();

            IList <object> returnValues = new List <object>();

            if (this.UniqueAllocationAttributes.Count == 0)
            {
                throw new NotSupportedException("There were no attributes to process unique allocations against");
            }

            string staticValue = this.TryGetUniqueValueFromStaticDeclarations(hologram);

            if (string.IsNullOrWhiteSpace(staticValue))
            {
                returnValues = this.ValueDeclaration.Expand(hologram, (string valueToTest, string wildCardValue) => this.IsAttributeUnique(hologram, valueToTest, wildCardValue));
            }
            else
            {
                returnValues.Add(staticValue);
            }

            if (returnValues == null || returnValues.Count == 0)
            {
                hologram.DeleteAttribute(this.Attribute);
            }
            else
            {
                if (returnValues.Count > 1)
                {
                    throw new TooManyValuesException(string.Format("The value declaration '{0}' returned more than one value. Only single valued attributes are supported for unique allocation", this.ValueDeclaration));
                }

                object newValue = TypeConverter.ConvertData(returnValues.First(), this.Attribute.Type);

                if (newValue != null && !(newValue is string && string.IsNullOrWhiteSpace((string)newValue)))
                {
                    valueChanges.Add(this.CreateValueChange(newValue, ValueModificationType.Add));
                }
            }

            this.ApplyValueChanges(hologram, valueChanges, AcmaAttributeModificationType.Replace);
            this.RaiseCompletedEvent();
        }
Exemple #4
0
 /// <summary>
 /// Executes the constructor
 /// </summary>
 /// <param name="hologram">The source object</param>
 internal override void Execute(MAObjectHologram hologram)
 {
     hologram.DeleteAttribute(this.Attribute);
     this.RaiseCompletedEvent();
 }