///--------------------------------------------------------------------------------
        /// <summary>This method assigns a value to a property, and updates corresponding
        /// forward and reverse engineering data.</summary>
        ///
        /// <param name="propertyName">The property name.</param>
        /// <param name="propertyValue">The property value.</param>
        ///--------------------------------------------------------------------------------
        public virtual bool AssignProperty(string propertyName, object propertyValue)
        {
            if (this.SetPropertyValue(propertyName, propertyValue) == true)
            {
                if (ReverseInstance == null)
                {
                    ReverseInstance = new PropertyInstance();
                    ReverseInstance.TransformDataFromObject(this, null, false);
                }
                else
                {
                    ReverseInstance.SetPropertyValue(propertyName, propertyValue);
                }
                if (ForwardInstance != null)
                {
                    this.TransformDataFromObject(ForwardInstance, null, false, true);
                }
            }
            else
            {
                return(false);
            }

            #region protected
            #endregion protected

            return(true);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method determines whether or not any metadata is
        /// different between the input instance and the current instance.</summary>
        ///
        /// <param name="inputPropertyInstance">The propertyinstance to compare metadata.</param>
        ///--------------------------------------------------------------------------------
        public bool IsIdenticalMetadata(PropertyInstance inputPropertyInstance)
        {
            if (ModelPropertyID.GetGuid() != inputPropertyInstance.ModelPropertyID.GetGuid())
            {
                return(false);
            }
            if (ObjectInstanceID.GetGuid() != inputPropertyInstance.ObjectInstanceID.GetGuid())
            {
                return(false);
            }
            if (Order.GetInt() != inputPropertyInstance.Order.GetInt())
            {
                return(false);
            }
            if (PropertyValue.GetString() != inputPropertyInstance.PropertyValue.GetString())
            {
                return(false);
            }
            if (IsAutoUpdated.GetBool() != inputPropertyInstance.IsAutoUpdated.GetBool())
            {
                return(false);
            }
            if (Description.GetString() != inputPropertyInstance.Description.GetString())
            {
                return(false);
            }

            #region protected
            #endregion protected

            return(true);
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method deletes the current PropertyInstance item from the solution.</summary>
 ///
 /// <param name="solutionContext">The associated solution.</param>
 ///--------------------------------------------------------------------------------
 public static void DeleteCurrentItemFromSolution(Solution solutionContext)
 {
     if (solutionContext.CurrentPropertyInstance != null)
     {
         PropertyInstance existingItem = solutionContext.PropertyInstanceList.Find(i => i.PropertyInstanceID == solutionContext.CurrentPropertyInstance.PropertyInstanceID);
         if (existingItem != null)
         {
             solutionContext.PropertyInstanceList.Remove(solutionContext.CurrentPropertyInstance);
         }
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method copies changed metadata between the input
        /// instance and the current instance.</summary>
        ///
        /// <param name="inputPropertyInstance">The propertyinstance to get metadata.</param>
        ///--------------------------------------------------------------------------------
        public void CopyChangedMetadata(PropertyInstance inputPropertyInstance)
        {
            ModelPropertyID  = inputPropertyInstance.ModelPropertyID;
            ObjectInstanceID = inputPropertyInstance.ObjectInstanceID;
            Order            = inputPropertyInstance.Order;
            PropertyValue    = inputPropertyInstance.PropertyValue;
            IsAutoUpdated    = inputPropertyInstance.IsAutoUpdated;
            Description      = inputPropertyInstance.Description;

            #region protected
            #endregion protected
        }
Exemplo n.º 5
0
        ///--------------------------------------------------------------------------------
        /// <summary>This property returns a copy of the forward engineering data for the solution.</summary>
        ///--------------------------------------------------------------------------------
        public ObjectInstance GetForwardInstance(Solution forwardSolution)
        {
            bool           isCustomized = false;
            ObjectInstance forwardItem  = new ObjectInstance();

            if (ForwardInstance != null)
            {
                forwardItem.TransformDataFromObject(ForwardInstance, null, false);
                isCustomized = true;
            }
            else if (IsAutoUpdated == false)
            {
                forwardItem.TransformDataFromObject(this, null, false);
                isCustomized = true;
            }
            else
            {
                forwardItem.ObjectInstanceID = ObjectInstanceID;
            }
            foreach (PropertyInstance item in PropertyInstanceList)
            {
                item.ObjectInstance = this;
                PropertyInstance forwardChildItem = item.GetForwardInstance(forwardSolution);
                if (forwardChildItem != null)
                {
                    forwardItem.PropertyInstanceList.Add(forwardChildItem);
                    isCustomized = true;
                }
            }
            if (isCustomized == false)
            {
                return(null);
            }
            forwardItem.SpecSourceName = DefaultSourceName;
            if (forwardSolution.ReferencedModelIDs.Find("ItemName", forwardItem.SpecSourceName) == null)
            {
                forwardSolution.ReferencedModelIDs.Add(CreateIDReference());
            }

            #region protected
            #endregion protected

            return(forwardItem);
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds a tag to TagList.</summary>
 ///--------------------------------------------------------------------------------
 public override void AddTag(string tagName)
 {
     if (ReverseInstance == null && IsAutoUpdated == true)
     {
         ReverseInstance = new PropertyInstance();
         ReverseInstance.TransformDataFromObject(this, null, false);
         IsAutoUpdated = false;
     }
     base.AddTag(tagName);
     if (ForwardInstance == null)
     {
         ForwardInstance = new PropertyInstance();
         ForwardInstance.PropertyInstanceID = PropertyInstanceID;
     }
     if (ForwardInstance.TagList.Find(t => t.TagName == tagName) == null)
     {
         ForwardInstance.TagList.Add(new Tag(Guid.NewGuid(), tagName));
     }
 }
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds the current item to the solution, if it is valid
 /// and not already present in the solution.</summary>
 ///
 /// <param name="solutionContext">The associated solution.</param>
 /// <param name="templateContext">The associated template.</param>
 /// <param name="lineNumber">The line number of the associated statement.</param>
 ///--------------------------------------------------------------------------------
 public static void AddCurrentItemToSolution(Solution solutionContext, ITemplate templateContext, int lineNumber)
 {
     if (solutionContext.CurrentPropertyInstance != null)
     {
         string validationErrors = solutionContext.CurrentPropertyInstance.GetValidationErrors();
         if (!String.IsNullOrEmpty(validationErrors))
         {
             templateContext.LogException(solutionContext, solutionContext.CurrentPropertyInstance, validationErrors, lineNumber, InterpreterTypeCode.Output);
         }
         // link item to known id, solution, and parent
         solutionContext.CurrentPropertyInstance.Solution = solutionContext;
         solutionContext.CurrentPropertyInstance.AddToParent();
         PropertyInstance existingItem = solutionContext.PropertyInstanceList.Find(i => i.PropertyInstanceID == solutionContext.CurrentPropertyInstance.PropertyInstanceID);
         if (existingItem == null)
         {
             // add new item to solution
             solutionContext.CurrentPropertyInstance.AssignProperty("PropertyInstanceID", solutionContext.CurrentPropertyInstance.PropertyInstanceID);
             solutionContext.CurrentPropertyInstance.ReverseInstance.ResetModified(false);
             solutionContext.PropertyInstanceList.Add(solutionContext.CurrentPropertyInstance);
         }
         else
         {
             // update existing item in solution
             if (existingItem.Solution == null)
             {
                 existingItem.Solution = solutionContext;
             }
             if (existingItem.ForwardInstance == null && existingItem.IsAutoUpdated == false)
             {
                 existingItem.ForwardInstance = new PropertyInstance();
                 existingItem.ForwardInstance.TransformDataFromObject(existingItem, null, false);
             }
             existingItem.TransformDataFromObject(solutionContext.CurrentPropertyInstance, null, false);
             existingItem.AddToParent();
             existingItem.AssignProperty("PropertyInstanceID", existingItem.PropertyInstanceID);
             existingItem.ReverseInstance.ResetModified(false);
             solutionContext.CurrentPropertyInstance = existingItem;
         }
         #region protected
         #endregion protected
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method determines whether the input instance metadata is
        /// effectively empty.</summary>
        ///
        /// <param name="inputPropertyInstance">The propertyinstance to compare metadata.</param>
        ///--------------------------------------------------------------------------------
        public bool IsEmptyMetadata(PropertyInstance inputPropertyInstance)
        {
            if (inputPropertyInstance == null)
            {
                return(true);
            }
            if (inputPropertyInstance.TagList.Count > 0)
            {
                return(false);
            }
            if (ModelPropertyID != inputPropertyInstance.ModelPropertyID)
            {
                return(false);
            }
            if (ObjectInstanceID != inputPropertyInstance.ObjectInstanceID)
            {
                return(false);
            }
            if (Order != DefaultValue.Int)
            {
                return(false);
            }
            if (!String.IsNullOrEmpty(inputPropertyInstance.PropertyValue))
            {
                return(false);
            }
            if (IsAutoUpdated != inputPropertyInstance.IsAutoUpdated)
            {
                return(false);
            }
            if (!String.IsNullOrEmpty(inputPropertyInstance.Description))
            {
                return(false);
            }

            #region protected
            #endregion protected

            return(true);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds this item to the parent, if not found.</summary>
        ///--------------------------------------------------------------------------------
        public void AddToParent()
        {
            ObjectInstance objectInstance = Solution.ObjectInstanceList.Find(i => i.ObjectInstanceID == ObjectInstanceID);

            if (objectInstance != null)
            {
                ObjectInstance = objectInstance;
                SetID();                  // id (from saved ids) may change based on parent info
                PropertyInstance propertyInstance = objectInstance.PropertyInstanceList.Find(i => i.PropertyInstanceID == PropertyInstanceID);
                if (propertyInstance != null)
                {
                    if (propertyInstance != this)
                    {
                        objectInstance.PropertyInstanceList.Remove(propertyInstance);
                        objectInstance.PropertyInstanceList.Add(this);
                    }
                }
                else
                {
                    objectInstance.PropertyInstanceList.Add(this);
                }
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This property returns a copy of the forward engineering data for the solution.</summary>
        ///--------------------------------------------------------------------------------
        public PropertyInstance GetForwardInstance(Solution forwardSolution)
        {
            bool             isCustomized = false;
            PropertyInstance forwardItem  = new PropertyInstance();

            if (ForwardInstance != null)
            {
                forwardItem.TransformDataFromObject(ForwardInstance, null, false);
                isCustomized = true;
            }
            else if (IsAutoUpdated == false)
            {
                forwardItem.TransformDataFromObject(this, null, false);
                isCustomized = true;
            }
            else
            {
                forwardItem.PropertyInstanceID = PropertyInstanceID;
            }
            if (isCustomized == false)
            {
                return(null);
            }
            forwardItem.SpecSourceName = DefaultSourceName;
            if (forwardSolution.ReferencedModelIDs.Find("ItemName", forwardItem.SpecSourceName) == null)
            {
                forwardSolution.ReferencedModelIDs.Add(CreateIDReference());
            }

            #region protected
            if (forwardItem.ModelPropertyID != Guid.Empty)
            {
                forwardItem.ModelProperty = Solution.ModelPropertyList.Find(p => p.ModelPropertyID == forwardItem.ModelPropertyID);
                if (forwardItem.ModelProperty != null && forwardSolution.ReferencedModelIDs.Find("ItemName", forwardItem.ModelProperty.DefaultSourceName) == null)
                {
                    forwardSolution.ReferencedModelIDs.Add(forwardItem.ModelProperty.CreateIDReference());
                }
            }
            if (forwardItem.ModelProperty != null)
            {
                if (forwardItem.ModelProperty.DefinedByModelObjectID != null)
                {
                    Guid objectID = Guid.Empty;
                    Guid.TryParse(forwardItem.PropertyValue, out objectID);
                    if (objectID != Guid.Empty)
                    {
                        ObjectInstance instance = Solution.ObjectInstanceList.Find(i => i.ObjectInstanceID == objectID);
                        if (instance != null && forwardSolution.ReferencedModelIDs.Find("ItemName", instance.DefaultSourceName) == null)
                        {
                            forwardSolution.ReferencedModelIDs.Add(instance.CreateIDReference());
                        }
                    }
                }
                else if (forwardItem.ModelProperty.DefinedByEnumerationID != null && forwardItem.ModelProperty.DefinedByValueID == null)
                {
                    Value value = Solution.ValueList.Find(v => v.EnumerationID == forwardItem.ModelProperty.DefinedByEnumerationID && v.EnumValue == forwardItem.PropertyValue);
                    if (value != null && forwardSolution.ReferencedModelIDs.Find("ItemName", value.DefaultSourceName) == null)
                    {
                        forwardSolution.ReferencedModelIDs.Add(value.CreateIDReference());
                    }
                }
            }
            #endregion protected

            return(forwardItem);
        }