Beispiel #1
0
        /// <summary>
        /// Reads the associations.
        /// </summary>
        private void ReadAssociations()
        {
            foreach (XmlNode assocNode in _xdoc.SelectNodes("/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Association/UML:Association.connection", _nsManager))
            {
                XmlNodeList assocEndNodes = assocNode.SelectNodes("UML:AssociationEnd", _nsManager);

                string typeName;
                bool   isPrimitive;
                bool   classExists;

                XmlNode node2 = assocEndNodes[0].SelectSingleNode("UML:AssociationEnd.participant/UML:Class", _nsManager);
                string  id    = node2.Attributes["xmi.idref"].Value;
                GetTypeInfo(id, out typeName, out isPrimitive);

                ClassNameInfo nameHelper = new ClassNameInfo(_initialNamespace, typeName);
                Entity        source     = (Entity)_layer.AddTypeIfNotExists(nameHelper, false, out classExists);
                Debug.Assert(isPrimitive == false && classExists == true);
                XmlNode      multiplicityNode   = assocEndNodes[0].SelectSingleNode("UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange", _nsManager);
                Multiplicity sourceMultiplicity = GetMultiplicityFromValue(multiplicityNode.Attributes["lower"].Value, multiplicityNode.Attributes["upper"].Value);

                node2 = assocEndNodes[1].SelectSingleNode("UML:AssociationEnd.participant/UML:Class", _nsManager);
                id    = node2.Attributes["xmi.idref"].Value;
                GetTypeInfo(id, out typeName, out isPrimitive);
                Entity target = (Entity)_layer.AddTypeIfNotExists(nameHelper, false, out classExists);
                Debug.Assert(isPrimitive == false && classExists == true);
                multiplicityNode = assocEndNodes[1].SelectSingleNode("UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange", _nsManager);
                Multiplicity targetMultiplicity = GetMultiplicityFromValue(multiplicityNode.Attributes["lower"].Value, multiplicityNode.Attributes["upper"].Value);

                Association assoc = source.AddAssociationTo(target);
                assoc.SourceMultiplicity = sourceMultiplicity;
                assoc.TargetMultiplicity = targetMultiplicity;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reads the generalizations.
        /// </summary>
        private void ReadGeneralizations()
        {
            foreach (XmlNode node in _xdoc.SelectNodes("/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Generalization", _nsManager))
            {
                string  typeName;
                bool    isPrimitive;
                bool    classExists;
                XmlNode node2 = node.SelectSingleNode("UML:Generalization.parent/UML:Class", _nsManager);
                string  id    = node2.Attributes["xmi.idref"].Value;
                GetTypeInfo(id, out typeName, out isPrimitive);

                ClassNameInfo nameHelper = new ClassNameInfo(_initialNamespace, typeName);
                Entity        parent     = (Entity)_layer.AddTypeIfNotExists(nameHelper, false, out classExists);

                Debug.Assert(isPrimitive == false && classExists == true);
                node2 = node.SelectSingleNode("UML:Generalization.child/UML:Class", _nsManager);
                id    = node2.Attributes["xmi.idref"].Value;
                GetTypeInfo(id, out typeName, out isPrimitive);
                nameHelper = new ClassNameInfo(_initialNamespace, typeName);
                Entity child = (Entity)_layer.AddTypeIfNotExists(nameHelper, false, out classExists);
                Debug.Assert(isPrimitive == false && classExists == true);

                child.BaseType = parent.Name;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Recherche d'un modèle par son nom
        /// </summary>
        /// <param name="fullName">The full name.</param>
        /// <returns></returns>
        private DataType FindModelClassByName(string fullName)
        {
            ClassNameInfo nameHelper = new ClassNameInfo(_initialNamespace, fullName);

            // On recherche d'abord dans le modèle courant
            DataType clazz = _layer.FindType(nameHelper.FullName);

            if (clazz == null)
            {
                // Puis dans les les systèmes référencés
                foreach (ExternalComponent sys in _layer.Component.Model.ExternalComponents)
                {
                    CandleModel model = sys.ReferencedModel;
                    if (model != null && model.DataLayer != null)
                    {
                        clazz = model.DataLayer.FindType(nameHelper.FullName);
                        if (clazz != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(clazz);
        }
Beispiel #4
0
        /// <summary>
        /// Creates the model.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        private Entity CreateModel(XmlNode node)
        {
            string        typeName = node.Attributes["name"].Value;
            bool          classExists;
            ClassNameInfo nameHelper = new ClassNameInfo(_initialNamespace, typeName);
            Entity        model      = (Entity)_layer.AddTypeIfNotExists(nameHelper, false, out classExists);

            model.Properties.Clear();
            return(model);
        }
Beispiel #5
0
        /// <summary>
        /// Création d'un modèle de type classe
        /// </summary>
        /// <param name="clazz">Type clr de la classe</param>
        /// <param name="createEnum">if set to <c>true</c> [create enum].</param>
        /// <returns></returns>
        private DataType CreateModel(Type clazz, bool createEnum)
        {
            bool          classExists;
            ClassNameInfo nameHelper = new ClassNameInfo(_initialNamespace, clazz.FullName);
            DataType      model      = _layer.AddTypeIfNotExists(nameHelper.Namespace, clazz.Name, createEnum, out classExists);

            CustomAttributeReflector c = new CustomAttributeReflector(clazz);

            if (c.MoveTo(typeof(XmlRootAttribute)))
            {
                model.XmlName       = c.GetPropertyValue <string>("ElementName");
                _layer.XmlNamespace = c.GetPropertyValue <string>("Namespace");
            }

            return(model);
        }
Beispiel #6
0
        /// <summary>
        /// Résolution du nom du fichier en remplacçant les mots-clés par leurs valeurs courantes.
        /// </summary>
        /// <param name="element">Element concerné par la génération</param>
        /// <param name="filePattern">Pattern du nom de fichier</param>
        /// <returns>Chaine résolue</returns>
        /// <remarks>
        /// Pattern dans le nom du fichier
        /// '~' : indique de mettre le fichier tel quel à la racine
        /// [codeFolder]|[code] : Répertoire de code (racine ou app_code)
        /// [namespace]|[nspc]  : namespace hierarchie
        /// [strategyName]|[sn] : Nom de la strategie
        /// ex : [codeFolder]/[namespace]/xxx.cs
        /// </remarks>
        /// <exception cref="Exception">Erreur de syntaxe dans le pattern</exception>
        private string ResolvePattern(ICustomizableElement element, string filePattern)
        {
            // Pour que le replace marche dans tous les cas, on va d'abord parcourir la chaine
            // pour mettre tous les mot-clés en minuscules sans toucher aux autres caractères.
            char[] buffer    = filePattern.ToCharArray();
            bool   inKeyword = false;

            for (int i = 0; i < buffer.Length; i++)
            {
                char ch = buffer[i];
                if (ch == ']')
                {
                    if (!inKeyword)
                    {
                        throw new Exception(
                                  String.Format("Syntax error in the generated file pattern '{1}' for element {0}",
                                                element.Name, filePattern));
                    }
                    inKeyword = false;
                }
                else if (ch == '[')
                {
                    if (inKeyword)
                    {
                        throw new Exception(
                                  String.Format("Syntax error in the generated file pattern '{1}' for element {0}",
                                                element.Name, filePattern));
                    }
                    inKeyword = true;
                }
                else if (inKeyword)
                {
                    buffer[i] = Char.ToLower(ch);
                }
            }

            if (inKeyword)
            {
                throw new Exception(
                          String.Format("Syntax error in the generated file pattern '{1}' for element {0}", element.Name,
                                        filePattern));
            }

            // Remplacement des mots-clés
            string tmpFileName = new String(buffer);

            tmpFileName = tmpFileName.Replace("[code]", "[codefolder]");
            tmpFileName = tmpFileName.Replace("[sn]", "[strategyname]");
            tmpFileName = tmpFileName.Replace("[nspc]", "[namespace]");

            tmpFileName = tmpFileName.Replace("[codefolder]", Context.RelativeProjectCodeFolder);
            tmpFileName = tmpFileName.Replace("[strategyname]", DisplayName);

            if (tmpFileName.Contains("[namespace]"))
            {
                // Arborescence correspondant au namespace
                string ns = String.Empty;
                if (element != null)
                {
                    ClassNameInfo cni = new ClassNameInfo(element.FullName);
                    ns = cni.Namespace.Replace('.', Path.DirectorySeparatorChar);
                }
                tmpFileName = tmpFileName.Replace("[namespace]", ns);
            }

            return(tmpFileName);
        }
Beispiel #7
0
        /// <summary>
        /// Alerts listeners that a property for an element has changed.
        /// </summary>
        /// <param name="e">Provides data for the ElementPropertyChanged event.</param>
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            #region Condition

            if (e.ModelElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.IsSerializing ||
                e.ModelElement.Store.InUndoRedoOrRollback)
            {
                return;
            }

            #endregion

            #region Traitement

            if (e.DomainProperty.Id == NamedElement.NameDomainPropertyId)
            {
                string name = ((NamedElement)e.ModelElement).Name;
                if (string.IsNullOrEmpty(name))
                {
                    return;
                }

                if (e.ModelElement is DataType)
                {
                    DataType      type    = (DataType)e.ModelElement;
                    ClassNameInfo cni     = new ClassNameInfo(type.Package.Name, (string)e.OldValue);
                    string        oldName = cni.FullName;
                    type.XmlName = name;

                    // Mise à jour de tous les types dans les opérations
                    foreach (SoftwareLayer layer in type.Package.Layer.Component.Layers)
                    {
                        if (layer is InterfaceLayer)
                        {
                            foreach (ServiceContract port in ((InterfaceLayer)layer).ServiceContracts)
                            {
                                foreach (Operation op in port.Operations)
                                {
                                    if (op.Type == oldName)
                                    {
                                        op.Type = name;
                                    }
                                    foreach (Argument arg in op.Arguments)
                                    {
                                        if (arg.Type == oldName)
                                        {
                                            arg.Type = name;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //if( e.ModelElement is DataLayer )
                //{
                //    ( (DataLayer)e.ModelElement ).XmlNamespace = name;
                //}

                if (e.ModelElement is Property)
                {
                    ((Property)e.ModelElement).XmlName = name;
                }
            }

            #endregion
        }
Beispiel #8
0
        /// <summary>
        /// Récupération des classes d'une assembly
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        /// <param name="selectedClasses">The selected classes.</param>
        public void AddAssembly(string fullPath, IList selectedClasses)
        {
            using (AssemblyResolver resolver = new AssemblyResolver(fullPath))
            {
                using (Transaction transaction = _layer.Store.TransactionManager.BeginTransaction("Import models"))
                {
                    transaction.Context.ContextInfo.Add("ReverseInProgress", true);

                    DataLayer modelsLayer = _layer.SoftwareComponent.DataLayer;

                    // 1er passage : Création des modéles
                    foreach (Type clazz in selectedClasses)
                    {
                        ServiceContract port = new ServiceContract(_layer.Store);
                        port.Name     = clazz.Name;
                        port.RootName = clazz.Name;
                        _layer.ServiceContracts.Add(port);

                        foreach (MethodInfo method in clazz.GetMethods(BindingFlags.Public | BindingFlags.Instance))
                        {
                            Operation op = new Operation(port.Store);
                            port.Operations.Add(op);
                            op.Name = method.Name;
                            string typeName = GetTypeElement(method, method.ReturnType);
                            op.Type         = typeName;
                            op.IsCollection = IsListe(method.ReturnType);
                            if (!Utils.StringStartsWith(op.Type, "System.") && !Utils.StringStartsWith(op.Type, "Microsoft."))
                            {
                                if (typeName != null)
                                {
                                    bool          exists;
                                    ClassNameInfo cni    = new ClassNameInfo(typeName);
                                    Entity        target = (Entity)modelsLayer.AddTypeIfNotExists(cni.Namespace, cni.ClassName, false, out exists);
                                    if (!exists)
                                    {
                                        CreateEntity(target, method.ReturnType);
                                    }
                                    op.Type = target.Name;
                                }
                            }
                            // TODO a revoir
                            if (op.Type == "System.Void")
                            {
                                op.Type = "void";
                            }

                            foreach (ParameterInfo parm in method.GetParameters())
                            {
                                Argument arg = new Argument(port.Store);
                                arg.Name = parm.Name;
                                typeName = GetTypeElement(parm, parm.ParameterType);
                                arg.Type = typeName;
                                if (!Utils.StringStartsWith(arg.Type, "System.") && !Utils.StringStartsWith(arg.Type, "Microsoft."))
                                {
                                    if (typeName != null)
                                    {
                                        ClassNameInfo cni = new ClassNameInfo(typeName);
                                        bool          exists;
                                        Entity        target = (Entity)modelsLayer.AddTypeIfNotExists(cni.Namespace, cni.ClassName, false, out exists);
                                        if (!exists)
                                        {
                                            CreateEntity(target, parm.ParameterType);
                                        }
                                        arg.Type = target.Name;
                                    }
                                }

                                // TODO a revoir
                                if (arg.Type == "System.Void")
                                {
                                    arg.Type = "void";
                                }

                                arg.IsCollection = IsListe(parm.ParameterType);
                                arg.Direction    = parm.IsOut ? ArgumentDirection.Out : ArgumentDirection.In;
                                op.Arguments.Add(arg);
                            }
                        }
                    }
                    transaction.Commit();
                }
            }
        }