/// <summary> /// Load this Redirect object from the database for the given source URL. /// </summary> /// <param name="sourceUrl">Value of SourceUrl of the object to load.</param> /// <returns><b>true</b> if load is successful, <b>false</b> otherwise</returns> public static Redirect LoadForSourceUrl(String sourceUrl) { Redirect redirect = null; if (string.IsNullOrEmpty(sourceUrl)) { throw new ArgumentException("sourceUrl"); } string loweredSourceUrl = sourceUrl.ToLowerInvariant(); //CREATE THE SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT " + Redirect.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_Redirects"); selectQuery.Append(" WHERE LoweredSourceUrl = @loweredSourceUrl"); selectQuery.Append(" AND StoreId = @storeId"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@loweredSourceUrl", System.Data.DbType.String, loweredSourceUrl); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); //EXECUTE THE COMMAND using (IDataReader dr = database.ExecuteReader(selectCommand)) { if (dr.Read()) { redirect = new Redirect(); Redirect.LoadDataReader(redirect, dr);; } dr.Close(); } return(redirect); }
public static Redirect Load(Int32 redirectId, bool useCache) { if (redirectId == 0) { return(null); } Redirect redirect = null; string key = "Redirect_" + redirectId.ToString(); if (useCache) { redirect = ContextCache.GetObject(key) as Redirect; if (redirect != null) { return(redirect); } } redirect = new Redirect(); if (redirect.Load(redirectId)) { if (useCache) { ContextCache.SetObject(key, redirect); } return(redirect); } return(null); }
public static bool Delete(Int32 redirectId) { Redirect redirect = new Redirect(); if (redirect.Load(redirectId)) { return(redirect.Delete()); } return(false); }
/// <summary> /// Loads the given Redirect object from the given database data reader. /// </summary> /// <param name="redirect">The Redirect object to load.</param> /// <param name="dr">The database data reader to read data from.</param> public static void LoadDataReader(Redirect redirect, IDataReader dr) { //SET FIELDS FROM ROW DATA redirect.RedirectId = dr.GetInt32(0); redirect.StoreId = dr.GetInt32(1); redirect.SourceUrl = dr.GetString(2); redirect.TargetUrl = dr.GetString(3); redirect.UseRegEx = dr.GetBoolean(4); redirect.CreatedDate = LocaleHelper.ToLocalTime(dr.GetDateTime(5)); redirect.LastVisitedDate = LocaleHelper.ToLocalTime(NullableData.GetDateTime(dr, 6)); redirect.VisitCount = NullableData.GetInt32(dr, 7); redirect.OrderBy = dr.GetInt16(8); redirect.IsDirty = false; }
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); }
/// <summary> /// Given the request url, return the Redirect that applies to this path. /// </summary> /// <param name="sourceUrl">The source url</param> public Redirect LocateRedirect(string sourceUrl) { // MAKE SURE WE HAVE A VALID CACHE if (!_ValidCache) { this.InitializeCache(); } // CHECK FOR FIXED REDIRECT IN CACHE string loweredSourceUrl = sourceUrl.ToLowerInvariant(); if (this._FixedRedirects.Contains(loweredSourceUrl)) { // RETURN CACHED ITEM return(this._FixedRedirects[loweredSourceUrl]); } // SEE IF WE HAVE MORE FIXED REDIRECTS IN DATABASE if (this._CacheSize < this._FixedRedirectCount) { // TRY TO FIND A FIXED REDIRECT BY QUERY Redirect redirect = RedirectDataSource.LoadForSourceUrl(loweredSourceUrl); if (redirect != null) { // REDIRECT FOUND, KICK OUT THE LAST ITEM IN CACHE this._FixedRedirects.RemoveAt(this._FixedRedirects.Count - 1); // PUT THE NEW ITEM TO THE TOP OF CACHE this._FixedRedirects.Insert(0, redirect); // RETURN THE NEW REDIRECT return(redirect); } } // LOOK THROUGH DYNAMIC REDIRECTS foreach (Redirect item in this._DynamicRedirects) { if (item.AppliesToUrl(sourceUrl)) { // A MATCHING REDIRECT IS FOUND, RETURN IT return(item); } } // NO REDIRECT FOUND FOR THE GIVEN URL return(null); }
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); }
public static SaveResult Insert(Redirect redirect) { return(redirect.Save()); }
public static SaveResult Update(Redirect redirect) { return(redirect.Save()); }
public static bool Delete(Redirect redirect) { return(redirect.Delete()); }