示例#1
0
        private void exportToXML(EAPackage rootPackage)
        {
            AESHelper.isEncrpted = encrpytOption.Checked;
            FaceFileExporter faceFileExporter = new FaceFileExporter(this.repository);

            faceFileExporter.export(rootPackage, this.faceXMLSelectDialog.FileName);
        }
示例#2
0
 private void importPackage(EA.Package topPackage, EAPackage rootPackage)
 {
     EA.Package package = topPackage.Packages.AddNew(defaultPackageName, "");
     package.Element.Stereotype = rootPackage.StereoType;
     package.Update();
     topPackage.Packages.Refresh();
 }
示例#3
0
 public void generatePackageFromXMLNode(EAPackage parentPackage, XmlNode xmlNode)
 {
     foreach (XmlNode n in xmlNode.ChildNodes)
     {
         if (isPackage(n))
         {
             EAPackage package = createEAPackageFromXMLNode(n);
             parentPackage.addPackage(package);
             generatePackageFromXMLNode(package, n);
         }
         else if (isClass(n))
         {
             parentPackage.addClass(createEAClassFromXMLNode(n));
         }
     }
 }
示例#4
0
        public void export(EAPackage rootPackage, string filePath)
        {
            connectorSet.Clear();
            depSet.Clear();
            // create document with declaration
            XDocument xDocument = new XDocument(new XDeclaration("1.0", "UTF-8", null));

            // add element
            XElement rootElment = createRootElement();
            XElement element    = new XElement(this.xmiNameSapce + "Documentation",
                                               new XAttribute("exporter", "Enterprise Architect"), new XAttribute("exporterVersion", "6.5"));

            xDocument.Add(rootElment);
            rootElment.Add(element);
            XElement modelElement = new XElement(this.umlNameSapce + "Model",
                                                 new XAttribute(this.xmiNameSapce + "type", "Enterprise Architect"), new XAttribute("name", "EA_Model"));

            rootElment.Add(modelElement);

            initDocumentWithPackage(modelElement, rootPackage);

            XElement extendElement = new XElement(this.xmiNameSapce + "Extension",
                                                  new XAttribute("extender", "Enterprise Architect"), new XAttribute("extenderID", "6.5"));

            rootElment.Add(extendElement);


            XElement xmlEles = new XElement("elements");
            XElement xmlCon  = new XElement("connectors");
            XElement xmlPrim = new XElement("primitivetypes");
            XElement xmlDia  = new XElement("diagrams");

            extendElement.Add(xmlEles);
            extendElement.Add(xmlCon);
            extendElement.Add(xmlPrim);
            extendElement.Add(xmlDia);
            addExtension(xmlEles, xmlCon, xmlPrim, xmlDia, rootPackage.EaPackage);

            // Encrypt and save
            AESHelper.encryptXML(xDocument, filePath);
            // save element
            //    xDocument.Save(filePath);
        }
示例#5
0
        public EAPackage parse(string key)
        {
            XmlDocument xmlDoc = null;

            try
            {
                xmlDoc = AESHelper.decryptXML(filePath, key);
            } catch (Exception e)
            {
                MessageBox.Show("无法读取文件,请确保秘钥是否正确!");
                return(null);
            }
            XmlNode    faceModelNode    = xmlDoc.LastChild;
            XmlElement faceModelElement = faceModelNode as XmlElement;
            String     name             = faceModelElement.GetAttribute("name");
            EAPackage  rootPackage      = new EAPackage(name, defaultRootPackageSterotype);

            generatePackageFromXMLNode(rootPackage, faceModelNode);
            return(rootPackage);
        }
示例#6
0
        private void exportModelButton_Click(object sender, EventArgs e)
        {
            EA.Package topPackage  = getRootPackage();
            EAPackage  rootPackage = null;

            if (topPackage != null)
            {
                rootPackage           = new EAPackage(topPackage.Name, topPackage.PackageGUID);
                rootPackage.EaPackage = topPackage;
                initPackage(topPackage, rootPackage);
            }
            if (rootPackage == null)
            {
                MessageBox.Show(String.Format("Sorry, can't export EA model {0} to face model file for no rootpackge!", topPackage.Name));
            }
            else
            {
                this.exportToXML(rootPackage);
                MessageBox.Show(String.Format("Successfully to export EA Project {0} to face model", this.repository.ConnectionString));
                this.Dispose();
            }
        }
示例#7
0
        private void initPackage(EA.Package topPackage, EAPackage rootPackage)
        {
            foreach (EA.Package p in topPackage.Packages)
            {
                EAPackage newPackage = new EAPackage(p.Name, p.PackageGUID);
                newPackage.EaPackage = p;

                foreach (EA.Element element in p.Elements)
                {
                    EAClass eAClass = new EAClass(element.Name, element.ElementGUID);
                    eAClass.Element = element;
                    foreach (EA.Attribute attribute in element.Attributes)
                    {
                        EAAttribute eAAttribute = new EAAttribute(attribute.Name, attribute.AttributeGUID);
                        eAAttribute.Attribute = attribute;
                        eAClass.addAttribute(eAAttribute);
                    }
                    newPackage.addClass(eAClass);
                }
                rootPackage.addPackage(newPackage);
                initPackage(p, newPackage);
            }
        }
示例#8
0
        private void initPackage(EA.Package topPackage, EAPackage rootPackage)
        {
            EA.Package pacakge = topPackage.Packages.AddNew(rootPackage.Name, "");
            pacakge.Update();
            pacakge.Element.Stereotype = rootPackage.StereoType;
            pacakge.Update();
            List <EAClass> remainEAClass        = new List <EAClass>();
            List <int>     remaineElementIDList = new List <int>();

            foreach (EAClass c in rootPackage.EAClass)
            {
                EA.Element element = createEAClass(pacakge, c);
                foreach (EAAttribute attribue in c.Attributes)
                {
                    if (attribue.IsEAClass)
                    {
                        remainEAClass.Add(new EAClass(attribue.Name, attribue.Type, attribue.ID));
                        remaineElementIDList.Add(element.ElementID);
                    }
                    else
                    {
                        EA.Attribute attribute = element.Attributes.AddNew(attribue.Name, attribue.Type);
                        attribute.Update();
                    }
                }
                element.Attributes.Refresh();
                element.Update();
                foreach (string axis in c.MeasurementAxisList)
                {
                    measurementAxisMap[axis] = c.ID;
                }
                eAIdElementIdMap[c.ID] = element.ElementID;
                eAElementEAClassMap[element.ElementID] = c;
            }
            foreach (EAClass c in remainEAClass)
            {
                EA.Element element = createEAClass(pacakge, c);
                eAIdElementIdMap[c.ID] = element.ElementID;
                eAElementEAClassMap[element.ElementID] = c;
                element.Update();
            }
            pacakge.Elements.Refresh();
            foreach (EAPackage p in rootPackage.EAPackages)
            {
                initPackage(pacakge, p);
            }
            topPackage.Packages.Refresh();
            EA.Diagram diagram = pacakge.Diagrams.AddNew(rootPackage.Name, "");
            diagram.ExtendedStyle = "ShowTags=1;";
            diagram.Update();
            EADirection eADirection = new EADirection();

            foreach (EA.Package p in pacakge.Packages)
            {
                EADirection      direction = eADirection.nextEADirection();
                EA.DiagramObject d         = diagram.DiagramObjects.AddNew(direction.ToString(), "");
                d.ElementID = p.Element.ElementID;;
                d.Update();
            }
            foreach (EA.Element e in pacakge.Elements)
            {
                EADirection      direction = eADirection.nextEADirection();
                EA.DiagramObject d         = diagram.DiagramObjects.AddNew(direction.ToString(), "");
                d.ElementID = e.ElementID;
                d.Update();
                int id = this.addRealizeRelation(e);
                if (id > 0)
                {
                    d = diagram.DiagramObjects.AddNew(direction.ToString(), "");
                    try
                    {
                        d.ElementID = this.repository.GetElementByID(id).ElementID;
                        d.Update();
                    } catch (Exception) {
                    }
                    // add aixs
                    int addAixsDiagramId = this.addAxisRelation(eAElementEAClassMap[e.ElementID].RealizeClassID);
                    if (addAixsDiagramId > 0)
                    {
                        direction = eADirection.nextEADirection();
                        d         = diagram.DiagramObjects.AddNew(direction.ToString(), "");
                        try
                        {
                            d.ElementID = this.repository.GetElementByID(addAixsDiagramId).ElementID;
                            d.Update();
                        }
                        catch (Exception) { }
                    }
                }
            }
            for (int i = 0; i < remainEAClass.Count; i++)
            {
                this.addMessagePortRelation(diagram, remaineElementIDList[i], eAIdElementIdMap[remainEAClass[i].ID]);
            }
        }
示例#9
0
        private void initDocumentWithPackage(XElement rootElement, EAPackage rootPackage)
        {
            foreach (EAPackage p in rootPackage.EAPackages)
            {
                XElement element = new XElement("packagedElement",
                                                new XAttribute(this.xmiNameSapce + "type", "uml:Package"),
                                                new XAttribute(this.xmiNameSapce + "id", handleGUID(p.StereoType)),
                                                new XAttribute("name", p.Name));
                rootElement.Add(element);

                foreach (EAClass c in p.EAClass)
                {
                    XElement classElement = new XElement("packagedElement",
                                                         new XAttribute(this.xmiNameSapce + "type", "uml:Class"),
                                                         new XAttribute(this.xmiNameSapce + "id", handleGUID(c.StereoType)),
                                                         new XAttribute("name", c.Name));
                    element.Add(classElement);
                    foreach (EA.Attribute att in c.Element.Attributes)
                    {
                        XElement xAttributeElement = new XElement("ownedAttribute",
                                                                  new XAttribute(this.xmiNameSapce + "type", "uml:Property"),
                                                                  new XAttribute("name", att.Name),
                                                                  new XAttribute(this.xmiNameSapce + "id", handleGUID(att.AttributeGUID)),
                                                                  new XAttribute("visibility",
                                                                                 att.Visibility.ToLower()));
                        classElement.Add(xAttributeElement);
                        xAttributeElement.Add(new XElement("lowerValue", new XAttribute("value", att.LowerBound)));
                        xAttributeElement.Add(new XElement("upperValue", new XAttribute("value", att.UpperBound)));
                        try
                        {
                            xAttributeElement.Add(new XElement("type", new XAttribute(this.xmiNameSapce + "idref",
                                                                                      handleGUID(this.repository.GetElementByID(att.ClassifierID).ElementGUID)
                                                                                      )));
                        }
                        catch
                        {
                            xAttributeElement.Add(new XElement("type", new XAttribute(this.xmiNameSapce + "idref",
                                                                                      att.Type
                                                                                      )));
                        }
                    }
                    foreach (EA.Element e in c.Element.EmbeddedElements)
                    {
                        XElement xElement = new XElement("ownedAttribute",
                                                         new XAttribute(this.xmiNameSapce + "type", "uml:" + e.Type),
                                                         new XAttribute(this.xmiNameSapce + "id", handleGUID(e.ElementGUID)),
                                                         new XAttribute("name", e.Name), new XAttribute("aggregation", "composite"));
                        classElement.Add(xElement);
                        foreach (EA.Connector connector in e.Connectors)
                        {
                            if (connectorSet.Contains(connector.ConnectorGUID))
                            {
                                continue;
                            }
                            if (connector.Type == "InformationFlow")
                            {
                                XElement connectorElement = new XElement("packagedElement",
                                                                         new XAttribute(this.xmiNameSapce + "type", "uml:" + connector.Type),
                                                                         new XAttribute(this.xmiNameSapce + "id", handleGUID(connector.ConnectorGUID)),
                                                                         new XAttribute("informationTarget", handleGUID(this.repository.GetElementByID(connector.SupplierID).ElementGUID)),
                                                                         new XAttribute("informationSource", handleGUID(this.repository.GetElementByID(connector.ClientID).ElementGUID)));
                                element.Add(connectorElement);
                                connectorSet.Add(connector.ConnectorGUID);
                            }
                        }
                    }
                    foreach (EA.Connector connector in c.Element.Connectors)
                    {
                        if (connectorSet.Contains(connector.ConnectorGUID))
                        {
                            continue;
                        }
                        if (connector.Type == "Realisation" || connector.Type == "Realization")
                        {
                            XElement connectorElement = new XElement("packagedElement",
                                                                     new XAttribute(this.xmiNameSapce + "type", "uml:" + connector.Type),
                                                                     new XAttribute(this.xmiNameSapce + "id", handleGUID(connector.ConnectorGUID)),
                                                                     new XAttribute("supplier", handleGUID(this.repository.GetElementByID(connector.SupplierID).ElementGUID)),
                                                                     new XAttribute("client", handleGUID(this.repository.GetElementByID(connector.ClientID).ElementGUID)));
                            element.Add(connectorElement);
                            connectorSet.Add(connector.ConnectorGUID);
                        }
                        else if (connector.Type == "Association")
                        {
                            XElement connectorElement = new XElement("packagedElement",
                                                                     new XAttribute(this.xmiNameSapce + "type", "uml:" + connector.Type),
                                                                     new XAttribute("name", connector.Name),
                                                                     new XAttribute(this.xmiNameSapce + "id", handleGUID(connector.ConnectorGUID)));
                            element.Add(connectorElement);
                            String   clientID  = "EAID_src" + Guid.NewGuid().ToString();
                            String   supplieID = "EAID_tgt" + Guid.NewGuid().ToString();
                            XElement s         = new XElement("memberEnd",
                                                              new XAttribute(this.xmiNameSapce + "idref", clientID));
                            XElement t = new XElement("memberEnd",
                                                      new XAttribute(this.xmiNameSapce + "idref", supplieID));
                            connectorElement.Add(s);
                            connectorElement.Add(t);
                            XElement sEnd = new XElement("ownedEnd",
                                                         new XAttribute(this.xmiNameSapce + "type", "uml:Property"),
                                                         new XAttribute(this.xmiNameSapce + "id", clientID), new XAttribute("association", handleGUID(connector.ConnectorGUID)));
                            sEnd.Add(new XElement("type",
                                                  new XAttribute(this.xmiNameSapce + "idref", handleGUID(this.repository.GetElementByID(connector.ClientID).ElementGUID))));

                            XElement oEnd = new XElement("ownedEnd",
                                                         new XAttribute(this.xmiNameSapce + "type", "uml:Property"),
                                                         new XAttribute(this.xmiNameSapce + "id", supplieID), new XAttribute("association", handleGUID(connector.ConnectorGUID)));
                            oEnd.Add(new XElement("type",
                                                  new XAttribute(this.xmiNameSapce + "idref",
                                                                 handleGUID(this.repository.GetElementByID(connector.SupplierID).ElementGUID))));
                            connectorElement.Add(sEnd);
                            connectorElement.Add(oEnd);
                            connectorSet.Add(connector.ConnectorGUID);
                        }
                        else if (connector.Type == "InformationFlow")
                        {
                            XElement connectorElement = new XElement("packagedElement",
                                                                     new XAttribute(this.xmiNameSapce + "type", "uml:" + connector.Type),
                                                                     new XAttribute(this.xmiNameSapce + "id", handleGUID(connector.ConnectorGUID)),
                                                                     new XAttribute("informationTarget", handleGUID(this.repository.GetElementByID(connector.SupplierID).ElementGUID)),
                                                                     new XAttribute("informationSource", handleGUID(this.repository.GetElementByID(connector.ClientID).ElementGUID)));
                            element.Add(connectorElement);
                            connectorSet.Add(connector.ConnectorGUID);
                        }
                    }
                }
                foreach (EA.Connector connector in p.EaPackage.Connectors)
                {
                    if (connectorSet.Contains(connector.ConnectorGUID))
                    {
                        continue;
                    }
                    if (connector.Type == "Dependency")
                    {
                        string sourceId = handleGUID(this.repository.GetElementByID(connector.ClientID).ElementGUID);
                        string tgtId    = handleGUID(this.repository.GetElementByID(connector.SupplierID).ElementGUID);

                        if (depSet.Contains(sourceId + "_" + tgtId))
                        {
                            continue;
                        }
                        depSet.Add(sourceId + "_" + tgtId);

                        XElement dependency = new XElement("packagedElement",
                                                           new XAttribute(this.xmiNameSapce + "type", "uml:" + connector.Type),
                                                           new XAttribute(this.xmiNameSapce + "id", handleGUID(connector.ConnectorGUID)),
                                                           new XAttribute("supplier", tgtId
                                                                          ),
                                                           new XAttribute("client", sourceId)
                                                           );
                        element.Add(dependency);
                        connectorSet.Add(connector.ConnectorGUID);
                    }
                }

                initDocumentWithPackage(element, p);
            }
        }