public Dictionary <Guid, QueryResponse> QueryDomains(IGlymaSession glymaSession)
        {
            using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection())
            {
                SqlCommand queryDomainMapCommand = new SqlCommand("SELECT [DomainUid], [NodeUid] FROM [Nodes] WHERE NodeTypeUid = '263754C2-2F31-4D21-B9C4-6509E00A5E94'", mapDbConnection.Connection);
                queryDomainMapCommand.CommandType = CommandType.Text;

                mapDbConnection.Open();

                SqlDataReader queryMapResults = queryDomainMapCommand.ExecuteReader();

                Dictionary <Guid, QueryResponse> domainResponses = new Dictionary <Guid, QueryResponse>();

                if (queryMapResults.HasRows)
                {
                    while (queryMapResults.Read())
                    {
                        Guid domainId = queryMapResults.GetGuid(0);
                        Guid nodeId   = queryMapResults.GetGuid(1);

                        QueryResponse response = QueryMap(glymaSession, domainId, nodeId, 0, false, null, null, 0, false);
                        domainResponses[domainId] = response;
                    }
                }
                mapDbConnection.Close();

                try
                {
                    mapDbConnection.Open();
                    AuditLogItem logItem = new AuditLogItem(mapDbConnection.Connection);
                    logItem.OperationName = "QueryDomains";
                    //logItem.CallingUrl = callingUrl;
                    logItem.DomainUid        = null;
                    logItem.NodeUid          = null;
                    logItem.RootMapUid       = null;
                    logItem.MaxDepth         = null;
                    logItem.ObjectIndex      = null;
                    logItem.EdgeConditions   = null;
                    logItem.FilterConditions = null;
                    logItem.SearchConditions = null;
                    logItem.PageNumber       = null;
                    logItem.PageSize         = null;
                    logItem.Commit();
                    mapDbConnection.Close();
                }
                catch
                {
                    /// Don't do anything. This is here because audit logging is a very low importance task and we don't want it potentially killing the more important tasks at hand.
                }

                return(domainResponses);
            }
        }
        public QueryResponse QueryMapByDomain(IGlymaSession glymaSession, Guid domainId, int maxDepth, EdgeConditions edgeConditions, FilterConditions filterConditions)
        {
            using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection())
            {
                SqlCommand queryDomainMapCommand = new SqlCommand("SELECT [NodeUid] FROM [Nodes] WHERE DomainUid = @DomainId AND NodeTypeUid = '263754C2-2F31-4D21-B9C4-6509E00A5E94'", mapDbConnection.Connection);
                queryDomainMapCommand.CommandType = CommandType.Text;
                queryDomainMapCommand.Parameters.Add(new SqlParameter("@DomainId", domainId));

                Guid domainNodeId = Guid.Empty;

                mapDbConnection.Open();

                SqlDataReader queryMapResults = queryDomainMapCommand.ExecuteReader();

                if (queryMapResults.HasRows)
                {
                    queryMapResults.Read();

                    domainNodeId = queryMapResults.GetGuid(0);
                }
                mapDbConnection.Close();

                try
                {
                    mapDbConnection.Open();
                    AuditLogItem logItem = new AuditLogItem(mapDbConnection.Connection);
                    logItem.OperationName = "QueryMapByDomain";
                    //logItem.CallingUrl = callingUrl;
                    logItem.DomainUid        = domainId;
                    logItem.NodeUid          = null;
                    logItem.RootMapUid       = null;
                    logItem.MaxDepth         = maxDepth;
                    logItem.ObjectIndex      = null;
                    logItem.EdgeConditions   = null;
                    logItem.FilterConditions = null;
                    logItem.SearchConditions = null;
                    logItem.PageNumber       = null;
                    logItem.PageSize         = null;
                    logItem.Commit();
                    mapDbConnection.Close();
                }
                catch
                {
                    /// Don't do anything. This is here because audit logging is a very low importance task and we don't want it potentially killing the more important tasks at hand.
                }

                return(QueryMap(glymaSession, domainId, domainNodeId, maxDepth, true, edgeConditions, filterConditions, 0));
            }
        }
Esempio n. 3
0
        public void LoadParameters()
        {
            SqlParameter sqlSessionParameter = new SqlParameter("@SessionId", GlymaSession.Session.Id);

            using (IDbConnectionAbstraction parametersDbConnection = GlymaSession.ConnectionFactory.CreateParametersDbConnection())
            {
                SqlCommand selectParametersFromId = new SqlCommand(SelectParametersFromSessionId, parametersDbConnection.Connection);
                selectParametersFromId.Parameters.Add(sqlSessionParameter);

                parametersDbConnection.Open();

                IDataReader parameters = selectParametersFromId.ExecuteReader();

                while (parameters.Read())
                {
                    MapParameter parameter = new MapParameter();

                    parameter.LoadSessionObject(parameters);

                    AddParameter(parameter);
                }

                parametersDbConnection.Close();
            }
        }
Esempio n. 4
0
        public void LoadTransactions()
        {
            SqlParameter sessionIdParameter = new SqlParameter("@SessionId", Id);

            using (IDbConnectionAbstraction sessionDbConnection = GlymaSession.ConnectionFactory.CreateSessionDbConnection())
            {
                SqlCommand selectSessionTransactions = new SqlCommand(SelectSessionTransactionsSqlQuery, sessionDbConnection.Connection);
                selectSessionTransactions.Parameters.Add(sessionIdParameter);

                sessionDbConnection.Open();

                SqlDataReader sessions = selectSessionTransactions.ExecuteReader();

                while (sessions.Read())
                {
                    TransactionType transactionType = (TransactionType)sessions["OperationId"];

                    if (transactionType != TransactionType.BeginSession && transactionType != TransactionType.CompleteSession)
                    {
                        MapTransactionWrapper mapTransaction = new MapTransactionWrapper(GlymaSession);

                        mapTransaction.LoadSessionObject(sessions);

                        Enqueue(mapTransaction);
                    }
                }

                sessionDbConnection.Close();
            }
        }
Esempio n. 5
0
        public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
        {
            Dictionary <string, object> .Enumerator parameters = _parameters.GetEnumerator();

            using (SqlCommand command = new SqlCommand())
            {
                IQueryBuilder queryBuilder = null;

                if (IsNew)
                {
                    queryBuilder = new InsertQueryBuilder();
                }
                else if (IsDirty)
                {
                    queryBuilder = new UpdateQueryBuilder();
                }
                else
                {
                    return;
                }

                while (parameters.MoveNext())
                {
                    queryBuilder.AddParameter(parameters.Current.Key, parameters.Current.Value);
                }

                command.Parameters.AddRange(queryBuilder.GenerateSqlParameters());
                command.Connection  = connectionAbstraction.Connection;
                command.CommandText = queryBuilder.GenerateSqlQuery();

                connectionAbstraction.Open();
                TransactionId = long.Parse(command.ExecuteScalar().ToString());
                connectionAbstraction.Close();
            }
        }
Esempio n. 6
0
        public void ExecuteCompleteSession()
        {
            using (IDbConnectionAbstraction sessionDbConnection = GlymaSession.ConnectionFactory.CreateSessionDbConnection())
            {
                SqlCommand command = CreateCompleteSessionCommand(sessionDbConnection.Connection);

                sessionDbConnection.Open();
                command.ExecuteNonQuery();
                sessionDbConnection.Close();
            }
        }
Esempio n. 7
0
        public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
        {
            if (IsNew)
            {
                SqlCommand createDomainCommand = CreateDomainCommand(DomainUid, DomainOriginalId);
                createDomainCommand.Connection = connectionAbstraction.Connection;

                connectionAbstraction.Open();
                createDomainCommand.ExecuteNonQuery();
                connectionAbstraction.Close();
            }
        }
Esempio n. 8
0
        public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
        {
            if (IsNew)
            {
                SqlCommand createDomainCommand = CreateDomainCommand(DomainUid, DomainOriginalId);
                createDomainCommand.Connection = connectionAbstraction.Connection;

                connectionAbstraction.Open();
                createDomainCommand.ExecuteNonQuery();
                connectionAbstraction.Close();
            }
        }
Esempio n. 9
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            Descriptor updatedDescriptor = new Descriptor();

            updatedDescriptor.NodeUid           = transactionWrapper.NodeParameter.Value;
            updatedDescriptor.DescriptorTypeUid = transaction.DescriptorTypeUid.Value;
            updatedDescriptor.RelationshipUid   = transactionWrapper.RelationshipParameter.Value;

            SqlCommand command = UpdateDescriptorCommand(connectionAbstraction.Connection, updatedDescriptor);

            connectionAbstraction.Open();
            object descriptorUidAsObject = command.ExecuteScalar();

            connectionAbstraction.Close();

            if (descriptorUidAsObject != null && descriptorUidAsObject != DBNull.Value)
            {
                updatedDescriptor.DescriptorUid = (Guid)descriptorUidAsObject;
            }
            else
            {
                // This case occurs if the relationship type has been changed and previously this descriptor didn't exist for this relationship type.
                Guid newDescriptorUid;

                SqlCommand createDescriptorCommand = CreateDescriptorCommand(connectionAbstraction.Connection, out newDescriptorUid, updatedDescriptor);
                updatedDescriptor.DescriptorUid = newDescriptorUid;

                connectionAbstraction.Open();
                createDescriptorCommand.ExecuteNonQuery();
                connectionAbstraction.Close();
            }

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

            transactionWrapper.ResponseParameter.Value = updatedDescriptor.DescriptorUid;
        }
Esempio n. 10
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            Descriptor updatedDescriptor = new Descriptor();
            updatedDescriptor.NodeUid = transactionWrapper.NodeParameter.Value;
            updatedDescriptor.DescriptorTypeUid = transaction.DescriptorTypeUid.Value;
            updatedDescriptor.RelationshipUid = transactionWrapper.RelationshipParameter.Value;

            SqlCommand command = UpdateDescriptorCommand(connectionAbstraction.Connection, updatedDescriptor);

            connectionAbstraction.Open();
            object descriptorUidAsObject = command.ExecuteScalar();
            connectionAbstraction.Close();

            if (descriptorUidAsObject != null && descriptorUidAsObject != DBNull.Value)
            {
                updatedDescriptor.DescriptorUid = (Guid)descriptorUidAsObject;
            }
            else
            {
                // This case occurs if the relationship type has been changed and previously this descriptor didn't exist for this relationship type.
                Guid newDescriptorUid;

                SqlCommand createDescriptorCommand = CreateDescriptorCommand(connectionAbstraction.Connection, out newDescriptorUid, updatedDescriptor);
                updatedDescriptor.DescriptorUid = newDescriptorUid;

                connectionAbstraction.Open();
                createDescriptorCommand.ExecuteNonQuery();
                connectionAbstraction.Close();
            }

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

            transactionWrapper.ResponseParameter.Value = updatedDescriptor.DescriptorUid;
        }
        public QueryResponse CreateRootMap(IGlymaSession glymaSession, Guid domainId, string name, NodeType nodeType, string originalId)
        {
            IDbConnectionAbstraction mapDbConnection        = null;
            IDbConnectionAbstraction parametersDbConnection = null;
            IDbConnectionAbstraction sessionDbConnection    = null;

            try
            {
                mapDbConnection        = glymaSession.ConnectionFactory.CreateMapDbConnection();
                parametersDbConnection = glymaSession.ConnectionFactory.CreateParametersDbConnection();
                sessionDbConnection    = glymaSession.ConnectionFactory.CreateSessionDbConnection();

                CreateRootMap createRootMapOperation = new CreateRootMap(mapDbConnection, parametersDbConnection, sessionDbConnection);

                mapDbConnection.Open();
                parametersDbConnection.Open();
                sessionDbConnection.Open();

                Guid nodeId = createRootMapOperation.Create(domainId, name, nodeType, originalId);

                sessionDbConnection.Close();
                parametersDbConnection.Close();
                mapDbConnection.Close();

                QueryResponse response = QueryMap(glymaSession, domainId, nodeId, 0, false, null, null, 0, false);

                return(response);
            }
            finally
            {
                if (mapDbConnection != null)
                {
                    mapDbConnection.Dispose();
                }

                if (parametersDbConnection != null)
                {
                    parametersDbConnection.Dispose();
                }

                if (sessionDbConnection != null)
                {
                    sessionDbConnection.Dispose();
                }
            }
        }
        public int DeleteDomain(IGlymaSession glymaSession, Guid domainId)
        {
            IDbConnectionAbstraction mapDbConnection        = null;
            IDbConnectionAbstraction parametersDbConnection = null;
            IDbConnectionAbstraction sessionDbConnection    = null;

            int deletions = -1;

            try
            {
                mapDbConnection        = glymaSession.ConnectionFactory.CreateMapDbConnection();
                parametersDbConnection = glymaSession.ConnectionFactory.CreateParametersDbConnection();
                sessionDbConnection    = glymaSession.ConnectionFactory.CreateSessionDbConnection();

                DeleteDomain deleteDomainOperation = new DeleteDomain(mapDbConnection, parametersDbConnection, sessionDbConnection);

                mapDbConnection.Open();
                parametersDbConnection.Open();
                sessionDbConnection.Open();

                deletions = deleteDomainOperation.ExecuteDeletion(domainId);

                sessionDbConnection.Close();
                parametersDbConnection.Close();
                mapDbConnection.Close();
            }
            finally
            {
                if (mapDbConnection != null)
                {
                    mapDbConnection.Dispose();
                }

                if (parametersDbConnection != null)
                {
                    parametersDbConnection.Dispose();
                }

                if (sessionDbConnection != null)
                {
                    sessionDbConnection.Dispose();
                }
            }

            return(deletions);
        }
Esempio n. 13
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            SqlCommand command = SelectDeleteRelationshipDescriptorsMetadataCommand(connectionAbstraction.Connection, transactionWrapper.RelationshipParameter.Value);

            connectionAbstraction.Open();

            SqlDataReader reader = command.ExecuteReader();

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

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

                if (reader.NextResult())
                {
                    while (reader.Read())
                    {
                        Descriptor deletedDescriptor = new Descriptor();
                        deletedDescriptor.LoadElement(reader);

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

                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.DeleteRelationship));
                    }
                }

                transactionWrapper.ResponseParameter.Value = deletedRelationship.RelationshipUid;
            }
            connectionAbstraction.Close();
        }
Esempio n. 14
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();
        }
Esempio n. 15
0
        public bool ExistsInDb(IDbConnectionAbstraction connectionAbstraction)
        {
            SqlCommand checkExistsSqlCommand = new SqlCommand(CheckParameterExists, connectionAbstraction.Connection);

            checkExistsSqlCommand.Parameters.Add(IdSqlParameter);

            connectionAbstraction.Open();
            int numberOfItems = (int)checkExistsSqlCommand.ExecuteScalar();

            connectionAbstraction.Close();

            if (numberOfItems > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 16
0
        public bool ExecuteIsCompletedQuery()
        {
            using (IDbConnectionAbstraction sessionDbConnection = GlymaSession.ConnectionFactory.CreateSessionDbConnection())
            {
                SqlCommand command = CreateQuerySessionCommand(sessionDbConnection.Connection);

                sessionDbConnection.Open();
                int numberOfCompleteRows = (int)command.ExecuteScalar();
                sessionDbConnection.Close();

                if (numberOfCompleteRows > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 17
0
        protected void CreateNewSession()
        {
            SqlParameter user = new SqlParameter("@User", User);
            SqlParameter transactionTimestamp = new SqlParameter("@TransactionTimestamp", DateTime.Now.ToUniversalTime());
            SqlParameter sessionId            = new SqlParameter("@SessionUid", Id);
            SqlParameter operationId          = new SqlParameter("@OperationId", TransactionType.BeginSession);

            using (IDbConnectionAbstraction sessionDbConnection = GlymaSession.ConnectionFactory.CreateSessionDbConnection())
            {
                SqlCommand insertSessionTransaction = new SqlCommand(InsertSessionTransactionSqlQuery, sessionDbConnection.Connection);
                insertSessionTransaction.Parameters.Add(user);
                insertSessionTransaction.Parameters.Add(transactionTimestamp);
                insertSessionTransaction.Parameters.Add(sessionId);
                insertSessionTransaction.Parameters.Add(operationId);

                sessionDbConnection.Open();
                insertSessionTransaction.ExecuteNonQuery();
                sessionDbConnection.Close();
            }
        }
Esempio n. 18
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            SqlCommand command = SelectDeleteMetadataCommand(connectionAbstraction.Connection, transactionWrapper.MetadataParameter.Value);

            connectionAbstraction.Open();

            SqlDataReader reader = command.ExecuteReader();

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

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

                transactionWrapper.ResponseParameter.Value = deletedMetadata.MetadataId;
            }
            connectionAbstraction.Close();
        }
Esempio n. 19
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            SqlCommand command = SelectDeleteMetadataCommand(connectionAbstraction.Connection, transactionWrapper.MetadataParameter.Value);

            connectionAbstraction.Open();

            SqlDataReader reader = command.ExecuteReader();

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

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

                transactionWrapper.ResponseParameter.Value = deletedMetadata.MetadataId;
            }
            connectionAbstraction.Close();
        }
Esempio n. 20
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            Descriptor newDescriptor = new Descriptor();
            newDescriptor.DescriptorTypeUid = transaction.DescriptorTypeUid.Value;
            newDescriptor.NodeUid = transactionWrapper.NodeParameter.Value;
            newDescriptor.RelationshipUid = transactionWrapper.RelationshipParameter.Value;

            Guid newDescriptorId;

            SqlCommand command = CreateDescriptorCommand(connectionAbstraction.Connection, out newDescriptorId, newDescriptor);

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

            newDescriptor.DescriptorUid = newDescriptorId;
            response.Changes.Add(new MapChange(transaction.TransactionId, newDescriptor, TransactionType.CreateDescriptor));

            transactionWrapper.ResponseParameter.Value = newDescriptorId;
        }
Esempio n. 21
0
        public MapParameter this[Guid parameterId]
        {
            get
            {
                if (ParameterContainer.ContainsKey(parameterId))
                {
                    return(ParameterContainer[parameterId]);
                }
                else
                {
                    SqlParameter parameterIdSqlParameter = new SqlParameter("@ParameterId", parameterId);

                    using (IDbConnectionAbstraction parametersDbConnection = GlymaSession.ConnectionFactory.CreateParametersDbConnection())
                    {
                        SqlCommand getParameter = new SqlCommand("SELECT * FROM [Parameters] WHERE [ParameterUid] = @ParameterId;", parametersDbConnection.Connection);
                        getParameter.Parameters.Add(parameterIdSqlParameter);

                        parametersDbConnection.Open();

                        IDataReader parameters = getParameter.ExecuteReader();

                        MapParameter parameter = null;

                        while (parameters.Read())
                        {
                            parameter = new MapParameter();

                            parameter.LoadSessionObject(parameters);

                            AddParameter(parameter);
                        }

                        parametersDbConnection.Close();

                        return(parameter);
                    }
                }
            }
        }
Esempio n. 22
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            Relationship newRelationship = new Relationship();

            newRelationship.RelationshipTypeUid = transaction.RelationshipTypeUid.Value;
            newRelationship.DomainUid           = transactionWrapper.DomainParameter.Value;

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

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

            Guid newRelationshipId;

            SqlCommand command = CreateRelationshipCommand(connectionAbstraction.Connection, out newRelationshipId, newRelationship);

            connectionAbstraction.Open();

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

            newRelationship.RelationshipUid = newRelationshipId;
            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, newRelationship, TransactionType.CreateRelationship));

            transactionWrapper.ResponseParameter.Value = newRelationshipId;
        }
Esempio n. 23
0
        public bool CheckRootMapAuthorisationBaseOnNode(Guid domainId, Guid nodeId, params IRight[] requiredRights)
        {
            using (IDbConnectionAbstraction connectionAbstraction = GlymaSession.ConnectionFactory.CreateMapDbConnection())
            {
                SqlCommand findRootMapIdCommand = BuildFindRootMapIdCommand(connectionAbstraction.Connection, domainId, nodeId);

                connectionAbstraction.Open();
                object rootMapIdQueryResult = findRootMapIdCommand.ExecuteScalar();
                connectionAbstraction.Close();

                if (rootMapIdQueryResult != null && rootMapIdQueryResult != DBNull.Value && rootMapIdQueryResult is Guid)
                {
                    Guid rootMapId = (Guid)rootMapIdQueryResult;

                    return(GlymaUser.IsAuthorised(domainId, rootMapId, requiredRights));
                }
                else
                {
                    return(GlymaUser.IsAuthorised(domainId, requiredRights));
                }
            }
        }
Esempio n. 24
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            Relationship newRelationship = new Relationship();
            newRelationship.RelationshipTypeUid = transaction.RelationshipTypeUid.Value;
            newRelationship.DomainUid = transactionWrapper.DomainParameter.Value;

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

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

            Guid newRelationshipId;

            SqlCommand command = CreateRelationshipCommand(connectionAbstraction.Connection, out newRelationshipId, newRelationship);

            connectionAbstraction.Open();

            command.ExecuteNonQuery();
            connectionAbstraction.Close();
            
            newRelationship.RelationshipUid = newRelationshipId;
            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, newRelationship, TransactionType.CreateRelationship));

            transactionWrapper.ResponseParameter.Value = newRelationshipId;
        }
Esempio n. 25
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            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;
        }
Esempio n. 26
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now.ToUniversalTime();

            Relationship updatedRelationship = new Relationship();
            updatedRelationship.DomainUid = transactionWrapper.DomainParameter.Value;
            updatedRelationship.RelationshipUid = transactionWrapper.RelationshipParameter.Value;
            updatedRelationship.RelationshipTypeUid = transaction.RelationshipTypeUid.Value;
            updatedRelationship.Modified = currentTime;
            updatedRelationship.ModifiedBy = transaction.User;

            SqlCommand updateRelationshipCommand = UpdateRelationshipCommand(connectionAbstraction.Connection, updatedRelationship);

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

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

            transactionWrapper.ResponseParameter.Value = updatedRelationship.RelationshipUid;
        }
Esempio n. 27
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            Descriptor newDescriptor = new Descriptor();

            newDescriptor.DescriptorTypeUid = transaction.DescriptorTypeUid.Value;
            newDescriptor.NodeUid           = transactionWrapper.NodeParameter.Value;
            newDescriptor.RelationshipUid   = transactionWrapper.RelationshipParameter.Value;

            Guid newDescriptorId;

            SqlCommand command = CreateDescriptorCommand(connectionAbstraction.Connection, out newDescriptorId, newDescriptor);

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

            newDescriptor.DescriptorUid = newDescriptorId;
            response.Changes.Add(new MapChange(transaction.TransactionId, newDescriptor, TransactionType.CreateDescriptor));

            transactionWrapper.ResponseParameter.Value = newDescriptorId;
        }
Esempio n. 28
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now.ToUniversalTime();

            Metadata updatedMetadata = new Metadata();
            updatedMetadata.MetadataId = transactionWrapper.MetadataParameter.Value;
            updatedMetadata.MetadataName = transaction.MetadataName;
            updatedMetadata.MetadataValue = transaction.MetadataValue;
            updatedMetadata.Modified = currentTime;
            updatedMetadata.ModifiedBy = transaction.User;

            SqlCommand command = UpdateMetadataCommand(connectionAbstraction.Connection, updatedMetadata);

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

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

            transactionWrapper.ResponseParameter.Value = updatedMetadata.MetadataId;
        }
Esempio n. 29
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            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;
        }
Esempio n. 30
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now.ToUniversalTime();

            Metadata updatedMetadata = new Metadata();

            updatedMetadata.MetadataId    = transactionWrapper.MetadataParameter.Value;
            updatedMetadata.MetadataName  = transaction.MetadataName;
            updatedMetadata.MetadataValue = transaction.MetadataValue;
            updatedMetadata.Modified      = currentTime;
            updatedMetadata.ModifiedBy    = transaction.User;

            SqlCommand command = UpdateMetadataCommand(connectionAbstraction.Connection, updatedMetadata);

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

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

            transactionWrapper.ResponseParameter.Value = updatedMetadata.MetadataId;
        }
Esempio n. 31
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now.ToUniversalTime();

            Relationship updatedRelationship = new Relationship();

            updatedRelationship.DomainUid           = transactionWrapper.DomainParameter.Value;
            updatedRelationship.RelationshipUid     = transactionWrapper.RelationshipParameter.Value;
            updatedRelationship.RelationshipTypeUid = transaction.RelationshipTypeUid.Value;
            updatedRelationship.Modified            = currentTime;
            updatedRelationship.ModifiedBy          = transaction.User;

            SqlCommand updateRelationshipCommand = UpdateRelationshipCommand(connectionAbstraction.Connection, updatedRelationship);

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

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

            transactionWrapper.ResponseParameter.Value = updatedRelationship.RelationshipUid;
        }
        public QueryResponse QueryMap(IGlymaSession glymaSession, Guid domainId, Guid nodeId, int maxDepth, bool isFullDomainSearch, EdgeConditions edgeConditions, FilterConditions filterConditions, int objectIndex, bool isCompressed)
        {
            if (!isCompressed)
            {
                TransactionalMappingToolServiceCommonBase.SoftObjectLimit = 3000;
                TransactionalMappingToolServiceCommonBase.HardObjectLimit = 4000;
            }
            else
            {
                TransactionalMappingToolServiceCommonBase.SoftObjectLimit = 5500;
                TransactionalMappingToolServiceCommonBase.HardObjectLimit = 6500;
            }

            using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection())
            {
                SqlCommand queryMapCommand = new SqlCommand("QueryMap", mapDbConnection.Connection);
                queryMapCommand.CommandType = CommandType.StoredProcedure;
                queryMapCommand.Parameters.Add(new SqlParameter("@DomainId", domainId));
                queryMapCommand.Parameters.Add(new SqlParameter("@NodeId", nodeId));
                queryMapCommand.Parameters.Add(new SqlParameter("@Depth", maxDepth));
                queryMapCommand.Parameters.Add(new SqlParameter("@FullDomain", isFullDomainSearch));

                mapDbConnection.Open();

                SqlDataReader queryMapResults = queryMapCommand.ExecuteReader();

                QueryResponse queryResponse = new QueryResponse();

                List <Node>[] orderedNodes = new List <Node> [maxDepth + 1];

                do
                {
                    while (queryMapResults.Read())
                    {
                        if (queryMapResults.GetSchemaTable().Select("ColumnName = 'Level'").Length > 0)
                        {
                            Node node = new Node();
                            node.LoadElement(queryMapResults);

                            List <Node> nodes;

                            if (orderedNodes[node.Depth] != null)
                            {
                                nodes = orderedNodes[node.Depth];
                            }
                            else
                            {
                                nodes = new List <Node>();
                                orderedNodes[node.Depth] = nodes;
                            }

                            nodes.Add(node);

                            queryResponse.AddNode(node);
                        }
                        else if (queryMapResults.GetSchemaTable().Select("ColumnName = 'MetadataId'").Length > 0)
                        {
                            Metadata metadata = new Metadata();
                            metadata.LoadElement(queryMapResults);

                            queryResponse.AddMetadata(metadata);
                        }
                        else if (queryMapResults.GetSchemaTable().Select("ColumnName = 'DescriptorUid'").Length > 0)
                        {
                            Descriptor descriptor = new Descriptor();
                            descriptor.LoadElement(queryMapResults);

                            queryResponse.AddDescriptor(descriptor);
                        }
                        else if (queryMapResults.GetSchemaTable().Select("ColumnName = 'RelationshipUid'").Length > 0)
                        {
                            Relationship relationship = new Relationship();
                            relationship.LoadElement(queryMapResults);

                            queryResponse.AddRelationship(relationship);
                        }
                    }
                }while (queryMapResults.NextResult());

                mapDbConnection.Close();

                try
                {
                    mapDbConnection.Open();
                    AuditLogItem logItem = new AuditLogItem(mapDbConnection.Connection);
                    logItem.OperationName = "QueryMap";
                    //logItem.CallingUrl = callingUrl;
                    logItem.DomainUid        = domainId;
                    logItem.NodeUid          = nodeId;
                    logItem.RootMapUid       = null;
                    logItem.MaxDepth         = maxDepth;
                    logItem.ObjectIndex      = objectIndex;
                    logItem.EdgeConditions   = null;
                    logItem.FilterConditions = null;
                    logItem.SearchConditions = null;
                    logItem.PageNumber       = null;
                    logItem.PageSize         = null;
                    logItem.Commit();
                    mapDbConnection.Close();
                }
                catch
                {
                    /// Don't do anything. This is here because audit logging is a very low importance task and we don't want it potentially killing the more important tasks at hand.
                }

                if (!queryResponse.Nodes.ContainsKey(nodeId))
                {
                    queryResponse.ErrorId      = 1;
                    queryResponse.ErrorMessage = "Provided node ID context doesn't exist";

                    return(queryResponse);
                }

                queryResponse.AttachElements();
                queryResponse.NodeContext = queryResponse.Nodes[nodeId];

                if (maxDepth > 0 && edgeConditions != null && edgeConditions.EdgeCondition != null)
                {
                    List <Guid> nodesToRemove         = new List <Guid>();
                    List <Guid> relationshipsToRemove = new List <Guid>();

                    List <Guid> boundaryNodes         = new List <Guid>();
                    List <Guid> boundaryRelationships = new List <Guid>();

                    for (int i = 1; i <= maxDepth; i++)
                    {
                        List <Node> nodes = orderedNodes[i];

                        foreach (Node node in nodes)
                        {
                            bool         isBoundaryNode         = false;
                            bool         isBoundaryRelationship = false;
                            bool         isNodeIncluded         = true;
                            bool         isRelationshipIncluded = true;
                            Relationship connectingRelationship = queryResponse.Relationships[node.ConnectingRelationship];

                            if (boundaryNodes.Contains(node.Origin))
                            {
                                isBoundaryNode         = true;
                                isBoundaryRelationship = true;
                                isNodeIncluded         = false;
                                isRelationshipIncluded = false;
                            }
                            else
                            {
                                EdgeResult relationshipEvalResult = edgeConditions.EdgeCondition.EvaluateCondition(connectingRelationship);

                                if (relationshipEvalResult.IsEdge.HasValue && relationshipEvalResult.IsEdge.Value)
                                {
                                    // THis means the relationship was evaluated to be a boundary edge.
                                    isBoundaryRelationship = true;
                                    isRelationshipIncluded = relationshipEvalResult.IsIncluded;
                                }

                                EdgeResult nodeEvalResult = edgeConditions.EdgeCondition.EvaluateCondition(node);

                                if (nodeEvalResult.IsEdge.HasValue && nodeEvalResult.IsEdge.Value)
                                {
                                    // This means the node was evaluated to be a boundary edge.
                                    isBoundaryNode = true;
                                    isNodeIncluded = nodeEvalResult.IsIncluded;
                                    // The inclusion value for the node trumps the relationship value as the relationship is dependent on the node existing anyway.
                                    isRelationshipIncluded = isNodeIncluded;
                                }
                                else if (isBoundaryRelationship)
                                {
                                    // If the relationship was discovered to be a boundary then this node will be a boundary edge too.
                                    isBoundaryNode = true;
                                    isNodeIncluded = isRelationshipIncluded;
                                }
                            }

                            if (isBoundaryNode)
                            {
                                boundaryNodes.Add(node.NodeUid);
                            }

                            if (isBoundaryRelationship)
                            {
                                boundaryRelationships.Add(connectingRelationship.RelationshipUid);
                            }

                            if (!isNodeIncluded)
                            {
                                nodesToRemove.Add(node.NodeUid);
                            }

                            if (!isRelationshipIncluded)
                            {
                                relationshipsToRemove.Add(connectingRelationship.RelationshipUid);
                            }
                        }
                    }

                    foreach (Guid nodeIdToRemove in nodesToRemove)
                    {
                        queryResponse.Nodes.Remove(nodeIdToRemove);
                    }

                    foreach (Guid relationshipIdToRemove in relationshipsToRemove)
                    {
                        queryResponse.Relationships.Remove(relationshipIdToRemove);
                    }
                }

                int totalObjects = queryResponse.CountObjects();

                queryResponse.Domain           = new Domain();
                queryResponse.Domain.DomainUid = domainId;

                if (totalObjects > TransactionalMappingToolServiceCommonBase.HardObjectLimit || objectIndex > 0)
                {
                    return(queryResponse.GetPage(objectIndex));
                }

                return(queryResponse);
            }
        }
        /// <summary>
        /// TODO: This method needs to be moved from here as it makes calls to schema specific methods.
        /// </summary>
        /// <param name="callingUrl"></param>
        /// <param name="domainId"></param>
        /// <param name="conditions"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public SearchMapResult SearchMap(IGlymaSession glymaSession, Guid domainId, Guid rootMapUid, SearchConditions conditions, int pageNumber = 1, int pageSize = 5)
        {
            SearchMapResult result = new SearchMapResult();

            using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection())
            {
                mapDbConnection.Open();

                SqlCommand findMetadata = conditions.BuildSearchQuery(mapDbConnection.Connection, rootMapUid, pageNumber, pageSize);

                SqlDataReader matchingMetadata = findMetadata.ExecuteReader();

                matchingMetadata.Read();
                int totalMetadataCount = (int)matchingMetadata[0];
                matchingMetadata.NextResult();

                int currentMetadataPagePosition = pageNumber * pageSize;

                DataTable nodesList;

                result.Count = totalMetadataCount;

                if (currentMetadataPagePosition > totalMetadataCount && pageNumber > 1)
                {
                    int itemsToRemove = currentMetadataPagePosition - totalMetadataCount;

                    if (itemsToRemove >= pageSize)
                    {
                        result = new SearchMapResult();

                        return(result);
                    }
                    else
                    {
                        nodesList = new DataTable("NodesList");
                        nodesList.Load(matchingMetadata);

                        for (int i = 0; i < itemsToRemove; i++)
                        {
                            nodesList.Rows.RemoveAt(0);
                        }

                        nodesList.Columns.Remove("Modified");
                    }
                }
                else
                {
                    nodesList = new DataTable("NodesList");
                    nodesList.Load(matchingMetadata);
                    nodesList.Columns.Remove("Modified");
                }

                QueryNodes queryNodes = new QueryNodes(mapDbConnection);
                Dictionary <Guid, SearchedNode> nodes = queryNodes.GetNodes(nodesList);

                result.SearchedNodes = nodes;

                mapDbConnection.Close();

                try
                {
                    mapDbConnection.Open();
                    AuditLogItem logItem = new AuditLogItem(mapDbConnection.Connection);
                    logItem.OperationName = "SearchMap";
                    //logItem.CallingUrl = callingUrl;
                    logItem.DomainUid        = domainId;
                    logItem.NodeUid          = null;
                    logItem.RootMapUid       = rootMapUid;
                    logItem.MaxDepth         = null;
                    logItem.ObjectIndex      = null;
                    logItem.EdgeConditions   = null;
                    logItem.FilterConditions = null;
                    logItem.SearchConditions = null;
                    logItem.PageNumber       = pageNumber;
                    logItem.PageSize         = pageSize;
                    logItem.Commit();
                    mapDbConnection.Close();
                }
                catch
                {
                    /// Don't do anything. This is here because audit logging is a very low importance task and we don't want it potentially killing the more important tasks at hand.
                }

                return(result);
            }
        }
Esempio n. 34
0
        public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
        {
            /// If this is a delayed transaction then we'll never need to update this. The reasons are -
            /// 1. Changing the ID of this object is pointless as it would violate referential integrity.
            /// 2. Changing the Session ID would never happen as this would breach Session fidelity.
            /// 3. Changing the Parameter Type is not going to happen. As this would already be referenced
            ///    in multiple places it would be changing a pre-existing and expected context.
            /// 4. The value never needs to be inserted as this is delayed and will be defined when the
            ///    transaction operation is run. - This isn't true, we do need the value to be updated in case we're referring to a MapParameter from an old transaction.
            if (!ValueUpdated && IsDelayed && !IsNew)
            {
                return;
            }

            SqlCommand parameterSqlCommand = null;

            try
            {
                bool addValue;

                if (IsNew && !ExistsInDb(connectionAbstraction))
                {
                    addValue            = true;
                    parameterSqlCommand = new SqlCommand(InsertParameter, connectionAbstraction.Connection);
                }
                else if (IsDirty)
                {
                    string updateSql;

                    if (ValueUpdated && Value != Guid.Empty)
                    {
                        updateSql = string.Format(UpdateParameter, "[Value] = @Value, ");
                        addValue  = true;
                    }
                    else
                    {
                        updateSql = string.Format(UpdateParameter, "");
                        addValue  = false;
                    }

                    parameterSqlCommand = new SqlCommand(updateSql, connectionAbstraction.Connection);
                }
                else
                {
                    return;
                }

                parameterSqlCommand.Parameters.Add(IdSqlParameter);

                if (addValue)
                {
                    parameterSqlCommand.Parameters.Add(ValueSqlParameter);
                }

                parameterSqlCommand.Parameters.Add(SessionIdSqlParameter);
                parameterSqlCommand.Parameters.Add(IsDelayedSqlParameter);
                parameterSqlCommand.Parameters.Add(ParameterTypeSqlParameter);

                connectionAbstraction.Open();
                parameterSqlCommand.ExecuteNonQuery();

                ValueUpdated = false;

                connectionAbstraction.Close();
            }
            finally
            {
                if (parameterSqlCommand != null)
                {
                    parameterSqlCommand.Dispose();
                }
            }
        }
Esempio n. 35
0
        public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
        {
            /// If this is a delayed transaction then we'll never need to update this. The reasons are -
            /// 1. Changing the ID of this object is pointless as it would violate referential integrity.
            /// 2. Changing the Session ID would never happen as this would breach Session fidelity.
            /// 3. Changing the Parameter Type is not going to happen. As this would already be referenced
            ///    in multiple places it would be changing a pre-existing and expected context.
            /// 4. The value never needs to be inserted as this is delayed and will be defined when the
            ///    transaction operation is run. - This isn't true, we do need the value to be updated in case we're referring to a MapParameter from an old transaction.
            if (!ValueUpdated && IsDelayed && !IsNew)
            {
                return;
            }

            SqlCommand parameterSqlCommand = null;

            try
            {
                bool addValue;

                if (IsNew && !ExistsInDb(connectionAbstraction))
                {
                    addValue = true;
                    parameterSqlCommand = new SqlCommand(InsertParameter, connectionAbstraction.Connection);
                }
                else if (IsDirty)
                {
                    string updateSql;

                    if (ValueUpdated && Value != Guid.Empty)
                    {
                        updateSql = string.Format(UpdateParameter, "[Value] = @Value, ");
                        addValue = true;
                    }
                    else
                    {
                        updateSql = string.Format(UpdateParameter, "");
                        addValue = false;
                    }

                    parameterSqlCommand = new SqlCommand(updateSql, connectionAbstraction.Connection);
                }
                else
                {
                    return;
                }

                parameterSqlCommand.Parameters.Add(IdSqlParameter);

                if (addValue)
                {
                    parameterSqlCommand.Parameters.Add(ValueSqlParameter);
                }

                parameterSqlCommand.Parameters.Add(SessionIdSqlParameter);
                parameterSqlCommand.Parameters.Add(IsDelayedSqlParameter);
                parameterSqlCommand.Parameters.Add(ParameterTypeSqlParameter);

                connectionAbstraction.Open();
                parameterSqlCommand.ExecuteNonQuery();

                ValueUpdated = false;

                connectionAbstraction.Close();
            }
            finally
            {
                if (parameterSqlCommand != null)
                {
                    parameterSqlCommand.Dispose();
                }
            }
        }
Esempio n. 36
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            Metadata newMetadata = new Metadata();

            newMetadata.MetadataTypeUid = transaction.MetadataTypeUid.Value;
            newMetadata.DomainUid       = transactionWrapper.DomainParameter.Value;

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

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

            if (transactionWrapper.NodeParameter == null)
            {
                newMetadata.NodeUid = null;
            }
            else
            {
                newMetadata.NodeUid = transactionWrapper.NodeParameter.Value;
            }

            if (transactionWrapper.RelationshipParameter == null)
            {
                newMetadata.RelationshipUid = null;
            }
            else
            {
                newMetadata.RelationshipUid = transactionWrapper.RelationshipParameter.Value;
            }

            if (transaction.DescriptorTypeUid == null)
            {
                newMetadata.DescriptorTypeUid = null;
            }
            else
            {
                newMetadata.DescriptorTypeUid = transaction.DescriptorTypeUid.Value;
            }

            newMetadata.MetadataName  = transaction.MetadataName;
            newMetadata.MetadataValue = transaction.MetadataValue;

            Guid newMetadataId;

            SqlCommand command = CreateMetadataCommand(connectionAbstraction.Connection, out newMetadataId, newMetadata);

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

            newMetadata.MetadataId = newMetadataId;
            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, newMetadata, TransactionType.CreateMetadata));

            transactionWrapper.ResponseParameter.Value = newMetadataId;
        }
Esempio n. 37
0
        public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
        {
            Dictionary<string, object>.Enumerator parameters = _parameters.GetEnumerator();

            using (SqlCommand command = new SqlCommand())
            {
                IQueryBuilder queryBuilder = null;

                if (IsNew)
                {
                    queryBuilder = new InsertQueryBuilder();
                }
                else if (IsDirty)
                {
                    queryBuilder = new UpdateQueryBuilder();
                }
                else
                {
                    return;
                }

                while (parameters.MoveNext())
                {
                    queryBuilder.AddParameter(parameters.Current.Key, parameters.Current.Value);
                }

                command.Parameters.AddRange(queryBuilder.GenerateSqlParameters());
                command.Connection = connectionAbstraction.Connection;
                command.CommandText = queryBuilder.GenerateSqlQuery();

                connectionAbstraction.Open();
                TransactionId = long.Parse(command.ExecuteScalar().ToString());
                connectionAbstraction.Close();
            }
        }
Esempio n. 38
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            Metadata newMetadata = new Metadata();
            newMetadata.MetadataTypeUid = transaction.MetadataTypeUid.Value;
            newMetadata.DomainUid = transactionWrapper.DomainParameter.Value;

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

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

            if (transactionWrapper.NodeParameter == null)
            {
                newMetadata.NodeUid = null;
            }
            else
            {
                newMetadata.NodeUid = transactionWrapper.NodeParameter.Value;
            }

            if (transactionWrapper.RelationshipParameter == null)
            {
                newMetadata.RelationshipUid = null;
            }
            else
            {
                newMetadata.RelationshipUid = transactionWrapper.RelationshipParameter.Value;
            }

            if (transaction.DescriptorTypeUid == null)
            {
                newMetadata.DescriptorTypeUid = null;
            }
            else
            {
                newMetadata.DescriptorTypeUid = transaction.DescriptorTypeUid.Value;
            }

            newMetadata.MetadataName = transaction.MetadataName;
            newMetadata.MetadataValue = transaction.MetadataValue;

            Guid newMetadataId;

            SqlCommand command = CreateMetadataCommand(connectionAbstraction.Connection, out newMetadataId, newMetadata);

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

            newMetadata.MetadataId = newMetadataId;
            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, newMetadata, TransactionType.CreateMetadata));

            transactionWrapper.ResponseParameter.Value = newMetadataId;
        }
Esempio n. 39
0
        public bool ExistsInDb(IDbConnectionAbstraction connectionAbstraction)
        {
            SqlCommand checkExistsSqlCommand = new SqlCommand(CheckParameterExists, connectionAbstraction.Connection);
            checkExistsSqlCommand.Parameters.Add(IdSqlParameter);

            connectionAbstraction.Open();
            int numberOfItems = (int)checkExistsSqlCommand.ExecuteScalar();
            connectionAbstraction.Close();

            if (numberOfItems > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }