Ejemplo n.º 1
0
        public static void FillRoles(GreyFoxUserCollection greyFoxUserCollection)
        {
            StringBuilder s;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;

            if (greyFoxUserCollection.Count > 0)
            {
                s = new StringBuilder("SELECT GreyFoxUserID, GreyFoxRoleID FROM sysGlobal_UsersChildren_Roles ORDER BY GreyFoxUserID; ");

                // Clone and sort collection by ID first to fill children in one pass
                GreyFoxUserCollection clonedCollection = greyFoxUserCollection.Clone();
                clonedCollection.Sort();

                database  = DatabaseFactory.CreateDatabase();
                dbCommand = database.GetSqlStringCommand(s.ToString());
                r         = database.ExecuteReader(dbCommand);

                bool more = r.Read();

                foreach (GreyFoxUser greyFoxUser in clonedCollection)
                {
                    GreyFoxRoleCollection roles;
                    if (greyFoxUser.roles != null)
                    {
                        roles = greyFoxUser.roles;
                        roles.Clear();
                    }
                    else
                    {
                        roles             = new GreyFoxRoleCollection();
                        greyFoxUser.roles = roles;
                    }

                    while (more)
                    {
                        if (r.GetInt32(0) < greyFoxUser.iD)
                        {
                            more = r.Read();
                        }
                        else if (r.GetInt32(0) == greyFoxUser.iD)
                        {
                            roles.Add(GreyFoxRole.NewPlaceHolder(r.GetInt32(1)));
                            more = r.Read();
                        }
                        else
                        {
                            break;
                        }
                    }

                    // No need to continue if there are no more records
                    if (!more)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public GreyFoxUserCollection DecodeString(string users, string separator)
        {
            GreyFoxUserCollection encodedUsers = new GreyFoxUserCollection();

            users = users.Trim();
            if (users.Trim() == string.Empty)
            {
                return(encodedUsers);
            }

            users = users.Replace("'", "");
            string[] names = users.Split(new string[] { separator },
                                         StringSplitOptions.RemoveEmptyEntries);

            if (names.Length < 20)
            {
                return(fastDecode(names));
            }

            GreyFoxUserCollection allUsers = GetCollection(string.Empty, string.Empty, null);

            for (int x = 0; x < allUsers.Count; x++)
            {
                for (int y = 0; y <= names.GetUpperBound(0); y++)
                {
                    if (allUsers[x].UserName == names[y])
                    {
                        encodedUsers.Add(allUsers[x]);
                    }
                }
            }

            return(encodedUsers);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Makes a shallow copy of the current GreyFoxUserCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>GreyFoxUserCollection</returns>
        public GreyFoxUserCollection Clone()
        {
            GreyFoxUserCollection clonedGreyFoxUser = new GreyFoxUserCollection(count);

            lock (this)
            {
                foreach (GreyFoxUser item in this)
                {
                    clonedGreyFoxUser.Add(item);
                }
            }
            return(clonedGreyFoxUser);
        }
Ejemplo n.º 4
0
        public GreyFoxUser GetByEmailAddress(string emailAddress)
        {
            emailAddress = emailAddress.Replace("'", "''");

            GreyFoxUserCollection results = GetCollection("Email1='" + emailAddress + "'", string.Empty, GreyFoxUserFlags.Contact);

            if (results.Count > 0)
            {
                return(results[0]);
            }
            else
            {
                throw(new Exception(string.Format("Cannot find user with email address '{0}'.", emailAddress)));
            }
        }
Ejemplo n.º 5
0
        public GreyFoxUser GetByUsername(string userName)
        {
            userName = userName.Replace("'", "''");

            GreyFoxUserCollection results =
                GetCollection("UserName='******'", string.Empty, null);

            if (results.Count > 0)
            {
                return(results[0]);
            }
            else
            {
                throw(new Exception(string.Format("Cannot find username '{0}'.",
                                                  userName)));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Makes a deep copy of the current GreyFoxUser.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the GreyFoxUserCollection from their children.</param>
        public GreyFoxUserCollection Copy(bool isolated)
        {
            GreyFoxUserCollection isolatedCollection = new GreyFoxUserCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxUserArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxUserArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
Ejemplo n.º 7
0
        public GreyFoxUserCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxUserFlags[] optionFlags)
        {
            StringBuilder         query;
            Database              database;
            DbCommand             dbCommand;
            IDataReader           r;
            GreyFoxUserCollection greyFoxUserCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("GreyFoxUser.");
                query.Append(columnName);
                query.Append(",");
            }

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int contactOffset = -1;

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxUserFlags.Contact:
                        for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Contact.");
                            query.Append(GreyFoxContactManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        contactOffset   = innerJoinOffset;
                        innerJoinOffset = contactOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;
                    }
                }
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            if (optionFlags != null)
            {
                query.Append(" FROM ");

                //
                // Start INNER JOIN expressions
                //
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    query.Append("(");
                }

                query.Append("sysGlobal_Users AS GreyFoxUser");
            }
            else
            {
                query.Append(" FROM sysGlobal_Users AS GreyFoxUser");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxUserFlags.Contact:
                        query.Append(" LEFT JOIN sysGlobal_Contacts AS Contact ON GreyFoxUser.ContactID = Contact.GreyFoxContactID)");
                        break;
                    }
                }
            }

            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
                        #if DEBUG
            try
            {
                r = database.ExecuteReader(dbCommand);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                throw(new Exception(msg + " --- Query: " + query.ToString()));
            }
                        #else
            r = database.ExecuteReader(dbCommand);
                        #endif

            greyFoxUserCollection = new GreyFoxUserCollection();

            while (r.Read())
            {
                GreyFoxUser greyFoxUser = ParseFromReader(r, 0, 1);

                // Fill Contact
                if (contactOffset != -1 && !r.IsDBNull(contactOffset))
                {
                    GreyFoxContactManager.FillFromReader(greyFoxUser.contact, "sysGlobal_Contacts", r, contactOffset, contactOffset + 1);
                }

                greyFoxUserCollection.Add(greyFoxUser);
            }

            // Microsoft DAAB still needs to close readers.
            r.Close();

            return(greyFoxUserCollection);
        }