Esempio n. 1
0
        /// <summary>
        /// Get Sitecore DataTemplate based on passed TemplateID
        /// </summary>
        /// <param name="TemplateID">string, TemplateID in string GUID format</param>
        /// <returns>TemplateItem</returns>
        public static TemplateItem GetTemplate(string TemplateID)
        {
            TemplateItem result = null;

            result = GetItem(TemplateID);
            if (result == null)
            {
                using (new SecurityDisabler())
                {
                    string itemcachekey = string.Empty;
                    try
                    {
                        itemcachekey = TemplateID + "-templkey";
                        if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName))
                        {
                            result = GetDatabase().GetTemplate(TemplateID);
                            APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName);
                        }
                        else
                        {
                            result = APICache.GetAPICachedItem <TemplateItem>(itemcachekey, Common.APICache.RegionName);
                        }
                    }
                    catch (Exception)
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns an item always from the provided ItemID
        /// This will get the db from the context or look from query string
        /// This will get the language from the context or look from query string
        /// This will get the version from the query string or take the default version which is latest
        /// </summary>
        /// <param name="ItemID">Item id in string</param>
        /// <param name="dbName">dbName in string</param>
        /// <param name="language">language in string</param>
        /// <param name="versionNum">versionNum in string</param>
        /// <returns>Sitecore.Data.Items.Item</returns>
        public static Item GetItem(string ItemID, string dbName = "master", string language = "en", int versionNum = 1)
        {
            Item result = null;

            using (new SecurityDisabler())
            {
                string   itemcachekey         = string.Empty;
                Database db                   = GetDatabase(dbName);
                Language lang                 = GetLanguage(language);
                Sitecore.Data.Version version = GetItemVersion(versionNum);
                if (db != null && lang != null && version != null)
                {
                    itemcachekey = ItemID + lang.Name + version.Number.ToString();
                    if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName))
                    {
                        result = db.GetItem(ItemID, lang, version);
                        APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName);
                    }
                    else
                    {
                        result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName);
                    }
                    return(result);
                }
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns an item always from the provided Path
        /// This will get the db from the context or look from query string
        /// This will get the language from the context or look from query string
        /// This will get the version from the query string or take the default version which is latest
        /// </summary>
        /// <param name="path">Item path in string</param>
        /// <returns>Sitecore.Data.Items.Item</returns>
        public static Item GetItemPath(string path)
        {
            Item result = null;

            using (new SecurityDisabler())
            {
                string   itemcachekey         = string.Empty;
                Database db                   = GetDatabase();
                Language lang                 = GetLanguage();
                Sitecore.Data.Version version = GetItemVersion();
                if (db != null && lang != null && version != null)
                {
                    itemcachekey = path.Trim() + lang.Name + version.Number.ToString();
                    if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName))
                    {
                        result = db.GetItem(path, lang, version);
                        APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName);
                    }
                    else
                    {
                        result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName);
                    }
                    return(result);
                }
                else if (db != null && lang != null)
                {
                    itemcachekey = path.Trim() + lang.Name + "0";
                    if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName))
                    {
                        result = db.GetItem(path, lang);
                        APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName);
                    }
                    else
                    {
                        result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName);
                    }
                    return(result);
                }
                else if (db != null)
                {
                    itemcachekey = path.Trim() + "default" + "0";
                    if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName))
                    {
                        result = db.GetItem(path);
                        APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName);
                    }
                    else
                    {
                        result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName);
                    }
                    result = db.GetItem(path);
                    return(result);
                }
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// This function returns the specific language based on passed name parameter
        /// </summary>
        /// <param name="dbname">string, Language name</param>
        /// <returns>Sitecore.Globalization.Language</returns>
        public static Language GetLanguage(string language)
        {
            Language result       = null;
            string   langcachekey = language + "-langkey";

            if (language == null)
            {
                return(result);
            }
            if (!APICache.isCacheExist(langcachekey, Common.APICache.RegionName))
            {
                result = LanguageManager.GetLanguage(language);
                APICache.AddToAPICache(langcachekey, result, APICachePriority.Default, Common.APICache.RegionName);
            }
            else
            {
                result = APICache.GetAPICachedItem <Language>(langcachekey, Common.APICache.RegionName);
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// This function returns the specific database based on passed name parameter
        /// </summary>
        /// <param name="dbname">string, Database name</param>
        /// <returns>Sitecore.Data.Database</returns>
        public static Database GetDatabase(string dbname)
        {
            Database result     = null;
            string   dbcachekey = dbname + "-dbkey";

            if (dbname == null)
            {
                return(result);
            }
            if (!APICache.isCacheExist(dbcachekey, Common.APICache.RegionName))
            {
                result = Sitecore.Configuration.Factory.GetDatabase(dbname);
                APICache.AddToAPICache(dbcachekey, result, APICachePriority.Default, Common.APICache.RegionName);
            }
            else
            {
                result = APICache.GetAPICachedItem <Database>(dbcachekey, Common.APICache.RegionName);
            }
            return(result);
        }