Exemplo n.º 1
0
        private void BuildModelNamespaces(XmlNode elementsExtension, List <string> namespaceNodeIdList, string modelFile)
        {
            foreach (string namespaceNodeId in namespaceNodeIdList)
            {
                XmlNode namespaceExtensionNode = elementsExtension.SelectSingleNode(string.Format(NodeElementByIdRef, namespaceNodeId), _currentNsManager);
                XmlNode namespaceNode          = _currentEap.SelectSingleNode(string.Format(NodeNamespaceByIdRef, namespaceNodeId), _currentNsManager);

                XmlAttribute   authorAttribute = namespaceExtensionNode.SelectSingleNode(NodeProject, _currentNsManager).Attributes[PropertyAuthor];
                ModelNamespace nmspace         = new ModelNamespace()
                {
                    Label   = namespaceExtensionNode.Attributes[PropertyName].Value,
                    Name    = namespaceExtensionNode.SelectSingleNode(NodeProperties, _currentNsManager).Attributes[PropertyAlias].Value,
                    Comment = namespaceExtensionNode.SelectSingleNode(NodeProperties, _currentNsManager).Attributes[PropertyComment].Value,
                    Creator = (authorAttribute == null) ? string.Empty : authorAttribute.Value,
                    Model   = _currentModelRoot
                };
                if (string.IsNullOrEmpty(nmspace.Comment))
                {
                    RegisterError(Category.Doc, "Le package [" + nmspace.Label + "] n'a pas de commentaire.");
                }

                BuildNamespaceClasses(nmspace, namespaceNode, elementsExtension, modelFile);
                _currentModelRoot.AddNamespace(nmspace);
            }

            foreach (string nsName in _currentModelRoot.Namespaces.Keys)
            {
                ModelNamespace nmsp = _currentModelRoot.Namespaces[nsName];
                foreach (ModelClass classe in nmsp.ClassList)
                {
                    foreach (ModelProperty property in classe.PropertyList)
                    {
                        if (_regexICollection.IsMatch(property.DataType))
                        {
                            string innerType = _regexICollection.Replace(property.DataType, "$1");
                            if (!string.IsNullOrEmpty(innerType))
                            {
                                if (!_classByNameMap.ContainsKey(innerType))
                                {
                                    if (!ParserHelper.IsPrimitiveType(innerType))
                                    {
                                        RegisterError(Category.Bug, "Ajout des usings dans la classe [" + classe.Name + "] : la classe [" + innerType + "] n'a pas été trouvée.");
                                    }
                                }
                                else
                                {
                                    ModelClass usingClasse = _classByNameMap[innerType];
                                    classe.AddUsing(usingClasse.Namespace);
                                }
                            }
                            else
                            {
                                RegisterError(Category.Bug, "Impossible de récupérer le type générique de la collection pour la propriété [" + property.Name + "] de la classe [" + property.Class.Name + "].");
                            }
                        }

                        if (classe.ParentClass != null)
                        {
                            classe.AddUsing(classe.ParentClass.Namespace);
                        }
                    }
                }
            }
        }