Inheritance: IMapElement, IMapElementLoader
Beispiel #1
0
 public MapChange(long transactionId, Guid mapParameter, Node node, TransactionType operation)
 {
     TransactionId = transactionId;
     MapParameter = mapParameter;
     Node = node;
     Operation = operation;
 }
Beispiel #2
0
        protected SqlCommand UpdateNodeCommand(SqlConnection connection, Node node)
        {
            SqlCommand updateNodeCommand = new SqlCommand();
            updateNodeCommand.CommandText = "UPDATE [Nodes] SET [NodeTypeUid] = @NodeTypeUid, [Modified] = @Modified, [ModifiedBy] = @ModifiedBy WHERE [DomainUid] = @DomainUid AND [NodeUid] = @NodeUid";
            updateNodeCommand.Connection = connection;

            updateNodeCommand.Parameters.AddWithValue("@DomainUid", node.DomainUid);
            updateNodeCommand.Parameters.AddWithValue("@NodeUid", node.NodeUid);
            updateNodeCommand.Parameters.AddWithValue("@NodeTypeUid", node.NodeTypeUid);

            if (node.Modified == null)
            {
                updateNodeCommand.Parameters.AddWithValue("@Modified", DBNull.Value);
            }
            else
            {
                updateNodeCommand.Parameters.AddWithValue("@Modified", node.Modified);
            }

            if (node.ModifiedBy == null)
            {
                updateNodeCommand.Parameters.AddWithValue("@ModifiedBy", DBNull.Value);
            }
            else
            {
                updateNodeCommand.Parameters.AddWithValue("@ModifiedBy", node.ModifiedBy);
            }

            return updateNodeCommand;
        }
Beispiel #3
0
        public Node NodeCreate(Domain newDomain, Guid nodeTypeId)
        {
            Guid newNodeId;
            Node newNode = new Node();

            SqlCommand createNodeCommand = CreateNodeCommand(out newNodeId, nodeTypeUid: nodeTypeId, domainUid: newDomain.DomainUid);
            createNodeCommand.Parameters.AddWithValue("@NodeOriginalId", newNodeId.ToString());

            createNodeCommand.ExecuteNonQuery();

            newNode.NodeUid = newNodeId;
            newNode.NodeOriginalId = newNodeId.ToString();
            newNode.NodeTypeUid = nodeTypeId;
            newNode.DomainUid = newDomain.DomainUid;

            return newNode;
        }
Beispiel #4
0
        public Node DomainGetRootNode(Domain domain)
        {
            Node domainNode = new Node();

            SqlCommand selectDomainNodeCommand = SelectDomainNodeCommand(domain.DomainUid);
            SqlDataReader reader = selectDomainNodeCommand.ExecuteReader();

            if (reader.Read())
            {
                domainNode.NodeUid = (Guid)reader["NodeUid"];
                domainNode.NodeOriginalId = (string)reader["NodeOriginalId"];
                domainNode.NodeTypeUid = (Guid)reader["NodeTypeUid"];
                domainNode.DomainUid = (Guid)reader["DomainUid"];
            }

            return domainNode;
        }
Beispiel #5
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            SqlCommand command = SelectDeleteNodeRelationshipsDescriptorsMetadataCommand(connectionAbstraction.Connection, transactionWrapper.NodeParameter.Value);

            connectionAbstraction.Open();

            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                Node deletedNode = new Node();
                deletedNode.LoadElement(reader);

                response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, deletedNode, TransactionType.DeleteNode));

                if (reader.NextResult())
                {
                    while (reader.Read())
                    {
                        Metadata deletedMetadata = new Metadata();
                        deletedMetadata.LoadElement(reader);

                        response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, deletedMetadata, TransactionType.DeleteMetadata));
                    }
                }

                if (reader.NextResult())
                {
                    while (reader.Read())
                    {
                        Relationship deletedRelationship = new Relationship();
                        deletedRelationship.LoadElement(reader);

                        response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, deletedRelationship, TransactionType.DeleteRelationship));
                    }
                }

                transactionWrapper.ResponseParameter.Value = deletedNode.NodeUid;
            }
            connectionAbstraction.Close();
        }
Beispiel #6
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now.ToUniversalTime();

            Node updatedNode = new Node();
            updatedNode.DomainUid = transactionWrapper.DomainParameter.Value;
            updatedNode.NodeUid = transactionWrapper.NodeParameter.Value;
            updatedNode.NodeTypeUid = transaction.NodeTypeUid.Value;
            updatedNode.Modified = currentTime;
            updatedNode.ModifiedBy = transaction.User;

            SqlCommand updateNodeCommand = UpdateNodeCommand(connectionAbstraction.Connection, updatedNode);

            connectionAbstraction.Open();
            updateNodeCommand.ExecuteNonQuery();
            connectionAbstraction.Close();

            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, updatedNode, TransactionType.UpdateNode));

            transactionWrapper.ResponseParameter.Value = updatedNode.NodeUid;
        }
Beispiel #7
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now.ToUniversalTime();

            Node newNode = new Node();
            newNode.NodeTypeUid = transaction.NodeTypeUid.Value;
            newNode.DomainUid = transactionWrapper.DomainParameter.Value;

            if (transactionWrapper.RootMapParameter != null)
            {
                newNode.RootMapUid = transactionWrapper.RootMapParameter.Value;
            }
            else
            {
                newNode.RootMapUid = null;
            }

            newNode.Created = currentTime;
            newNode.Modified = currentTime;
            newNode.CreatedBy = transaction.User;
            newNode.ModifiedBy = transaction.User;

            Guid newNodeId;

            SqlCommand command = CreateNodeCommand(connectionAbstraction.Connection, out newNodeId, newNode);

            connectionAbstraction.Open();
            command.ExecuteNonQuery();
            connectionAbstraction.Close();

            newNode.NodeUid = newNodeId;
            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, newNode, TransactionType.CreateNode));

            transactionWrapper.ResponseParameter.Value = newNodeId;
        }
Beispiel #8
0
 public void AddNode(Node node)
 {
     if (!Nodes.ContainsKey(node.NodeUid))
     {
         Nodes.Add(node.NodeUid, node);
     }
 }
Beispiel #9
0
        protected SqlCommand CreateNodeCommand(SqlConnection connection, out Guid newNodeId, Node newNodeParameters)
        {
            SqlCommand createNodeCommand = new SqlCommand();
            //createNodeCommand.CommandText = "INSERT INTO [Nodes] ([NodeUid], [NodeOriginalId], [NodeTypeUid], [DomainUid]) VALUES (@NodeUid, @NodeOriginalId, @NodeTypeUid, @DomainUid)";
            createNodeCommand.CommandText = "INSERT INTO [Nodes] ([NodeUid], [NodeTypeUid], [DomainUid], [RootMapUid], [Created], [Modified], [CreatedBy], [ModifiedBy]) VALUES (@NodeUid, @NodeTypeUid, @DomainUid, @RootMapUid, @Created, @Modified, @CreatedBy, @ModifiedBy)";
            createNodeCommand.Connection = connection;

            newNodeId = Guid.NewGuid();

            createNodeCommand.Parameters.AddWithValue("@NodeUid", newNodeId);
            /// TODO: Need to persist the NodeOriginalId value.
            //createNodeCommand.Parameters.AddWithValue("@NodeOriginalId", GetNodeUid(mapParameters));
            createNodeCommand.Parameters.AddWithValue("@NodeTypeUid", newNodeParameters.NodeTypeUid);
            createNodeCommand.Parameters.AddWithValue("@DomainUid", newNodeParameters.DomainUid);

            if (newNodeParameters.RootMapUid == null)
            {
                createNodeCommand.Parameters.AddWithValue("@RootMapUid", DBNull.Value);
            }
            else
            {
                createNodeCommand.Parameters.AddWithValue("@RootMapUid", newNodeParameters.RootMapUid);
            }

            if (newNodeParameters.Created == null)
            {
                createNodeCommand.Parameters.AddWithValue("@Created", DBNull.Value);
            }
            else
            {
                createNodeCommand.Parameters.AddWithValue("@Created", newNodeParameters.Created);
            }

            if (newNodeParameters.Modified == null)
            {
                createNodeCommand.Parameters.AddWithValue("@Modified", DBNull.Value);
            }
            else
            {
                createNodeCommand.Parameters.AddWithValue("@Modified", newNodeParameters.Modified);
            }

            if (newNodeParameters.CreatedBy == null)
            {
                createNodeCommand.Parameters.AddWithValue("@CreatedBy", DBNull.Value);
            }
            else
            {
                createNodeCommand.Parameters.AddWithValue("@CreatedBy", newNodeParameters.CreatedBy);
            }

            if (newNodeParameters.ModifiedBy == null)
            {
                createNodeCommand.Parameters.AddWithValue("@ModifiedBy", DBNull.Value);
            }
            else
            {
                createNodeCommand.Parameters.AddWithValue("@ModifiedBy", newNodeParameters.ModifiedBy);
            }

            return createNodeCommand;
        }
Beispiel #10
0
 public MapChange(long transactionId, Node node, TransactionType operation)
 {
     TransactionId = transactionId;
     Node = node;
     Operation = operation;
 }