private static ScriptletCollection GetCachedScriptlets(string themeId)
        {
            StoreSettingCollection settings = Token.Instance.Store.Settings;
            HttpContext            context  = HttpContext.Current;
            ScriptletCollection    scriptlets;

            if (themeId == null)
            {
                themeId = string.Empty;
            }

            string pathPart;

            if (string.IsNullOrEmpty(themeId))
            {
                pathPart = "App_Data\\Scriptlets";
            }
            else
            {
                pathPart = "App_Themes\\" + themeId + "\\Scriptlets";
                if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart)))
                {
                    pathPart = "App_Data\\Scriptlets";
                }
            }

            if (context != null)
            {
                scriptlets = context.Cache[_CacheKey + themeId] as ScriptletCollection;
                if (scriptlets == null)
                {
                    scriptlets = ScriptletDataSource.LoadAll(themeId);
                    if (scriptlets.Count > 0)
                    {
                        scriptlets.Sort("Identifier", GenericComparer.SortDirection.ASC);
                        CacheDependency   dep      = new CacheDependency(GetScriptletDirectories(context.Server.MapPath("~/" + pathPart.Replace('\\', '/'))));
                        CacheItemPriority priority = scriptlets.Count < 400 ? CacheItemPriority.NotRemovable : CacheItemPriority.High;
                        context.Cache.Insert(_CacheKey + themeId, scriptlets, dep, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, priority, null);
                    }
                }
                return(scriptlets);
            }

            //CALLED FROM NON-WEB CONTEXT, LOAD STORE SETTINGS
            scriptlets = ScriptletDataSource.LoadAll(themeId);
            scriptlets.Sort("Identifier", GenericComparer.SortDirection.ASC);
            return(scriptlets);
        }
Example #2
0
        /// <summary>
        /// Retrieves settings for the current store using application cache.
        /// </summary>
        /// <returns>Settings for the current store.</returns>
        public static StoreSettingCollection GetCachedSettings()
        {
            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                StoreSettingCollection settings = context.Cache["AbleCommerceStoreSettings"] as StoreSettingCollection;
                if (settings == null)
                {
                    settings = Token.Instance.Store.Settings;
                    context.Cache.Insert("AbleCommerceStoreSettings", settings, null, DateTime.Now.AddMinutes(20), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
                }
                return(settings);
            }
            //CALLED FROM NON-WEB CONTEXT, LOAD STORE SETTINGS
            return(Token.Instance.Store.Settings);
        }
Example #3
0
        public static StoreSettingCollection LoadForStore(int maximumRows, int startRowIndex, string sortExpression)
        {
            int storeId = Token.Instance.StoreId;
            //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(" " + StoreSetting.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_StoreSettings");
            selectQuery.Append(" WHERE StoreId = @storeId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                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);
            //EXECUTE THE COMMAND
            StoreSettingCollection results = new StoreSettingCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        StoreSetting storeSetting = new StoreSetting();
                        StoreSetting.LoadDataReader(storeSetting, dr);
                        results.Add(storeSetting);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
        /// <summary>
        /// Loads all Scriptlet objects for the given theme
        /// </summary>
        /// <returns>A collection of all Scriptlet objects in the store</returns>
        public static ScriptletCollection LoadAll(string themeId)
        {
            StoreSettingCollection settings = Token.Instance.Store.Settings;
            Hashtable           ht          = new Hashtable();
            ScriptletCollection results     = new ScriptletCollection();
            //LOAD CUSTOM SCRIPTLETS FIRST
            string pathPart;

            if (string.IsNullOrEmpty(themeId))
            {
                pathPart = "App_Data\\Scriptlets";
            }
            else
            {
                pathPart = "App_Themes\\" + themeId + "\\Scriptlets";
                if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart)))
                {
                    pathPart = "App_Data\\Scriptlets";
                }
            }

            DirectoryInfo di = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart + "\\Custom"));

            if (di.Exists)
            {
                DirectoryInfo[] folders = di.GetDirectories();
                foreach (DirectoryInfo folder in folders)
                {
                    ScriptletType scriptletType;
                    try
                    {
                        scriptletType = (ScriptletType)Enum.Parse(typeof(ScriptletType), folder.Name, true);
                    }
                    catch (ArgumentException)
                    {
                        //FOLDER IS NOT A RECOGNIZED SCRIPTLET TYPE
                        scriptletType = ScriptletType.Unspecified;
                    }
                    if (scriptletType != ScriptletType.Unspecified)
                    {
                        FileInfo[] files = folder.GetFiles("*.htm");
                        foreach (FileInfo file in files)
                        {
                            string    identifier = Path.GetFileNameWithoutExtension(file.Name);
                            string    hashkey    = scriptletType.ToString() + "_" + identifier;
                            Scriptlet s          = ScriptletDataSource.Load(themeId, identifier, scriptletType, BitFieldState.True, false);
                            if (s != null)
                            {
                                ht.Add(s.ScriptletType + "_" + s.Identifier, true);
                                results.Add(s);
                            }
                        }
                    }
                }
            }
            //LOAD DEFAULT SCRIPTLETS NEXT
            di = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart + "\\Default"));
            if (di.Exists)
            {
                DirectoryInfo[] folders = di.GetDirectories();
                foreach (DirectoryInfo folder in folders)
                {
                    ScriptletType scriptletType;
                    try
                    {
                        scriptletType = (ScriptletType)Enum.Parse(typeof(ScriptletType), folder.Name, true);
                    }
                    catch (ArgumentException)
                    {
                        //FOLDER IS NOT A RECOGNIZED SCRIPTLET TYPE
                        scriptletType = ScriptletType.Unspecified;
                    }
                    if (scriptletType != ScriptletType.Unspecified)
                    {
                        FileInfo[] files = folder.GetFiles("*.htm");
                        foreach (FileInfo file in files)
                        {
                            string identifier = Path.GetFileNameWithoutExtension(file.Name);
                            string hashkey    = scriptletType.ToString() + "_" + identifier;
                            if (!ht.ContainsKey(hashkey))
                            {
                                Scriptlet s = ScriptletDataSource.Load(themeId, identifier, scriptletType, BitFieldState.False, false);
                                if (s != null)
                                {
                                    ht.Add(hashkey, true);
                                    results.Add(s);
                                }
                            }
                        }
                    }
                }
            }
            return(results);
        }