Example #1
0
        //<y:EdgeLabel alignment="center" distance="2.0"
        //  fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false"
        //  hasLineColor="false" modelName="six_pos" modelPosition="tail"
        //  preferredPlacement="anywhere" ratio="0.5"
        //  textColor="#000000" visible="true" width="75.384765625">select,update
        //</y:EdgeLabel>
        public XElement CreateEdgeElement(string Id, DBEntryDescriptor parentNode, DBEntryDescriptor childNode, string edgeLabel)
        {
            XElement xmlEdge = new XElement(GraphNS + "edge",
                                            new XAttribute("id", Id),                  //childNode.Id + "_" + parentNode.Id
                                            new XAttribute("source", childNode.Path),  //Id
                                            new XAttribute("target", parentNode.Path), //Id
                                            new XElement(GraphNS + "data",
                                                         new XAttribute("key", "d6"),  //EDGE_ID
                                                         new XElement(YedNS + "PolyLineEdge",
                                                                      new XElement(YedNS + "LineStyle",
                                                                                   new XAttribute("type", "dashed"),
                                                                                   new XAttribute("width", "1.0"),
                                                                                   new XAttribute("color", "#000000")
                                                                                   ),
                                                                      new XElement(YedNS + "Arrows",
                                                                                   new XAttribute("source", "none"),
                                                                                   new XAttribute("target", "standard")
                                                                                   ),
                                                                      new XElement(YedNS + "EdgeLabel",
                                                                                   new XAttribute("fontSize", "9"),
                                                                                   new XAttribute("fontStyle", "plain"),
                                                                                   new XAttribute("width", "1.0"),
                                                                                   new XAttribute("alignment", "center"),
                                                                                   edgeLabel
                                                                                   ),
                                                                      new XElement(YedNS + "BendStyle",
                                                                                   new XAttribute("smoothed", "false")
                                                                                   )
                                                                      )
                                                         )
                                            );

            return(xmlEdge);
        }
Example #2
0
        private NodeDescriptor CreateNewNode(DBEntryDescriptor entry)
        {
            NodeDescriptor newNode = new NodeDescriptor();

            newNode.Name        = entry.Name;
            newNode.Id          = entry.Id;
            newNode.Description = (String.IsNullOrEmpty(entry.Description) ? entry.DbType : entry.Description);
            //if (!string.IsNullOrEmpty(entry.Url)) newNode.Url = @"javascript:void(window.open('" + entry.Url + "','_blank'))";

            switch (ShapeType)
            {
            case ShapeTypes.Figure:
                newNode.Shape = "rectangle";
                break;

            case ShapeTypes.Image:
                newNode.Shape = entry.Shape;
                if (String.IsNullOrEmpty(newNode.Shape))
                {
                    newNode.Shape = "ellipse";
                }
                break;

            case ShapeTypes.Picture:
                newNode.IsImage            = true;
                newNode.ActiveImageName    = "user_on.jpg";
                newNode.NonActiveImageName = "user_off.jpg";
                break;

            default:
                break;
            }
            SetColor(true, ref newNode);

            return(newNode);
        }
Example #3
0
 public void LoadData(ref Dictionary <string, DBEntryDescriptor> DBObjects)
 {
     using (SqlConnection cnn = new SqlConnection(DBConnectionString))
     {
         SqlCommand cmd = new SqlCommand(Request, cnn);
         cmd.CommandTimeout = cnn.ConnectionTimeout;
         try
         {
             cnn.Open();
             SqlDataReader dr = cmd.ExecuteReader();
             while (dr.Read())
             {
                 string currentIdFrom = dr["IdFrom"].ToString();
                 string currentIdTo   = (dr["IdTo"] != DBNull.Value ? dr["IdTo"].ToString() : string.Empty);
                 if (dr["IdFrom"] != DBNull.Value && !DBObjects.ContainsKey(currentIdFrom))
                 {
                     DBEntryDescriptor dbobjectFrom = new DBEntryDescriptor();
                     dbobjectFrom.Name    = dr["NameFrom"].ToString();
                     dbobjectFrom.Id      = currentIdFrom.ToString();
                     dbobjectFrom.DbType  = GetTypeName(dr["TypeFrom"].ToString());
                     dbobjectFrom.Shape   = GetShapeByTypeCode(dr["TypeFrom"].ToString());
                     dbobjectFrom.Members = new Dictionary <string, string>();
                     try
                     {
                         if (dr["UrlFrom"] != null && dr["UrlFrom"] != DBNull.Value)
                         {
                             dbobjectFrom.Url = dr["UrlFrom"].ToString();
                         }
                         if (dr["DescriptionFrom"] != null && dr["DescriptionFrom"] != DBNull.Value)
                         {
                             dbobjectFrom.Description = dr["DescriptionFrom"].ToString();
                         }
                     }
                     catch (Exception)
                     {
                     }
                     DBObjects.Add(currentIdFrom, dbobjectFrom);
                 }
                 DBEntryDescriptor dbobjectTo;
                 if (dr["IdTo"] != DBNull.Value)
                 {
                     if (!DBObjects.ContainsKey(currentIdTo))
                     {
                         dbobjectTo         = new DBEntryDescriptor();
                         dbobjectTo.Name    = dr["NameTo"].ToString();
                         dbobjectTo.Id      = dr["IdTo"].ToString();
                         dbobjectTo.DbType  = GetTypeName(dr["TypeTo"].ToString());
                         dbobjectTo.Shape   = GetShapeByTypeCode(dr["TypeTo"].ToString());
                         dbobjectTo.Members = new Dictionary <string, string>();
                         try
                         {
                             if (dr["UrlTo"] != null && dr["UrlTo"] != DBNull.Value)
                             {
                                 dbobjectTo.Url = dr["UrlTo"].ToString();
                             }
                             if (dr["DescriptionTo"] != null && dr["DescriptionTo"] != DBNull.Value)
                             {
                                 dbobjectTo.Description = dr["DescriptionTo"].ToString();
                             }
                         }
                         catch (Exception)
                         {
                         }
                         DBObjects.Add(currentIdTo, dbobjectTo);
                     }
                     else
                     {
                         dbobjectTo = DBObjects[currentIdTo];
                     }
                     if (!dbobjectTo.Members.ContainsKey(currentIdFrom.ToString()))
                     {
                         dbobjectTo.Members.Add(currentIdFrom.ToString(), dr["Actions"].ToString());
                     }
                 }
             }
         }
         catch (SqlException ex)
         {
             throw ex;
         }
         finally
         {
             if (cnn.State != System.Data.ConnectionState.Closed)
             {
                 cnn.Close();
             }
         }
     }
 }
Example #4
0
        //new graphml node
        public XElement CreateNodeElement(DBEntryDescriptor entry)
        {
            XElement xmlNode = new XElement(GraphNS + "node",
                                            new XAttribute("id", "n" + entry.Id)
                                            );

            NodeDescriptor Node = CreateNewNode(entry); //.Name, entry.Id, entry.Description,

            //Node.GroupId = XmlSection.GetAttribute("id") +":"+ Node.Id;
            //XmlElement xmlNode = this.Document.CreateElement("node");
            //xmlNode.SetAttribute("id", Node.GroupId);
            if (!string.IsNullOrEmpty(entry.Url))
            {
                XElement xmlUrl = new XElement(GraphNS + "data",
                                               new XAttribute("key", "d1"), //URL_ID
                                               entry.Url
                                               );
                xmlNode.Add(xmlUrl);
            }
            if (entry.Description != null)
            {
                XElement xmlGroupDescription = new XElement(GraphNS + "data",
                                                            new XAttribute("key", "d2"), //NODE_DESC_ID
                                                            entry.Description
                                                            );
                xmlNode.Add(xmlGroupDescription);
            }
            XElement xmlImageShape;

            if (Node.IsImage)
            {
                xmlImageShape = new XElement(YedNS + "Image",
                                             new XAttribute("href", Node.ImageSrc)
                                             );
            }
            else
            {
                xmlImageShape = new XElement(YedNS + "Shape",
                                             new XAttribute("type", Node.Shape)
                                             );
            }

            XElement xmlGroupData3 = new XElement(GraphNS + "data",
                                                  new XAttribute("key", "d3"), //N_ID
                                                  new XElement(YedNS + (Node.IsImage ? "ImageNode" : "ShapeNode"),
                                                               new XElement(YedNS + "Geometry",
                                                                            new XAttribute("width", Node.Width),
                                                                            new XAttribute("height", Node.Height)
                                                                            ),
                                                               new XElement(YedNS + "Fill",
                                                                            new XAttribute("color", Node.FillColor),
                                                                            new XAttribute("transparent", Node.Transparent)
                                                                            ),
                                                               new XElement(YedNS + "BorderStyle",
                                                                            new XAttribute("type", Node.BorderType),
                                                                            new XAttribute("width", Node.BorderWidth),
                                                                            new XAttribute("color", Node.BorderColor)
                                                                            ),
                                                               new XElement(YedNS + "NodeLabel",
                                                                            new XAttribute("alignment", Node.LabelAlignment),
                                                                            new XAttribute("fontFamily", Node.LabelFontFamily),
                                                                            new XAttribute("textColor", Node.LabelTextColor),
                                                                            new XAttribute("autoSizePolicy", Node.LabelAutoSizePolicy),
                                                                            new XAttribute("modelName", Node.ModelName),
                                                                            new XAttribute("modelPosition", Node.ModelPosition),
                                                                            Node.Name
                                                                            ),
                                                               xmlImageShape
                                                               )
                                                  );

            xmlNode.Add(xmlGroupData3);
            //xmlNode.Add(new XElement(GraphNS + "data",
            //            new XAttribute("key", "d1"), //URL_ID
            //            Node.Url
            //            )
            //    );

            return(xmlNode);
        }
Example #5
0
        public XElement CreateGroupElement(DBEntryDescriptor group)
        {
            XElement xmlGroupNode = new XElement(GraphNS + "node",
                                                 new XAttribute("id", group.Id),
                                                 new XAttribute("yfiles.foldertype", "group")
                                                 );

            if (group.Description != null)
            {
                XElement xmlGroupDescription = new XElement(GraphNS + "data",
                                                            new XAttribute("key", "d2"),
                                                            group.Description
                                                            );
                xmlGroupNode.Add(xmlGroupDescription);
            }

            XElement xmlGroupData3 = new XElement(GraphNS + "data",
                                                  new XAttribute("key", "d3"), //N_ID
                                                  new XElement(YedNS + "ProxyAutoBoundsNode",
                                                               new XElement(YedNS + "Realizers",
                                                                            new XAttribute("active", "0"),
                                                                            new XElement(YedNS + "GroupNode",
                                                                                         new XElement(YedNS + "Fill",
                                                                                                      new XAttribute("color", "#CAECFF84"),
                                                                                                      new XAttribute("transparent", "false")
                                                                                                      ),
                                                                                         new XElement(YedNS + "NodeLabel",
                                                                                                      new XAttribute("alignment", "left"),
                                                                                                      new XAttribute("modelName", "internal"),
                                                                                                      new XAttribute("modelPosition", "t"),
                                                                                                      new XAttribute("backgroundColor", "#99CCFF"),
                                                                                                      group.Name
                                                                                                      ),
                                                                                         new XElement(YedNS + "State",
                                                                                                      new XAttribute("closed", "false")
                                                                                                      )
                                                                                         ),
                                                                            new XElement(YedNS + "GroupNode",
                                                                                         new XElement(YedNS + "Fill",
                                                                                                      new XAttribute("color", "#CAECFF84"),
                                                                                                      new XAttribute("transparent", "false")
                                                                                                      ),
                                                                                         new XElement(YedNS + "NodeLabel",
                                                                                                      new XAttribute("alignment", "left"),
                                                                                                      new XAttribute("modelName", "internal"),
                                                                                                      new XAttribute("modelPosition", "t"),
                                                                                                      new XAttribute("backgroundColor", "#99CCFF"),
                                                                                                      (group.Name.Length <= 20 ? group.Name : group.Name.Substring(0, 20) + "...")
                                                                                                      ),
                                                                                         new XElement(YedNS + "State",
                                                                                                      new XAttribute("closed", "true")
                                                                                                      )
                                                                                         )
                                                                            )
                                                               )
                                                  );

            xmlGroupNode.Add(xmlGroupData3);

            XElement xmlGrap = new XElement(GraphNS + "graph",
                                            new XAttribute("edgedefault", "directed"),
                                            new XAttribute("id", group.Id + ":")
                                            );

            xmlGroupNode.Add(xmlGrap);

            return(xmlGroupNode);
        }
Example #6
0
        public void Build(Dictionary <string, DBEntryDescriptor> dbObjects)
        {
            GraphBuilder graph = new GraphBuilder();
            XElement     xmlRootSectionGraph = new XElement(graph.GraphNS + "graph",
                                                            new XAttribute("id", "G"), //GRAPH
                                                            new XAttribute("edgedefault", "directed"),
                                                            new XAttribute("label", "Database Graph")
                                                            );
            XElement AppGroup = graph.CreateGroupElement(new DBEntryDescriptor
            {
                Id          = "o0",
                Name        = "Applications",
                Description = "this group controls releshionships between applications and database objects"
            });
            XElement AppGroupSectionGraph = (XElement)AppGroup.LastNode;

            XElement DBGroup = graph.CreateGroupElement(new DBEntryDescriptor
            {
                Id          = "u0",
                Name        = "Database",
                Description = "this group controls releshionships between database objects"
            });
            XElement DBGroupSectionGraph = (XElement)DBGroup.LastNode;
            //CultureInfo ci = new CultureInfo("en-EN"); ;
            bool AppGroupHasElements = false, DBGroupHasElements = false;

            #region objects
            List <string> dbTypeNames = new List <string>();

            List <DBEntryDescriptor> objectList = new List <DBEntryDescriptor>();
            foreach (KeyValuePair <string, DBEntryDescriptor> dbObjectPair in dbObjects)
            {
                objectList.Add(dbObjectPair.Value);
            }

            for (int i = 0; i < objectList.Count; i++)
            {
                string            dbTypeId = "u0";
                DBEntryDescriptor dbObject = objectList[i];
                if ((!dbTypeNames.Contains(dbObject.DbType)) && (!String.IsNullOrEmpty(dbObject.DbType)))
                {
                    dbTypeId = dbTypeId + "::dp" + (dbTypeNames.Count + 1).ToString();
                    dbTypeNames.Add(dbObject.DbType);
                    XElement dbTypeGroup = new XElement(
                        graph.CreateGroupElement(new DBEntryDescriptor
                    {
                        Id          = dbTypeId,
                        Name        = dbObject.DbType,
                        Description = dbObject.DbType
                    }));
                    XElement dbTypeGroupSectionGraph = (XElement)dbTypeGroup.LastNode;

                    graph.ShapeType = ShapeTypes.Image;
                    for (int j = 0; j < objectList.Count; j++)
                    {
                        DBEntryDescriptor objectInfo = objectList[j];
                        if (objectInfo.DbType == dbObject.DbType)
                        {
                            XElement entryElement = graph.CreateNodeElement(objectInfo);
                            if (entryElement != null)
                            {
                                //objectInfo.Id = dbTypeId + "::n" + objectInfo.Id;
                                objectInfo.Path = dbTypeId + "::n" + objectInfo.Id;
                                entryElement.SetAttributeValue("id", objectInfo.Path);

                                dbTypeGroupSectionGraph.Add(entryElement);
                                dbObjects[objectInfo.Id] = objectInfo;
                                objectList[j]            = objectInfo;
                            }
                        }
                    }
                    graph.ShapeType = ShapeTypes.Figure;
                    string groupvalue = dbTypeGroup.Value;
                    if (groupvalue.StartsWith("MESSAGEOBJECT") ||
                        groupvalue.StartsWith("UNIT") ||
                        groupvalue.StartsWith("PROJECT") ||
                        groupvalue.StartsWith("REPLICATION") ||
                        groupvalue.StartsWith("MENU")
                        )
                    {
                        AppGroupSectionGraph.Add(dbTypeGroup);
                        AppGroupHasElements = true;
                    }
                    if (groupvalue.StartsWith("HEAT ") ||
                        groupvalue.StartsWith("ONTIME ")
                        )
                    {
                        xmlRootSectionGraph.Add(dbTypeGroup);
                    }
                    else
                    {
                        DBGroupSectionGraph.Add(dbTypeGroup);
                        DBGroupHasElements = true;
                    }

                    //var groupName = dbTypeGroup.XPathEvaluate("node/data[@key='d3'/ProxyAutoBoundsNode/Realizers/GroupNode/NodeLabel[@modelName='internal']]");
                    //if (groupName != null)
                    //{
                    //    switch (groupName.ToString())
                    //    {
                    //        case "MESSAGEOBJECT":
                    //        case "UNITNAME":
                    //        case "PROJECTNAME":
                    //        case "REPLICATION":
                    //            OtherGroupSectionGraph.Add(dbTypeGroup);
                    //            break;
                    //        default:
                    //            ObjectGroupSectionGraph.Add(dbTypeGroup);
                    //            break;
                    //    }
                    //}
                }
                else if (String.IsNullOrEmpty(dbObject.DbType))
                {
                    graph.ShapeType = ShapeTypes.Image;

                    XElement entryElement = graph.CreateNodeElement(dbObject);
                    if (entryElement != null)
                    {
                        //dbObject.Id = dbTypeId + "::n" + dbObject.Id;
                        dbObject.Path = dbTypeId + "::n" + dbObject.Id;
                        entryElement.SetAttributeValue("id", dbObject.Path);
                        DBGroupSectionGraph.Add(entryElement);
                        dbObjects[dbObject.Id] = dbObject;
                        objectList[i]          = dbObject;
                    }
                    graph.ShapeType = ShapeTypes.Figure;
                }
            }
            #endregion


            //#region groups
            //for (int i = 0; i < dbGroups.Count; i++)
            //{
            //    DBEntryDescriptor group = dbGroups[i];
            //    XElement entryElement = graph.CreateNodeElement(group);
            //    //XElement groupElement = graph.CreateGroupElement(group);
            //    if (entryElement != null)
            //    {
            //        /*if (group.Name.StartsWith("r", false, ci))
            //        {
            //            group.Id = "r0::n" + group.Id;
            //            entryElement.SetAttributeValue("id", group.Id);
            //            ReadOnlyGroupSectionGraph.Add(entryElement);
            //        }
            //        else if (group.Name.StartsWith("c", false, ci))
            //        {
            //            group.Id = "c0::n" + group.Id;
            //            entryElement.SetAttributeValue("id", group.Id);
            //            ChangeGroupSectionGraph.Add(entryElement);
            //        }
            //        else*/
            //        {
            //            group.Id = "o0::n" + group.Id;
            //            entryElement.SetAttributeValue("id", group.Id);
            //            OtherGroupSectionGraph.Add(entryElement);
            //        }

            //        dbGroups[i] = group;
            //    }
            //}
            //#endregion

            #region edges
            int counterId = 1;

            foreach (DBEntryDescriptor dbObject in objectList)
            {
                foreach (KeyValuePair <string, string> childEntryId in dbObject.Members)
                {
                    IEnumerable <XElement> similarEdges =
                        from el in xmlRootSectionGraph.Descendants(xmlRootSectionGraph.Name.Namespace + "edge")
                        where (string)el.Attribute("source") == dbObject.Path &&
                        (string)el.Attribute("target") == dbObjects[childEntryId.Key].Path
                        select el;

                    if (similarEdges.Count() == 0)
                    {
                        XElement edgeElement = graph.CreateEdgeElement("e" + counterId.ToString(), dbObject, dbObjects[childEntryId.Key], childEntryId.Value);
                        if (edgeElement != null)
                        {
                            xmlRootSectionGraph.Add(edgeElement);
                            counterId++;
                        }
                    }
                    else
                    {
                        foreach (XElement edge in similarEdges)
                        {
                            edge.Element(xmlRootSectionGraph.Name.Namespace + "data")
                            .Descendants(graph.YedNS + "PolyLineEdge")
                            .Descendants(graph.YedNS + "Arrows").FirstOrDefault()
                            .SetAttributeValue("source", "standard");
                        }
                    }
                }
            }
            #endregion

            if (AppGroupHasElements == true || DBGroupHasElements == true)
            {
                xmlRootSectionGraph.Add(AppGroup, DBGroup);
            }

            graph.Root.Add(xmlRootSectionGraph);
            graph.Root.Save(YedOutputFilePath);
        }