Ejemplo n.º 1
0
        public static GreyFoxSettingCollection GetSettings(string parentKey)
        {
            GreyFoxSettingManager settingManager =
                new GreyFoxSettingManager();
            GreyFoxSettingCollection settingCollection =
                settingManager.GetCollection("GreyFoxSetting.Name='" +
                                             parentKey + "'", "GreyFoxSetting.Name", GreyFoxSettingFlags.Parent);

            return(settingCollection);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Makes a shallow copy of the current GreyFoxSettingCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>GreyFoxSettingCollection</returns>
        public GreyFoxSettingCollection Clone()
        {
            GreyFoxSettingCollection clonedGreyFoxSetting = new GreyFoxSettingCollection(count);

            lock (this)
            {
                foreach (GreyFoxSetting item in this)
                {
                    clonedGreyFoxSetting.Add(item);
                }
            }
            return(clonedGreyFoxSetting);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Makes a deep copy of the current GreyFoxSetting.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the GreyFoxSettingCollection from their children.</param>
        public GreyFoxSettingCollection Copy(bool isolated)
        {
            GreyFoxSettingCollection isolatedCollection = new GreyFoxSettingCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxSettingArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxSettingArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
Ejemplo n.º 4
0
        public GreyFoxSettingCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxSettingFlags[] optionFlags)
        {
            StringBuilder query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }
            foreach (string columnName in InnerJoinFields)
            {
                query.Append("sysGlobal_Settings.");
                query.Append(columnName);
                query.Append(",");
            }

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

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxSettingFlags.ModifyRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("sysGlobal_Roles.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        modifyRoleOffset = innerJoinOffset;
                        innerJoinOffset  = modifyRoleOffset + GreyFoxRoleManager.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_Settings");
            }
            else
            {
                query.Append(" FROM sysGlobal_Settings ");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxSettingFlags.ModifyRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles ON sysGlobal_Settings.ModifyRoleID = sysGlobal_Roles.GreyFoxRoleID)");
                        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(";");
            OleDbConnection dbConnection = new OleDbConnection(connectionString);
            OleDbCommand    dbCommand    = new OleDbCommand(query.ToString(), dbConnection);

            dbConnection.Open();

                        #if DEBUG
            OleDbDataReader r;
            try
            {
                r = dbCommand.ExecuteReader();
            }
            catch (Exception e)
            {
                throw(new Exception(e.Message + " --- Query: " + query.ToString()));
            }
                        #else
            OleDbDataReader r = dbCommand.ExecuteReader();
                        #endif

            GreyFoxSettingCollection greyFoxSettingCollection = new GreyFoxSettingCollection();

            while (r.Read())
            {
                GreyFoxSetting greyFoxSetting = ParseFromReader(r, 0, 1);

                // Fill ModifyRole
                if (modifyRoleOffset != -1 && !r.IsDBNull(modifyRoleOffset))
                {
                    GreyFoxRoleManager.FillFromReader(greyFoxSetting.modifyRole, r, modifyRoleOffset, modifyRoleOffset + 1);
                }

                greyFoxSettingCollection.Add(greyFoxSetting);
            }

            r.Close();
            dbConnection.Close();

            return(greyFoxSettingCollection);
        }
Ejemplo n.º 5
0
        public GreyFoxSettingCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxSettingFlags[] optionFlags)
        {
            StringBuilder            query;
            Database                 database;
            DbCommand                dbCommand;
            IDataReader              r;
            GreyFoxSettingCollection greyFoxSettingCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

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

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

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int parentOffset           = -1;
            int parentParentOffset     = -1;
            int parentModifyRoleOffset = -1;
            int modifyRoleOffset       = -1;

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

                    case GreyFoxSettingFlags.ParentParent:
                        for (int i = 0; i <= GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Parent_Parent.");
                            query.Append(GreyFoxSettingManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentParentOffset = innerJoinOffset;
                        innerJoinOffset    = parentParentOffset + GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case GreyFoxSettingFlags.ParentModifyRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Parent_ModifyRole.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentModifyRoleOffset = innerJoinOffset;
                        innerJoinOffset        = parentModifyRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case GreyFoxSettingFlags.ModifyRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ModifyRole.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        modifyRoleOffset = innerJoinOffset;
                        innerJoinOffset  = modifyRoleOffset + GreyFoxRoleManager.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_Settings AS GreyFoxSetting");
            }
            else
            {
                query.Append(" FROM sysGlobal_Settings AS GreyFoxSetting");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxSettingFlags.Parent:
                        query.Append(" LEFT JOIN sysGlobal_Settings AS Parent ON GreyFoxSetting.ParentID = Parent.GreyFoxSettingID)");
                        break;

                    case GreyFoxSettingFlags.ParentParent:
                        query.Append(" LEFT JOIN sysGlobal_Settings AS Parent_Parent ON Parent.ParentID = Parent_Parent.GreyFoxSettingID)");
                        break;

                    case GreyFoxSettingFlags.ParentModifyRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles AS Parent_ModifyRole ON Parent.ModifyRoleID = Parent_ModifyRole.GreyFoxRoleID)");
                        break;

                    case GreyFoxSettingFlags.ModifyRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles AS ModifyRole ON GreyFoxSetting.ModifyRoleID = ModifyRole.GreyFoxRoleID)");
                        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

            greyFoxSettingCollection = new GreyFoxSettingCollection();

            while (r.Read())
            {
                GreyFoxSetting greyFoxSetting = ParseFromReader(r, 0, 1);

                // Fill Parent
                if (parentOffset != -1 && !r.IsDBNull(parentOffset))
                {
                    GreyFoxSettingManager.FillFromReader(greyFoxSetting.parent, r, parentOffset, parentOffset + 1);

                    // Fill
                    if (parentParentOffset != -1 && !r.IsDBNull(parentParentOffset))
                    {
                        GreyFoxSettingManager.FillFromReader(greyFoxSetting.parent.Parent, r, parentParentOffset, parentParentOffset + 1);
                    }

                    // Fill
                    if (parentModifyRoleOffset != -1 && !r.IsDBNull(parentModifyRoleOffset))
                    {
                        GreyFoxRoleManager.FillFromReader(greyFoxSetting.parent.ModifyRole, r, parentModifyRoleOffset, parentModifyRoleOffset + 1);
                    }
                }

                // Fill ModifyRole
                if (modifyRoleOffset != -1 && !r.IsDBNull(modifyRoleOffset))
                {
                    GreyFoxRoleManager.FillFromReader(greyFoxSetting.modifyRole, r, modifyRoleOffset, modifyRoleOffset + 1);
                }

                greyFoxSettingCollection.Add(greyFoxSetting);
            }

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

            return(greyFoxSettingCollection);
        }