Beispiel #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;
                    }
                }
            }
        }
Beispiel #2
0
        //--- Begin Custom Code ---

        #region Encoding

        public GreyFoxRoleCollection DecodeString(string roles, string separator)
        {
            GreyFoxRoleCollection encodedRoles = new GreyFoxRoleCollection();

            roles = roles.Trim();
            if (roles.Trim() == string.Empty)
            {
                return(encodedRoles);
            }

            string[] names = roles.Split(new string[] { separator },
                                         StringSplitOptions.RemoveEmptyEntries);

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

            GreyFoxRoleCollection allRoles =
                GetCollection(string.Empty, string.Empty);

            for (int x = 0; x < allRoles.Count; x++)
            {
                for (int y = 0; y <= names.GetUpperBound(0); y++)
                {
                    if (allRoles[x].Name == names[y])
                    {
                        encodedRoles.Add(allRoles[x]);
                    }
                }
            }

            return(encodedRoles);
        }
Beispiel #3
0
        /// <summary>
        /// Makes a shallow copy of the current GreyFoxRoleCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>GreyFoxRoleCollection</returns>
        public GreyFoxRoleCollection Clone()
        {
            GreyFoxRoleCollection clonedGreyFoxRole = new GreyFoxRoleCollection(count);

            lock (this)
            {
                foreach (GreyFoxRole item in this)
                {
                    clonedGreyFoxRole.Add(item);
                }
            }
            return(clonedGreyFoxRole);
        }
Beispiel #4
0
        public static void FillRoles(GreyFoxUser greyFoxUser)
        {
            StringBuilder s;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;

            s = new StringBuilder("SELECT GreyFoxRoleID FROM sysGlobal_UsersChildren_Roles ");
            s.Append("WHERE GreyFoxUserID=");
            s.Append(greyFoxUser.iD);
            s.Append(";");

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

            GreyFoxRoleCollection roles;

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

            while (r.Read())
            {
                roles.Add(GreyFoxRole.NewPlaceHolder(r.GetInt32(0)));
            }

            greyFoxUser.Roles = roles;
            // Store GreyFoxUser in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxUser);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Makes a deep copy of the current GreyFoxRole.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the GreyFoxRoleCollection from their children.</param>
        public GreyFoxRoleCollection Copy(bool isolated)
        {
            GreyFoxRoleCollection isolatedCollection = new GreyFoxRoleCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxRoleArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxRoleArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
Beispiel #6
0
        public GreyFoxRoleCollection GetCollection(int topCount, string whereClause, string sortClause)
        {
            StringBuilder         query;
            Database              database;
            DbCommand             dbCommand;
            IDataReader           r;
            GreyFoxRoleCollection greyFoxRoleCollection;


            query = new StringBuilder("SELECT ");

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

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

            //
            // Remove trailing comma
            //
            query.Length--;
            query.Append(" FROM sysGlobal_Roles AS GreyFoxRole");
            //
            // 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

            greyFoxRoleCollection = new GreyFoxRoleCollection();

            while (r.Read())
            {
                GreyFoxRole greyFoxRole = ParseFromReader(r, 0, 1);

                greyFoxRoleCollection.Add(greyFoxRole);
            }

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

            return(greyFoxRoleCollection);
        }