Exemplo n.º 1
0
        protected void StoreDbNode(SqlServerDatabaseNode dbnode)
        {
            TypeService tsvc = new TypeService();

            if (dbnode.NodeIdentity == 0)
            {
                NodeService      nsvc   = new NodeService();
                AttributeService attsvc = new AttributeService();

                NodeType dbtype = tsvc.GetNodeType("Database", true);

                Node existing = nsvc.GetByName(dbnode.Name);
                if (existing == null)
                {
                    existing = new Node
                    {
                        name        = dbnode.Name,
                        description = "SQL Server Database",
                        type        = dbtype
                    };
                    int dbnodeid = nsvc.AddNode(existing);
                    dbnode.NodeIdentity = dbnodeid;
                    if (dbnode.Metadata != null)
                    {
                        foreach (NodeAttribute natt in dbnode.Metadata)
                        {
                            AttributeType atype = tsvc.GetAttributeType(natt.type.name, true);
                            natt.nodeId = dbnodeid;
                            natt.type   = atype;
                            attsvc.AddNodeAttribute(natt);
                        }
                    }
                }
                else
                {
                    dbnode.NodeIdentity = existing.id;
                }
            }
            //If the identities are set, add membership setting
            if (dbnode.NodeIdentity != 0 && serverStructure.ServerNode.NodeIdentity != 0)
            {
                MembershipType    mtype = tsvc.GetMembershipType("Database", true);
                MembershipService msvc  = new MembershipService();
                msvc.AddNodeMembership(serverStructure.ServerNode.NodeIdentity, dbnode.NodeIdentity, mtype.typeId);
            }
        }
Exemplo n.º 2
0
        protected void StoreServerNode()
        {
            DataSourceNodeBase srvrNode = serverStructure.ServerNode;
            NodeService        nsvc     = new NodeService();
            TypeService        tsvc     = new TypeService();
            AttributeService   attsvc   = new AttributeService();
            Node existing = nsvc.GetByName(srvrNode.Name);

            if (existing == null)
            {
                //doesn't exist--add it
                existing = new Node {
                    name = srvrNode.Name
                };
                NodeType srvrType = tsvc.GetNodeType("SQL Server", true);
                existing.type = srvrType;
                int srvrId = nsvc.AddNode(existing);
                existing.id = srvrId;
            }
            else
            {
                srvrNode.NodeIdentity = existing.id;
            }
            if (srvrNode.Metadata != null)
            {
                foreach (NodeAttribute natt in srvrNode.Metadata)
                {
                    try
                    {
                        AttributeType atype = tsvc.GetAttributeType(natt.type.name, true);
                        natt.nodeId = existing.id;
                        natt.type   = atype;
                        attsvc.AddNodeAttribute(natt);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void SeedTypeData()
        {
            using (TypeService tsvc = new TypeService())
            {
                string      descr = "Automatically seeded type data";
                Assembly    assm  = Assembly.LoadFrom(@".\SystemMap.dll");
                List <Type> tlist = assm.GetTypes().Where(t => t.IsEnum).ToList <Type>();
                foreach (string ntype in nodeEnums)
                {
                    Type nodeEnum = tlist.Where(en => en.Name == ntype).SingleOrDefault();
                    if (nodeEnum != null)
                    {
                        FieldInfo[] nfields = nodeEnum.GetFields();
                        foreach (FieldInfo f in nfields)
                        {
                            if (f.Name.Equals("value__"))
                            {
                                continue;
                            }
                            string           showval = f.Name;
                            DisplayAttribute display = ((DisplayAttribute[])f.GetCustomAttributes(typeof(DisplayAttribute), false)).FirstOrDefault();
                            if (display != null)
                            {
                                showval = display.GetName();
                            }
                            NodeType tdata = new NodeType {
                                name = showval, description = descr
                            };
                            NodeType added = tsvc.GetNodeType(tdata.name, true);
                        }
                    }
                }
                foreach (string etype in edgeEnums)
                {
                    Type edgeEnum = tlist.Where(en => en.Name == etype).SingleOrDefault();
                    if (edgeEnum != null)
                    {
                        FieldInfo[] nfields = edgeEnum.GetFields();
                        foreach (FieldInfo f in nfields)
                        {
                            if (f.Name.Equals("value__"))
                            {
                                continue;
                            }
                            string           showval = f.Name;
                            DisplayAttribute display = ((DisplayAttribute[])f.GetCustomAttributes(typeof(DisplayAttribute), false)).FirstOrDefault();
                            if (display != null)
                            {
                                showval = display.GetName();
                            }
                            EdgeType tdata = new EdgeType {
                                name = showval, description = descr
                            };
                            EdgeType added = tsvc.GetEdgeType(tdata.name, true);
                        }
                    }
                }
                foreach (string atype in attrEnums)
                {
                    Type attEnum = tlist.Where(en => en.Name == atype).SingleOrDefault();
                    if (attEnum != null)
                    {
                        FieldInfo[] nfields = attEnum.GetFields();
                        foreach (FieldInfo f in nfields)
                        {
                            if (f.Name.Equals("value__"))
                            {
                                continue;
                            }
                            string           showval = f.Name;
                            DisplayAttribute display = ((DisplayAttribute[])f.GetCustomAttributes(typeof(DisplayAttribute), false)).FirstOrDefault();
                            if (display != null)
                            {
                                showval = display.GetName();
                            }
                            AttributeType tdata = new AttributeType {
                                name = showval, description = descr
                            };
                            AttributeType added = tsvc.GetAttributeType(tdata.name, true);
                        }
                    }
                }
                foreach (string mtype in memEnums)
                {
                    Type memEnum = tlist.Where(en => en.Name == mtype).SingleOrDefault();
                    if (memEnum != null)
                    {
                        FieldInfo[] nfields = memEnum.GetFields();
                        foreach (FieldInfo f in nfields)
                        {
                            if (f.Name.Equals("value__"))
                            {
                                continue;
                            }
                            string           showval = f.Name;
                            DisplayAttribute display = ((DisplayAttribute[])f.GetCustomAttributes(typeof(DisplayAttribute), false)).FirstOrDefault();
                            if (display != null)
                            {
                                showval = display.GetName();
                            }
                            MembershipType tdata = new MembershipType {
                                name = showval, description = descr
                            };
                            MembershipType added = tsvc.GetMembershipType(tdata.name, true);
                        }
                    }
                }

                foreach (string dtype in docEnums)
                {
                    Type docEnum = tlist.Where(en => en.Name == dtype).SingleOrDefault();
                    if (docEnum != null)
                    {
                        FieldInfo[] nfields = docEnum.GetFields();
                        foreach (FieldInfo f in nfields)
                        {
                            if (f.Name.Equals("value__"))
                            {
                                continue;
                            }
                            string           showval = f.Name;
                            DisplayAttribute display = ((DisplayAttribute[])f.GetCustomAttributes(typeof(DisplayAttribute), false)).FirstOrDefault();
                            if (display != null)
                            {
                                showval = display.GetName();
                            }
                            DocType tdata = new DocType {
                                name = showval, description = descr
                            };
                            DocType added = tsvc.GetDocType(tdata.name, true);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected void StoreNodes(List <DataSourceNodeBase> nlist, SqlServerDatabaseNode databaseNode)
        {
            NodeService       nsvc   = new NodeService();
            TypeService       tsvc   = new TypeService();
            AttributeService  attsvc = new AttributeService();
            MembershipService msvc   = new MembershipService();

            foreach (DataSourceNodeBase dbnode in nlist)
            {
                string memtypename = null;

                //if there is a non-zero id value, it's already been stored/pulled.
                if (dbnode.NodeIdentity == 0)
                {
                    Node existnode = nsvc.GetByName(dbnode.Name);
                    if (existnode == null)
                    {
                        //hasn't been added yet--create one
                        Type   nclasstype = dbnode.GetType();
                        string ntypename  = null;
                        switch (nclasstype.FullName)
                        {
                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerInstanceNode":
                            ntypename   = "SQL Server";
                            memtypename = null;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerDatabaseNode":
                            ntypename   = EnumParser.GetValueName(DbClasses.Database);
                            memtypename = null;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerTableNode":
                            ntypename   = EnumParser.GetValueName(DbClasses.Table);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerViewNode":
                            ntypename   = EnumParser.GetValueName(DbClasses.View);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerProcedureNode":
                            ntypename   = EnumParser.GetValueName(DbProcesses.StoredProcedue);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerFunctionNode":
                            ntypename   = EnumParser.GetValueName(DbProcesses.Function);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.GenericDataSourceNode":
                            ntypename   = "External Reference";
                            memtypename = null;
                            break;

                        default:
                            ntypename   = "General";
                            memtypename = null;
                            break;
                        }
                        NodeType ntype = tsvc.GetNodeType(ntypename, true);
                        existnode = new Node
                        {
                            name        = dbnode.Name,
                            description = ntypename,
                            type        = ntype
                        };
                        try
                        {
                            int nid = nsvc.AddNode(existnode);
                            dbnode.NodeIdentity = nid;
                            if (dbnode.Metadata != null)
                            {
                                foreach (NodeAttribute natt in dbnode.Metadata)
                                {
                                    try
                                    {
                                        AttributeType atype = tsvc.GetAttributeType(natt.type.name, true);
                                        natt.nodeId = dbnode.NodeIdentity;
                                        natt.type   = atype;
                                        attsvc.AddNodeAttribute(natt);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.StackTrace);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    else
                    {
                        dbnode.NodeIdentity = existnode.id;
                    }
                }
                if (memtypename != null)
                {
                    MembershipType mtype = tsvc.GetMembershipType(memtypename, true);
                    if (mtype != null && databaseNode.NodeIdentity != 0 && dbnode.NodeIdentity != 0)
                    {
                        try
                        {
                            msvc.AddNodeMembership(databaseNode.NodeIdentity, dbnode.NodeIdentity, mtype.typeId);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
        }