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