private static RedirectCollection LoadRedirects(bool dynamic, int maximumRows, int startRowIndex, string sortExpression)
        {
            int storeId = Token.Instance.StoreId;

            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + Redirect.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_Redirects");
            selectQuery.Append(" WHERE StoreId = @storeId");
            selectQuery.Append(" AND UseRegEx = @useRegEx");
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, storeId);
            database.AddInParameter(selectCommand, "@useRegEx", System.Data.DbType.Boolean, dynamic);
            //EXECUTE THE COMMAND
            RedirectCollection results = new RedirectCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        Redirect redirect = new Redirect();
                        Redirect.LoadDataReader(redirect, dr);
                        results.Add(redirect);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
Exemplo n.º 2
0
        protected void InitializeCache()
        {
            // WE ALWAYS LOAD ALL DYNAMIC REDIRECTS TO CACHE
            _DynamicRedirects = RedirectDataSource.LoadDynamicRedirects();

            // WE LOAD FIXED REDIRECTS UP TO CACHE SIZE
            _FixedRedirects = new KeyedRedirectCollection();
            RedirectCollection tempFixedRedirects = RedirectDataSource.LoadFixedRedirects(this._CacheSize, 0);

            foreach (Redirect item in tempFixedRedirects)
            {
                _FixedRedirects.Add(item);
            }
            _FixedRedirectCount = RedirectDataSource.CountFixedRedirects();
            _ValidCache         = true;
        }
        public static RedirectCollection  LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + Redirect.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_Redirects");
            string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria;

            selectQuery.Append(whereClause);
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());
            //EXECUTE THE COMMAND
            RedirectCollection results = new RedirectCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        Redirect redirect = new Redirect();
                        Redirect.LoadDataReader(redirect, dr);
                        results.Add(redirect);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }