/// <summary> /// Initialize the cache /// </summary> protected void InitializeCache() { // WE LOAD FIXED REDIRECTS UP TO CACHE SIZE _CustomUrls = new KeyedCustomUrlCollection(); CustomUrlCollection tempCustomUrls = CustomUrlDataSource.LoadForStore(this._CacheSize, 0); foreach (CustomUrl item in tempCustomUrls) { _CustomUrls.Add(item); } _CustomUrlCount = CustomUrlDataSource.CountForStore(); _ValidCache = true; }
public virtual SaveResult Save() { CustomUrl checkExists = CustomUrlDataSource.LoadCustomUrl(this.Url); if (checkExists == null || checkExists.CustomUrlId == this.CustomUrlId) { SaveResult result = this.BaseSave(); IUrlRewriter rewriter = RewriteServiceLocator.GetInstance(Token.Instance.UrlRewriterSettings.Provider); if (rewriter != null) { rewriter.ReloadCache(); } return(result); } else { throw new InvalidOperationException("The value of Url is already defined in the database. Url must be unique."); } }
private CustomUrl LoadCustomUrl(string resourceUrl) { // MAKE SURE WE HAVE A VALID CACHE if (!_ValidCache) { this.InitializeCache(); } // CHECK FOR CUSTOM URL IN CACHE string loweredSourceUrl = resourceUrl.ToLowerInvariant(); if (this._CustomUrls.Contains(loweredSourceUrl)) { // RETURN CACHED ITEM return(this._CustomUrls[loweredSourceUrl]); } // SEE IF WE HAVE MORE CUSTOM URLS IN DATABASE if (this._CacheSize < this._CustomUrlCount) { // TRY TO FIND CUSTOM URL BY QUERY CustomUrl customUrl = CustomUrlDataSource.LoadCustomUrl(loweredSourceUrl); if (customUrl != null) { // CUSTOM URL FOUND, KICK OUT THE LAST ITEM IN CACHE this._CustomUrls.RemoveAt(this._CustomUrls.Count - 1); // PUT THE NEW ITEM TO THE TOP OF CACHE this._CustomUrls.Insert(0, customUrl); // RETURN THE NEW CUSTOM URL return(customUrl); } } // NO REWRITE FOUND FOR THE GIVEN URL return(null); }
/// <summary> /// Deletes this category object from database /// </summary> /// <returns>true if delete successful, false otherwise</returns> public bool Delete() { // DELETE ALL CHILDREN, DELETE NODES THAT DO NOT APPEAR IN OTHER CATEGORIES foreach (CatalogNode node in CatalogNodes) { if (node.CatalogNodeType == CatalogNodeType.Product) { Product product = (Product)node.ChildObject; if (product.Categories.Count == 1) { product.Delete(); } } else if (node.CatalogNodeType == CatalogNodeType.Webpage) { Webpage webpage = (Webpage)node.ChildObject; if (webpage.Categories.Count == 1) { webpage.Delete(); } } else if (node.CatalogNodeType == CatalogNodeType.Link) { Link link = (Link)node.ChildObject; if (link.Categories.Count == 1) { link.Delete(); } } else if (node.CatalogNodeType == CatalogNodeType.Category) { Category cat = (Category)node.ChildObject; if (cat != null) { cat.Delete(); } } //DELETE THE CHILD NODE node.Delete(); } //GET DATABASE Database database = Token.Instance.Database; DbCommand deleteCommand; //DELETE ALL PATHS deleteCommand = database.GetSqlStringCommand("DELETE FROM ac_CategoryParents WHERE CategoryId=@categoryId"); database.AddInParameter(deleteCommand, "@categoryId", DbType.Int32, this.CategoryId); database.ExecuteNonQuery(deleteCommand); //DELETE ALL CATALOG NODES LINKED TO OR FROM THIS CATEGORY deleteCommand = database.GetSqlStringCommand("DELETE FROM ac_CatalogNodes WHERE (CategoryId=@categoryId OR (CatalogNodeId=@categoryId AND CatalogNodeTypeId=@catalogNodeTypeId))"); database.AddInParameter(deleteCommand, "@categoryId", DbType.Int32, this.CategoryId); database.AddInParameter(deleteCommand, "@catalogNodeTypeId", System.Data.DbType.Byte, (byte)CatalogNodeType.Category); database.ExecuteNonQuery(deleteCommand); //DELTE CUSTOM URL INFORMATION IF THERE IS ANY CustomUrlDataSource.Delete(this.CategoryId, CatalogNodeType.Category); //PERFORM BASE DELETE return(this.BaseDelete()); }
public static CustomUrl Load(Int32 customUrlId) { return(CustomUrlDataSource.Load(customUrlId, true)); }