Exemple #1
0
        public BOM RetrieveBOM(string path)
        {
            var d = findDiagram("class", path);

            BOM m     = new BOM();
            var cache = new Dictionary <int, Class>();

            // populate edges

            ow.WriteLine("scanning connector edges:");
            ow.BeginChapter();
            foreach (EA.DiagramLink l in d.DiagramLinks)
            {
                EA.Connector    c      = repo.GetConnectorByID(l.ConnectorID);
                var             target = retrieveClassByID(cache, c.ClientID);
                var             source = retrieveClassByID(cache, c.SupplierID);
                Action <String> p      = (name) => ow.WriteLine("added {0} {1} [{2} -> {3}] <<{4}>>", name,
                                                                string.IsNullOrEmpty(c.Name) ? "(unnamed)" : c.Name, source.Name, target.Name, c.Stereotype);
                switch (c.Type)
                {
                case "Aggregation":
                    switch (c.Subtype)
                    {
                    case "Strong":
                        p("composition");
                        m.AddComposition(c.Name, c.Stereotype, source, target);
                        break;

                    default:
                        p("aggregation");
                        m.AddAggregation(c.Name, c.Stereotype, source, target);
                        break;
                    }
                    break;

                case "Association":
                    p("association");
                    m.AddAssociation(c.Name, c.Stereotype, source, target);
                    break;

                case "Generalization":
                    p("specialization");
                    m.AddSpecialization(c.Name, c.Stereotype, source, target);
                    break;

                default:
                    throw new NotSupportedException(string.Format("unsupported connector of type {0}", c.Type));
                }
            }
            ow.EndChapter();

            // populate nodes

            ow.WriteLine("rescanning all elements for unconnected class nodes:");
            ow.BeginChapter();
            foreach (EA.DiagramObject o in d.DiagramObjects)
            {
                EA.Element e = repo.GetElementByID(o.ElementID);
                switch (e.Type)
                {
                case "Class":
                    m.AddClass(retrieveClassByID(cache, o.ElementID));
                    break;

                default:
                    ow.WriteLine("skipping element {0} of type {1}...", e.Name, e.Type);
                    break;
                }
            }
            ow.EndChapter();

            return(m);
        }