/// <summary>
        /// Creates IR representation for given IUMLAttribute attribute
        /// </summary>
        /// <param name="attr">original IUMLAttribute attribute</param>
        /// <returns>Created IR attribute representation</returns>
        private IR.TableAttribute BuildIRTableAttribute(IUMLAttribute attr)
        {
            IR.TableAttribute irAttr = new IR.TableAttribute();

            irAttr.Name = attr.Name;
            irAttr.Type = attr.TypeExpression;

            irAttr.PrimaryKey = attr.GetTaggedValueAsBoolean(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN, Symbols.ERD_STEREOTYPE_PRIMARY_KEY);

            string nullOption = attr.GetTaggedValueAsEnum(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN, Symbols.ERD_STEREOTYPE_NULL_OPTION);

            irAttr.NotNull  = (nullOption == Symbols.ERD_STEREOTYPE_NOT_NULL);
            irAttr.Identity = (nullOption == Symbols.ERD_STEREOTYPE_IDENTITY);

            irAttr.ForeignKey = attr.GetTaggedValueAsBoolean(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN, Symbols.ERD_STEREOTYPE_FOREIGN_KEY);
            if (irAttr.ForeignKey)
            {
                IExtensibleModel refModel = attr.GetTaggedValueAsReference(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN, Symbols.ERD_STEREOTYPE_FOREIGN_KEY_REF);
                if (refModel != null)
                {
                    irAttr.ForeignKeyRef = refModel.Name;
                    string[] splittedPathName = refModel.Pathname.Split(new string[] { "::" }, System.StringSplitOptions.None);
                    irAttr.ForeignTableRef = splittedPathName[splittedPathName.Length - 2];
                }
            }
            return(irAttr);
        }
 /// <summary>
 /// Merge the given values with the current property value in the given model.  If the property is not set,
 /// the value is replaced
 /// </summary>
 /// <param name="model">The model to change.</param>
 /// <param name="propertyKey">The property to set</param>
 /// <param name="values">The value(s) to set for the property</param>
 public static void SetOrAppendProperty(this IExtensibleModel model, string propertyKey, params string[] values)
 {
     if (propertyKey != null)
     {
         model.ExtendedProperties.SetOrAppendProperty(propertyKey, values);
     }
 }
        /// <summary>
        /// Safely get the given property for the model as an array of string.
        /// </summary>
        /// <param name="model">The model to search</param>
        /// <param name="propertyKey">The given key of the property</param>
        /// <returns>The value of the property in the given model, or an empty array if the property is not set</returns>
        public static string[] GetPropertyAsArray(this IExtensibleModel model, string propertyKey)
        {
            string[] result = new string[0];
            if (model.IsPropertySet(propertyKey))
            {
                result = model.ExtendedProperties.GetPropertyAsArray(propertyKey);
            }

            return(result);
        }
 /// <summary>
 /// Copy Unset propeties from another extensible model to this one
 /// </summary>
 /// <param name="model"></param>
 /// <param name="newModel"></param>
 public static void UpdateProperties(this IExtensibleModel model, IExtensibleModel newModel)
 {
     if (model != null && newModel != null)
     {
         foreach (var item in newModel.ExtendedProperties)
         {
             model.SetProperty(item.Key, item.Value);
         }
     }
 }
 /// <summary>
 /// Copy the properties from the given model object
 /// </summary>
 /// <param name="model"></param>
 /// <param name="source"></param>
 public static void CopyPropertiesFrom(this IExtensibleModel model, IExtensibleModel source)
 {
     if (model != null && source != null)
     {
         foreach (var item in source.ExtendedProperties)
         {
             model.ExtendedProperties[item.Key] = item.Value;
         }
     }
 }
        /// <summary>
        /// Determine if the given proeprty is set in the model
        /// </summary>
        /// <param name="model">The model to check</param>
        /// <param name="propertyKey">The property to check</param>
        /// <returns>True if the property is set, otherwise false</returns>
        public static bool IsPropertySet(this IExtensibleModel model, string propertyKey)
        {
            bool result = false;

            if (propertyKey != null)
            {
                result = model.ExtendedProperties.IsPropertySet(propertyKey);
            }

            return(result);
        }
        /// <summary>
        /// Safely get the given property for the model
        /// </summary>
        /// <param name="model">The model to search</param>
        /// <param name="propertyKey">The given key of the property</param>
        /// <returns>The value of the property in the given model, or null if the property is not set</returns>
        public static string GetProperty(this IExtensibleModel model, string propertyKey)
        {
            string result = null;

            if (model.IsPropertySet(propertyKey))
            {
                result = model.ExtendedProperties.GetProperty(propertyKey);
            }

            return(result);
        }
Ejemplo n.º 8
0
 private static bool MergeProperty(IExtensibleModel dest, IExtensibleModel src, string propertyName)
 {
     if (string.IsNullOrEmpty(dest.GetProperty(propertyName)))
     {
         var propertyValue = src.GetProperty(propertyName);
         if (!string.IsNullOrEmpty(propertyValue))
         {
             dest.SetProperty(propertyName, propertyValue);
             return(true);
         }
     }
     return(false);
 }
        private void AddErdTableAttribute(IUMLPackage parentPackage, IUMLClass parentTable, string diagramName, IR.TableAttribute irAttr)
        {
            // Attribute creation + basic properties
            IUMLAttribute attr = m_UMLFactory.CreateAttribute(parentTable);

            attr.Name           = irAttr.Name;
            attr.TypeExpression = irAttr.Type;
            attr.SetStereotype2(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN);


            // Setting optional properties

            if (irAttr.PrimaryKey)
            {
                attr.SetTaggedValueAsBoolean(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN, Symbols.ERD_STEREOTYPE_PRIMARY_KEY, true);
            }

            string nullStatus;

            if (irAttr.Identity)
            {
                nullStatus = Symbols.ERD_STEREOTYPE_IDENTITY;
            }
            else if (irAttr.NotNull || irAttr.PrimaryKey)
            {
                nullStatus = Symbols.ERD_STEREOTYPE_NOT_NULL;
            }
            else
            {
                nullStatus = Symbols.ERD_STEREOTYPE_NULL;
            }

            attr.SetTaggedValueAsEnum(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN,
                                      Symbols.ERD_STEREOTYPE_NULL_OPTION, nullStatus);


            if (irAttr.ForeignKey)
            {
                attr.SetTaggedValueAsBoolean(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN, Symbols.ERD_STEREOTYPE_FOREIGN_KEY, true);
                string           relativePath = irAttr.ForeignTableRef + "::" + irAttr.ForeignKeyRef;
                IExtensibleModel refModel     = parentPackage.FindByRelativePathname(relativePath) as IExtensibleModel;
                if (refModel != null)
                {
                    attr.SetTaggedValueAsReference(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_COLUMN, Symbols.ERD_STEREOTYPE_FOREIGN_KEY_REF, refModel);
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Check that the extended properties in the two models are equal
 /// </summary>
 /// <param name="model">This model</param>
 /// <param name="other">The model being comparied to this model</param>
 /// <returns>true if the models are equal, or false otherwise</returns>
 public static bool CheckExtensionsEqual(this IExtensibleModel model, IExtensibleModel other)
 {
     return(model != null && other != null &&
            CheckEquality(model.ExtendedProperties, other.ExtendedProperties));
 }
 /// <summary>
 /// Populate the model extensions from a PSObject
 /// </summary>
 /// <param name="model">The model to populate</param>
 /// <param name="other">The PSObject to populate it from</param>
 public static void PopulateExtensions(this IExtensibleModel model, PSObject other)
 {
     model.ExtendedProperties.Populate(nameof(model.ExtendedProperties), other);
 }