Inheritance: MapTypeElement
Exemplo n.º 1
0
        public TypeResponse LoadTypesFromDb()
        {
            TypeResponse types = new TypeResponse();
            SqlCommand selectTypes = new SqlCommand(SelectTypes, MapObjects.MapDbConnection.Connection);

            MapObjects.MapDbConnection.Open();

            SqlDataReader typesReader = selectTypes.ExecuteReader();

            int count = 0;

            do
            {
                count++;

                while (typesReader.Read())
                {
                    switch (count)
                    {
                        case 1:
                            NodeType nodeType = new NodeType();
                            nodeType.LoadSessionObject(typesReader);

                            types.NodeTypes[nodeType.Name] = nodeType;
                            break;
                        case 2:
                            RelationshipType relationshipType = new RelationshipType();
                            relationshipType.LoadSessionObject(typesReader);

                            types.RelationshipTypes[relationshipType.Name] = relationshipType;
                            break;
                        case 3:
                            DescriptorType descriptorType = new DescriptorType();
                            descriptorType.LoadSessionObject(typesReader);

                            types.DescriptorTypes[descriptorType.Name] = descriptorType;
                            break;
                        case 4:
                            MetadataType metadataType = new MetadataType();
                            metadataType.LoadSessionObject(typesReader);

                            types.MetadataTypes[metadataType.Name] = metadataType;
                            break;
                        default:
                            break;
                    }
                }
            }
            while (typesReader.NextResult());

            MapObjects.MapDbConnection.Close();

            return types;
        }
Exemplo n.º 2
0
        public Guid Create(Guid domainId, string name, NodeType nodeType, string originalId)
        {
            SqlCommand getDomainNodeId = new SqlCommand(GetDomainNodeId, MapObjects.MapDbConnection.Connection);
            getDomainNodeId.Parameters.Add(new SqlParameter("@NodeTypeUid", new Guid("263754C2-2F31-4D21-B9C4-6509E00A5E94")));
            getDomainNodeId.Parameters.Add(new SqlParameter("@DomainUid", domainId));

            Guid? domainNodeId = (Guid?)getDomainNodeId.ExecuteScalar();

            if (domainNodeId == null)
            {
                return Guid.Empty;
            }

            Guid nodeId = Guid.NewGuid();
            DateTime currentTime = DateTime.Now;

            SqlCommand createRootMapCommand = new SqlCommand(CreateRootMapNode, MapObjects.MapDbConnection.Connection);
            createRootMapCommand.Parameters.Add(new SqlParameter("@NodeUid", nodeId));

            if (string.IsNullOrEmpty(originalId))
            {
                createRootMapCommand.Parameters.Add(new SqlParameter("@NodeOriginalId", DBNull.Value));
            }
            else
            {
                createRootMapCommand.Parameters.Add(new SqlParameter("@NodeOriginalId", originalId));
            }

            createRootMapCommand.Parameters.Add(new SqlParameter("@NodeTypeUid", nodeType.Id));
            createRootMapCommand.Parameters.Add(new SqlParameter("@DomainUid", domainId));
            createRootMapCommand.Parameters.Add(new SqlParameter("@RootMapUid", nodeId));
            createRootMapCommand.Parameters.Add(new SqlParameter("@Created", currentTime));
            createRootMapCommand.Parameters.Add(new SqlParameter("@Modified", currentTime));
            createRootMapCommand.Parameters.Add(new SqlParameter("@CreatedBy", User));
            createRootMapCommand.Parameters.Add(new SqlParameter("@ModifiedBy", User));

            createRootMapCommand.ExecuteNonQuery();

            Guid metadataId = Guid.NewGuid();

            SqlCommand metadataRootMapCommand = new SqlCommand(CreateRootMapNameMetadata, MapObjects.MapDbConnection.Connection);
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@MetadataId", metadataId));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@MetadataTypeUid", new Guid("C7628C1E-77C1-4A07-A2E8-8DE9F4E9803C")));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@NodeUid", nodeId));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@RelationshipUid", DBNull.Value));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@DescriptorTypeUid", DBNull.Value));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@MetadataName", "Name"));

            if (string.IsNullOrEmpty(name))
            {
                metadataRootMapCommand.Parameters.Add(new SqlParameter("@MetadataValue", DBNull.Value));
            }
            else
            {
                metadataRootMapCommand.Parameters.Add(new SqlParameter("@MetadataValue", name));
            }

            metadataRootMapCommand.Parameters.Add(new SqlParameter("@RootMapUid", nodeId));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@DomainUid", domainId));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@Created", currentTime));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@Modified", currentTime));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@CreatedBy", User));
            metadataRootMapCommand.Parameters.Add(new SqlParameter("@ModifiedBy", User));

            metadataRootMapCommand.ExecuteNonQuery();

            Guid relationshipId = Guid.NewGuid();

            SqlCommand relationshipRootMapCommand = new SqlCommand(CreateRootMapRelationship, MapObjects.MapDbConnection.Connection);
            relationshipRootMapCommand.Parameters.Add(new SqlParameter("@RelationshipUid", relationshipId));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter("@RelationshipOriginalId", ""));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter(@"RelationshipTypeUid", new Guid("4AFF46D7-87BE-48DD-B703-A93E38EF8FFB")));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter(@"DomainUid", domainId));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter(@"RootMapUid", nodeId));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter(@"Created", currentTime));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter(@"Modified", currentTime));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter(@"CreatedBy", User));
            relationshipRootMapCommand.Parameters.Add(new SqlParameter(@"ModifiedBy", User));

            relationshipRootMapCommand.ExecuteNonQuery();

            Guid fromDescriptorId = Guid.NewGuid();

            SqlCommand fromDescriptorRootMapCommand = new SqlCommand(CreateRootMapDescriptors, MapObjects.MapDbConnection.Connection);
            fromDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@DescriptorUid", fromDescriptorId));
            fromDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@DescriptorTypeUid", new Guid("96DA1782-058C-4F9B-BB1A-31B048F8C75A")));
            fromDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@NodeUid", nodeId));
            fromDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@RelationshipUid", relationshipId));

            fromDescriptorRootMapCommand.ExecuteNonQuery();

            Guid toDescriptorId = Guid.NewGuid();

            SqlCommand toDescriptorRootMapCommand = new SqlCommand(CreateRootMapDescriptors, MapObjects.MapDbConnection.Connection);
            toDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@DescriptorUid", toDescriptorId));
            toDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@DescriptorTypeUid", new Guid("07C91D35-4DAC-431B-966B-64C924B8CDAB")));
            toDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@NodeUid", domainNodeId.Value));
            toDescriptorRootMapCommand.Parameters.Add(new SqlParameter("@RelationshipUid", relationshipId));

            toDescriptorRootMapCommand.ExecuteNonQuery();

            return nodeId;
        }