예제 #1
0
        public override void PersistMap(DataSourceStructure dbstruct)
        {
            //translate the structure into the SystemMap Services.
            StoreServerNode();
            SqlServerDatabaseNode databaseNode = (SqlServerDatabaseNode)dbstruct.DataSource;

            StoreDbNode(databaseNode);
            dbstruct.Nodes.Add(serverStructure.ServerNode);
            dbstruct.Nodes.Add(dbstruct.DataSource);
            StoreNodes(dbstruct.Nodes, databaseNode);
            StoreDependencies(dbstruct.Relationships);
        }
예제 #2
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);
            }
        }
        protected override void LoadDatabaseObjects()
        {
            Nodes.Clear();
            //list the databases
            SqlConnectionStringBuilder dbconnbuilder = new SqlConnectionStringBuilder();

            dbconnbuilder.DataSource         = ConnectionStringBuilder.DataSource;
            dbconnbuilder.IntegratedSecurity = ConnectionStringBuilder.IntegratedSecurity;
            dbconnbuilder.UserID             = ConnectionStringBuilder.UserID;
            dbconnbuilder.Password           = ConnectionStringBuilder.Password;
            using (SqlConnection dbinstance = new SqlConnection(dbconnbuilder.ConnectionString))
            {
                dbinstance.Open();
                DataTable databases = dbinstance.GetSchema(SqlClientMetaDataCollectionNames.Databases);
                foreach (DataRow dbrow in databases.Rows)
                {
                    SqlConnectionStringBuilder dbconn = new SqlConnectionStringBuilder(dbconnbuilder.ConnectionString);
                    dbconn.InitialCatalog = dbrow[0].ToString();
                    SqlServerDatabaseNode dbnode = new SqlServerDatabaseNode(dbconn.InitialCatalog, dbconn);
                    Nodes.Add(dbnode);
                }
                dbinstance.Close();
            }
        }
예제 #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);
                        }
                    }
                }
            }
        }