显示序列消息

时间:2015-07-23 10:14:36

标签: c# enterprise-architect

我试图显示序列图中的消息,但到目前为止没有运气

这是我的代码:

函数browse以递归方式调用自身来发现图表,但是我对DiagramLinks或DiagramObjects没有运气,任何提示?

    private void browse(EA.Repository Repository, int ID, EA.ObjectType otype)
    {
        if (otype == EA.ObjectType.otPackage)
        {
            EA.Package pack = Repository.GetPackageByID(ID);
            foreach(EA.Element el in pack.Elements)
            {
                ID = el.ElementID;
                otype = el.ObjectType;
                this.browse(Repository, ID, otype);
            }
        }

        if (otype == EA.ObjectType.otElement)
        {
            EA.Element el = Repository.GetElementByID(ID);
            foreach (EA.Diagram diag in el.Diagrams)
            {
                ID = diag.DiagramID;
                otype = diag.ObjectType;
                this.browse(Repository, ID, otype);
            }
        }

        if (otype == EA.ObjectType.otDiagram)
        {
            EA.Diagram diag = Repository.GetDiagramByID(ID);
            //foreach (EA.DiagramLink dobj in diag.DiagramLinks)
            //{
                MessageBox.Show(diag.Name+diag.Type);
            //}
        }
    }

这是识别插件是否从主菜单,树视图或图表启动的功能。 它调用上面的函数Browse

    private string simplify(EA.Repository Repository, string Location)
    {

        String s = "";


        if (Location == "MainMenu") {
            s = "ROOT";
            MessageBox.Show("test");
        }

        else if (Location == "TreeView")
        {


            //Get the element in the tree view which was clicked
            Object obj = null;
            EA.ObjectType otype = Repository.GetTreeSelectedItem(out obj);

            //Si le type n'arrive pas a etre determiné
            if (!Enum.IsDefined(typeof(EA.ObjectType), otype))
            {
                //Should not occur
                String error = "Type indeterminé.";
                MessageBox.Show(error, "Erreur");
            }

                //The user clicked on a package - try to determine the stereotype
            else if (otype == EA.ObjectType.otPackage)
            {
                EA.Package p = (EA.Package)obj;
                //If the package has no superpackage, it must be the very top package
                //-> if the very top package is clicked, ALL will be validated
                int ID = p.PackageID;
                bool hasParent = false;
                try
                {
                    int dummy = p.ParentID;
                    if (dummy != 0)
                        hasParent = true;
                }
                catch (Exception e) { }

                if (!hasParent)
                {
                    s = "ROOT";
                }
                else
                {
                    this.browse(Repository, ID, otype);
                }
            }

            else
            {
                int ID = 0;

                if (otype == EA.ObjectType.otDiagram)
                {
                    ID = ((EA.Diagram)obj).DiagramID;
                    EA.Diagram d = Repository.GetDiagramByID(ID);
                    this.browse(Repository, ID, otype);
                }
                else if (otype == EA.ObjectType.otElement)
                {
                    ID = ((EA.Element)obj).ElementID;
                    EA.Element e = Repository.GetElementByID(ID);
                    this.browse(Repository, ID, otype);
                }


            }
            if (obj == null)
                s = "From Main Menu";
        }
        //If the users clicks into a diagram we must determine to which package
        //the diagram belongs
        else if (Location == "Diagram")
        {
            int ID = 0;
            try
            {
                Object obj = null;
                EA.ObjectType otype = Repository.GetContextItem(out obj);
                if (otype == EA.ObjectType.otDiagram)
                {
                    ID = ((EA.Diagram)obj).DiagramID;
                    EA.Diagram d = Repository.GetDiagramByID(ID);
                    this.browse(Repository, ID, otype);
                }
                else if (otype == EA.ObjectType.otElement)
                {
                    ID = ((EA.Element)obj).ElementID;
                    EA.Element e = Repository.GetElementByID(ID);
                    this.browse(Repository, ID, otype);
                }
                else
                {
                    Repository.Models.GetAt(0);
                    s = "From Main Menu";
                }
            }
            catch (Exception ex) 
            {                 }         
        }

        return s;


        this.encours = true;
    }

2 个答案:

答案 0 :(得分:1)

以下Perl脚本片段(希望它具有可读性)演示了如何获取连接器:

my $dia = $rep->GetDiagramByGUID("{7EA250AD-F37A-4e9a-9C52-BF8FCA3D87F7}"); # access the diagram
for (my $i = 0 ; $i < $dia->DiagramObjects->Count; $i++) { # every object inside the diagram
  my $do = $dia->DiagramObjects->GetAt($i);
  my $e = $rep->GetElementByID($do->ElementID); # the according element
  next unless $e->Type eq "Sequence"; # look only at life lines
  for (my $j = 0 ; $j < $e->Connectors->Count; $j++) { # now go through its connectors
    my $con = $e->Connectors->GetAt($j);
    print $con->Type . "\n"; # will print Sequence
  }
}

答案 1 :(得分:1)

非常感谢你的帮助托马斯 这是我在C#中翻译的代码

if (otype == EA.ObjectType.otDiagram)
        {
            EA.Diagram diag = Repository.GetDiagramByID(ID);
            foreach (EA.DiagramObject dobj in diag.DiagramObjects)
            {
                EA.Element el = Repository.GetElementByID(dobj.ElementID);
                foreach (EA.Connector con in el.Connectors)
                {
                    if (con.Type == "Sequence")
                    {
                           MessageBox.Show(con.Name);

                    }

                }
            }
        }