Exemple #1
0
        public static ItemType GetAssociationClass <ItemType>(string key)
            where ItemType : ActiveRecord <ItemType>, new()
        {
            TUPUX.Access.DataAccess dataAccess = new TUPUX.Access.DataAccess();

            StarUML.IUMLModelElement model = dataAccess.FindModel(key);

            if (model is StarUML.IUMLAssociation)
            {
                StarUML.IUMLAssociationClass associationClass = ((StarUML.IUMLAssociation)model).AssociationClass;
                if (associationClass != null)
                {
                    StarUML.IUMLClass classifier = associationClass.ClassSide;

                    ItemType item = new ItemType();

                    if (classifier != null && item.IsKindOf(classifier.GetClassName(), classifier.StereotypeName))
                    {
                        item.Load(classifier);
                        return(item);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        //RELATIONSHIPS
        public static ListType GetAssociationEndCollection <ItemType, ListType>(string key)
            where ItemType : ActiveRecord <ItemType>, new()
            where ListType : ActiveList <ItemType, ListType>, new()
        {
            ListType list = new ListType();

            TUPUX.Access.DataAccess dataAccess = new TUPUX.Access.DataAccess();

            StarUML.IUMLModelElement model = dataAccess.FindModel(key);

            if (model is StarUML.IUMLAssociation)
            {
                StarUML.IUMLAssociation classifier = (StarUML.IUMLAssociation)model;

                for (int i = 0; i < classifier.GetConnectionCount(); i++)
                {
                    ItemType item = new ItemType();
                    StarUML.IUMLAssociationEnd end = classifier.GetConnectionAt(i);

                    if (end != null &&
                        item.IsKindOf(end.GetClassName(), end.StereotypeName))
                    {
                        item.Load(end);
                        list.Add(item);
                    }
                }
            }
            return(list);
        }
Exemple #3
0
        /// <summary>
        /// Gets previus element associated to this element, by association type "dependency"
        /// </summary>
        /// <param name="element">Element</param>
        /// <param name="stereoTypeDependency">Stereotype</param>
        /// <returns>Previus element</returns>
        public static T GetPrev <T>(IUMLElement element, string stereoTypeDependency)
            where T : ActiveRecord <T>, new()
        {
            T item = new T();

            TUPUX.Access.DataAccess dataAccess = new TUPUX.Access.DataAccess();

            string key = element.Guid;

            StarUML.IUMLModelElement model = dataAccess.FindModel(key);

            try
            {
                if (model is StarUML.IUMLClassifier && model.GetSupplierDependencyCount() > 0)
                {
                    for (int i = 0; i < model.GetSupplierDependencyCount(); i++)
                    {
                        StarUML.IUMLDependency depencency = model.GetSupplierDependencyAt(i);
                        StarUML.IUMLClassifier prevModel  = (StarUML.IUMLClassifier)depencency.Client;

                        if (stereoTypeDependency.Equals(depencency.StereotypeName) &&
                            item.IsKindOf(prevModel.GetClassName(), prevModel.StereotypeName))
                        {
                            item.Load(prevModel);
                            return(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex);
            }
            return(null);
        }
Exemple #4
0
        public ListType Load()
        {
            TUPUX.Access.DataAccess dataAccess = new TUPUX.Access.DataAccess();
            StarUML.IUMLProject     prj        = dataAccess.GetCurrentProject();

            if (prj != null)
            {
                try
                {
                    List <StarUML.IUMLModelElement> listPkg = dataAccess.GetModelElements(prj);

                    List <StarUML.IUMLModelElement> list = dataAccess.GetModelElements((StarUML.IUMLClassifier)listPkg[0]);

                    foreach (StarUML.IUMLModelElement itemList in list)
                    {
                        ItemType item = new ItemType();
                        item.Load(itemList);
                        this.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    log.Error("", ex);
                }
            }
            return(this as ListType);
        }
Exemple #5
0
 /// <summary>
 /// Delete itseft
 /// </summary>
 public void Delete()
 {
     if ((State == RecordState.Loaded) || (State == RecordState.Modified))
     {
         TUPUX.Access.DataAccess dataAccess = new TUPUX.Access.DataAccess();
         dataAccess.DeleteModel(this.Guid);
     }
     MarkDeleted();
 }
Exemple #6
0
        public static ItemType GetDependencySupplier <ItemType>(string key)
            where ItemType : ActiveRecord <ItemType>, new()
        {
            TUPUX.Access.DataAccess dataAccess = new TUPUX.Access.DataAccess();

            StarUML.IUMLModelElement model = dataAccess.FindModel(key);

            if (model is StarUML.IUMLDependency || model is StarUML.IUMLRealization)
            {
                StarUML.IUMLClassifier classifier = (StarUML.IUMLClassifier)((StarUML.IUMLDependency)model).Supplier;
                ItemType item = new ItemType();

                if (classifier != null && item.IsKindOf(classifier.GetClassName(), classifier.StereotypeName))
                {
                    item.Load(classifier);
                    return(item);
                }
            }
            return(null);
        }
Exemple #7
0
 /// <summary>
 /// If the record contains Deleted or IsDeleted flag columns, sets them to true. If not, invokes Destroy()
 /// </summary>
 public static void Delete(string guid)
 {
     //return DeleteByParameter(BaseSchema.PrimaryKey.ColumnName, keyID, null);
     TUPUX.Access.DataAccess dataAccess = new TUPUX.Access.DataAccess();
     dataAccess.DeleteModel(guid);
 }
Exemple #8
0
        /// <summary>
        /// Saves this object's state to the selected Database.
        /// </summary>
        public void Save()
        {
            if ((State == RecordState.Created) || (State == RecordState.Modified))
            {
                #region Load Model
                PropertyInfo[] propertyList = typeof(T).GetProperties();

                TUPUX.Access.DataAccess  dataAccess = new TUPUX.Access.DataAccess();
                StarUML.IUMLModelElement model;

                if (this.State == RecordState.Created)
                {
                    string     methodName   = "Create" + this.GetUMLClassName().Replace("UML", String.Empty);
                    MethodInfo createMethod = typeof(StarUML.IUMLFactory).GetMethod(methodName);

                    List <object>   parameters    = new List <object>();
                    ParameterInfo[] parameterList = createMethod.GetParameters();

                    foreach (ParameterInfo parameterInfo in parameterList)
                    {
                        if (parameterInfo.Name.Equals("AOwner") ||
                            parameterInfo.Name.Equals("AClassifier") ||
                            parameterInfo.Name.Equals("ABehavioralFeature") ||
                            parameterInfo.Name.Equals("AEnumeration"))
                        {
                            parameters.Add(dataAccess.FindModel(this.Owner.Guid));
                        }
                        else
                        {
                            parameters.Add(null);
                        }
                    }

                    model = (StarUML.IUMLModelElement)createMethod.Invoke(dataAccess.Factory, parameters.ToArray());
                }
                else
                {
                    model = dataAccess.FindModel(this.GetKey().ToString());
                }
                #endregion

                #region Update Model Properties
                foreach (PropertyInfo property in propertyList)
                {
                    object[] attributeList = property.GetCustomAttributes(true);

                    foreach (object attribute in attributeList)
                    {
                        if (attribute is UMLPropertyAttribute)
                        {
                            try
                            {
                                UMLPropertyAttribute modelAttribute = (attribute as UMLPropertyAttribute);

                                if (!modelAttribute.IsReadOnly)
                                {
                                    object       value         = property.GetValue(this, null);
                                    PropertyInfo modelProperty = typeof(StarUML.IUMLModelElement).GetProperty(modelAttribute.PropertyName);

                                    if (modelProperty == null)
                                    {
                                        modelProperty = typeof(StarUML.IUMLGeneralizableElement).GetProperty(modelAttribute.PropertyName);
                                    }

                                    if (value != null)
                                    {
                                        if (modelAttribute.PropertyName.Equals("DirectionKind"))
                                        {
                                            modelProperty = typeof(StarUML.IUMLParameter).GetProperty(modelAttribute.PropertyName);
                                        }

                                        if (modelAttribute.PropertyName.Equals("StereotypeName"))
                                        {
                                            model.SetStereotype(value.ToString());
                                        }
                                        else if (modelAttribute.PropertyName.Equals("TypeExpression"))
                                        {
                                            if (model is StarUML.IUMLParameter)
                                            {
                                                ((StarUML.IUMLParameter)model).SetType2(value.ToString());
                                            }
                                            else if (model is StarUML.IUMLAttribute)
                                            {
                                                ((StarUML.IUMLAttribute)model).SetType2(value.ToString());
                                            }
                                        }
                                        else if (modelProperty != null)
                                        {
                                            modelProperty.SetValue(model, value, null);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Error("", ex);
                            }
                        }

                        if (attribute is UMLTagAttribute)
                        {
                            try
                            {
                                UMLTagAttribute tagAttribute = (UMLTagAttribute)attribute;
                                object          value        = property.GetValue(this, null);

                                if (value != null)
                                {
                                    if (property.PropertyType == typeof(String))
                                    {
                                        model.SetTaggedValueAsString(tagAttribute.ProfileName, tagAttribute.TagDefinitionSetName, tagAttribute.TagDefinitionName, value.ToString());
                                    }
                                    else if (property.PropertyType == typeof(Double))
                                    {
                                        model.SetTaggedValueAsReal(tagAttribute.ProfileName, tagAttribute.TagDefinitionSetName, tagAttribute.TagDefinitionName, (Double)value);
                                    }
                                    else if (property.PropertyType == typeof(int))
                                    {
                                        model.SetTaggedValueAsInteger(tagAttribute.ProfileName, tagAttribute.TagDefinitionSetName, tagAttribute.TagDefinitionName, (int)value);
                                    }
                                    else if (property.PropertyType == typeof(bool))
                                    {
                                        model.SetTaggedValueAsBoolean(tagAttribute.ProfileName, tagAttribute.TagDefinitionSetName, tagAttribute.TagDefinitionName, (bool)value);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Error("", ex);
                            }
                        }
                    }
                }
                #endregion

                this.Load(model);
                MarkLoaded();
            }
        }