/// <summary>
        /// Gets the securable context identifier for the siteID
        /// </summary>
        /// <returns>The Securable Context ID associated with the SP Site ID or -1 if it doesn't exist</returns>
        internal SecurableContext GetSecurableContext()
        {
            SecurableContext result = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(this.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            var securableContext = from sc in dataContext.SecurableContexts
                                                   where sc.SecurableContextId == glymaSession.SecurableContextId
                                                   select sc;
                            if (securableContext.Any())
                            {
                                result = securableContext.First();
                            }
                        }
                    }
                }
            });
            return(result);
        }
Esempio n. 2
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. 3
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();
            }
        }
        internal SecurableObject CreateSecurableObject(bool breaksInheritance)
        {
            SecurableObject createdSecurableObject = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(Context.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            SecurableObject securableObject    = new SecurableObject();
                            securableObject.SecurableObjectUid = SecurableObject.SecurableObjectUid;
                            securableObject.BreaksInheritance  = breaksInheritance;
                            securableObject.SecurableContextId = SecurableContextId;
                            dataContext.SecurableObjects.InsertOnSubmit(securableObject);
                            dataContext.SubmitChanges();

                            // Return the group that was created
                            securableObject = (from so in dataContext.SecurableObjects
                                               where so.SecurableObjectUid == SecurableObject.SecurableObjectUid &&
                                               so.SecurableContextId == SecurableContextId
                                               select so).First();
                            createdSecurableObject = securableObject;
                        }
                    }
                }
            });

            return(createdSecurableObject);
        }
        private void CopyGroupAssociationsToRootMap(GlymaSecurableObject rootMapSecurableObject)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(this.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            var groupAssociations = from ga in dataContext.GroupAssociations
                                                    where ga.SecurableObjectUid == rootMapSecurableObject.SecurableParentUid
                                                    select ga;

                            if (groupAssociations.Any())
                            {
                                foreach (GroupAssociation groupAssociation in groupAssociations)
                                {
                                    GlymaSecurableObject securableObject = new GlymaSecurableObject();
                                    securableObject.SecurableParentUid   = groupAssociation.SecurableObjectUid;       //the parent is now the project uid
                                    securableObject.SecurableObjectUid   = rootMapSecurableObject.SecurableObjectUid; //the object is now the root map being copied to
                                    GlymaSecurityAssociationContext securityAssocationContext = new GlymaSecurityAssociationContext(this, rootMapSecurableObject);
                                    securityAssocationContext.CreateGroupAssociation(groupAssociation.GroupId);
                                }
                            }
                        }
                    }
                }
            });
        }
        internal Group GetGroup(GlymaSecurityGroup securityGroup)
        {
            Group result = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(this.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            var groups = from g in dataContext.Groups
                                         where g.GroupId == securityGroup.GroupId &&
                                         g.SecurableContextId == securityGroup.SecurableContextId
                                         select g;

                            Group group = null; //default value if it doesn't exist
                            if (groups.Any())
                            {
                                group = groups.First();
                            }
                            result = group;
                        }
                    }
                }
            });
            return(result);
        }
        private void RemoveRootMapGroupAssociations(GlymaSecurableObject rootMapSecurableObject)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(this.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            var groupAssociations = from ga in dataContext.GroupAssociations
                                                    where ga.SecurableObjectUid == rootMapSecurableObject.SecurableObjectUid &&
                                                    ga.SecurableParentUid == rootMapSecurableObject.SecurableParentUid
                                                    select ga;

                            if (groupAssociations.Any())
                            {
                                foreach (GroupAssociation groupAssociation in groupAssociations)
                                {
                                    dataContext.GroupAssociations.DeleteOnSubmit(groupAssociation);
                                }
                                dataContext.SubmitChanges();
                            }
                        }
                    }
                }
            });
        }
Esempio n. 8
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. 9
0
        /// <summary>
        /// Creates the GroupAssociation
        /// </summary>
        /// <param name="groupId">The ID of the Group object</param>
        internal void CreateGroupAssociation(int groupId)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(Context.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            SecurableContext securableContext = Context.GetSecurableContext();
                            int securableContextId            = securableContext.SecurableContextId;

                            GroupAssociation groupAssociation   = new GroupAssociation();
                            groupAssociation.GroupId            = groupId;
                            groupAssociation.SecurableContextId = securableContextId;
                            if (SecurableObject.SecurableParentUid != Guid.Empty)
                            {
                                //group association is for a root map (not a project)
                                groupAssociation.SecurableParentUid = SecurableObject.SecurableParentUid;
                            }
                            groupAssociation.SecurableObjectUid = SecurableObject.SecurableObjectUid;
                            dataContext.GroupAssociations.InsertOnSubmit(groupAssociation);
                            dataContext.SubmitChanges();
                        }
                    }
                }
            });
        }
        /// <summary>
        /// Creates the Group in the database
        /// </summary>
        /// <param name="glGroup">The details of the group</param>
        /// <returns>The group object that was created</returns>
        internal Group CreateGroup(string displayName)
        {
            Group createdGroup = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(Context.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            // Create the group
                            Group group = new Group();
                            group.SecurableContextId = SecurableContextId;
                            group.GroupSPID          = SPGroupId;
                            group.WebSPID            = WebId;
                            group.DisplayName        = displayName;
                            dataContext.Groups.InsertOnSubmit(group);
                            dataContext.SubmitChanges();

                            // Return the group that was created
                            group = (from g in dataContext.Groups
                                     where g.DisplayName == displayName && g.GroupSPID == SPGroupId &&
                                     g.SecurableContextId == SecurableContextId && g.WebSPID == WebId
                                     select g).First();
                            createdGroup = group;
                        }
                    }
                }
            });
            return(createdGroup);
        }
        public MapResponse CreateDomain(IGlymaSession glymaSession, string name)
        {
            using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection())
            {
                Domain newDomain = new Domain(true);
                newDomain.DomainUid        = Guid.NewGuid();
                newDomain.DomainOriginalId = null;

                TypeResponse types = GetAllMapTypes(glymaSession);

                NodeType     domainNodeType     = types.NodeTypes["DomainNode"];
                MetadataType stringMetadataType = types.MetadataTypes["string"];

                newDomain.PersistSessionObject(mapDbConnection);

                Guid sessionId = BeginTransaction(glymaSession);

                MapParameter domainIdParameter = new MapParameter();
                domainIdParameter.Id            = Guid.NewGuid();
                domainIdParameter.IsDelayed     = false;
                domainIdParameter.ParameterType = MapParameterType.Domain;
                domainIdParameter.SessionId     = sessionId;
                domainIdParameter.Value         = newDomain.DomainUid;

                MapParameter newNode = AddNode(glymaSession, sessionId, domainIdParameter, null, domainNodeType, string.Empty);
                AddMetadata(glymaSession, sessionId, domainIdParameter, null, newNode, null, null, stringMetadataType, "Name", name);

                MapResponse newDomainNodeResponse = CompleteTransaction(glymaSession, sessionId);

                return(newDomainNodeResponse);
            }
        }
Esempio n. 12
0
        internal SecurableObject GetSecurableObject(int securableContextId, Guid securableObjectUid)
        {
            SecurableObject result = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(this.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            var securableObjects = from so in dataContext.SecurableObjects
                                                   where so.SecurableObjectUid == securableObjectUid &&
                                                   so.SecurableContextId == securableContextId
                                                   select so;

                            SecurableObject securableObject = null; //default value if it doesn't exist
                            if (securableObjects.Any())
                            {
                                securableObject = securableObjects.First();
                            }
                            result = securableObject;
                        }
                    }
                }
            });
            return(result);
        }
        public TypeResponse GetAllMapTypes(IGlymaSession glymaSession)
        {
            using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection())
            {
                MapSchema    mapSchema = new MapSchema(mapDbConnection);
                TypeResponse response  = mapSchema.LoadTypesFromDb();

                return(response);
            }
        }
Esempio n. 14
0
 public void PersistSessionObject()
 {
     foreach (MapParameter parameter in ParameterContainer.Values)
     {
         using (IDbConnectionAbstraction parametersDbConnection = GlymaSession.ConnectionFactory.CreateParametersDbConnection())
         {
             parameter.PersistSessionObject(parametersDbConnection);
         }
     }
 }
Esempio n. 15
0
 public void ExecuteOperation(ref MapResponse response)
 {
     if (OperationEngine != null)
     {
         using (IDbConnectionAbstraction mapDbConnection = GlymaSession.ConnectionFactory.CreateMapDbConnection())
         {
             OperationEngine.ExecuteTransaction(mapDbConnection, this, ref response);
         }
     }
 }
Esempio n. 16
0
        public void ExecuteCompleteSession()
        {
            using (IDbConnectionAbstraction sessionDbConnection = GlymaSession.ConnectionFactory.CreateSessionDbConnection())
            {
                SqlCommand command = CreateCompleteSessionCommand(sessionDbConnection.Connection);

                sessionDbConnection.Open();
                command.ExecuteNonQuery();
                sessionDbConnection.Close();
            }
        }
Esempio n. 17
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. 18
0
        public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
        {
            if (IsNew)
            {
                SqlCommand createDomainCommand = CreateDomainCommand(DomainUid, DomainOriginalId);
                createDomainCommand.Connection = connectionAbstraction.Connection;

                connectionAbstraction.Open();
                createDomainCommand.ExecuteNonQuery();
                connectionAbstraction.Close();
            }
        }
        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. 21
0
        public void PersistSessionObject()
        {
            if (IsNew)
            {
                CreateNewSession();
                IsNew = false;
            }

            foreach (MapTransactionWrapper transaction in NewTransactions)
            {
                using (IDbConnectionAbstraction sessionDbConnection = GlymaSession.ConnectionFactory.CreateSessionDbConnection())
                {
                    transaction.PersistSessionObject(sessionDbConnection);
                }
            }
        }
        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);
        }
        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();
                }
            }
        }
Esempio n. 24
0
        public SPGlymaUser(SPWeb web, IGlymaSession glymaSession)
        {
            Web          = web;
            GlymaSession = glymaSession;

            SecurableContextId = GlymaSession.SecurableContextId;

            SecurityDBDataContext    dataContext          = null;
            IDbConnectionAbstraction securityDbConnection = GlymaSession.ConnectionFactory.CreateSecurityDbConnection();

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    dataContext = new SecurityDBDataContext(securityDbConnection.Connection);

                    var securableContext = (from dcSecurableContext in dataContext.SecurableContexts
                                            where dcSecurableContext.SecurableContextId == SecurableContextId
                                            select dcSecurableContext).FirstOrDefault();

                    if (securableContext == null)
                    {
                        return;
                    }

                    SecurableContextName = securableContext.SecurableContextName;
                    SecurableContextUid  = securableContext.SecurableContextUid;
                });
            }
            finally
            {
                if (dataContext != null)
                {
                    dataContext.Dispose();
                    dataContext = null;
                }

                if (securityDbConnection != null)
                {
                    securityDbConnection.Dispose();
                    securityDbConnection = null;
                }
            }
        }
Esempio n. 25
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. 26
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. 27
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. 28
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. 29
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. 30
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. 31
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();
        }
 internal void SetSecurableObjectInheritance(bool breaksInheritance)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         using (IGlymaSession glymaSession = new WebAppSPGlymaSession(Context.WebUrl))
         {
             using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
             {
                 using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                 {
                     SecurableObject securableObject = (from so in dataContext.SecurableObjects
                                                        where so.SecurableObjectUid == SecurableObject.SecurableObjectUid &&
                                                        so.SecurableContextId == SecurableContextId
                                                        select so).First();
                     securableObject.BreaksInheritance = breaksInheritance;
                     dataContext.SubmitChanges();
                 }
             }
         }
     });
 }
Esempio n. 33
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. 34
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. 35
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. 36
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. 37
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. 38
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. 39
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. 40
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. 41
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. 42
0
 public QueryNodes(IDbConnectionAbstraction mapDbConnection)
 {
     MapDbConnection = mapDbConnection;
 }
Esempio n. 43
0
 public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
 {
     Core.PersistSessionObject(connectionAbstraction);
 }
Esempio n. 44
0
 public void PersistSessionObject(IDbConnectionAbstraction connectionAbstraction)
 {
     throw new NotImplementedException();
 }
Esempio n. 45
0
 public CreateRootMap(IDbConnectionAbstraction mapDbConnection, IDbConnectionAbstraction parametersDbConnection, IDbConnectionAbstraction sessionDbConnection)
 {
     MapDbConnection = mapDbConnection;
     ParametersDbConnection = parametersDbConnection;
     SessionDbConnection = sessionDbConnection;
 }
Esempio n. 46
0
 public DeleteDomain(IDbConnectionAbstraction mapDbConnection, IDbConnectionAbstraction parametersDbConnection, IDbConnectionAbstraction sessionDbConnection)
 {
     MapDbConnection = mapDbConnection;
     ParametersDbConnection = parametersDbConnection;
     SessionDbConnection = sessionDbConnection;
 }
Esempio n. 47
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. 48
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. 49
0
        public MapSchema(IDbConnectionAbstraction mapDbConnection)
        {
            MapDbConnection = mapDbConnection;

            LoadTypesFromDb();
        }