private Dictionary <string, ItemDefinition> BuildItemDefinitions()
        {
            var persistentData  = _repository.GetAllItemDefinitions(_buildSettings.SiteId, _buildSettings.IsStage);
            var typesDictionary = _typeFinder.GetTypesOf <AbstractItem>();

            return(persistentData
                   .Where(_ => typesDictionary.ContainsKey(_.TypeName))
                   .Select(_ => new ItemDefinition {
                Id = _.Id, Discriminator = _.Discriminator, TypeName = _.TypeName, Type = typesDictionary[_.TypeName]
            })
                   .ToDictionary(_ => _.Discriminator, _ => _));
        }
        private Dictionary <string, ItemDefinitionPersistentData> GetCachedItemDefinitions()
        {
            var cacheTags = new string[1] {
                _qpContentCacheTagNamingProvider.GetByNetName(KnownNetNames.ItemDefinition, _buildSettings.SiteId, _buildSettings.IsStage)
            }
            .Where(t => t != null)
            .ToArray();

            return(_cacheProvider.GetOrAdd("UniversalAbstractItemFactory.GetCachedItemDefinitions",
                                           cacheTags,
                                           _cacheSettings.ItemDefinitionCachePeriod,
                                           () => _repository.GetAllItemDefinitions(_buildSettings.SiteId, _buildSettings.IsStage).ToDictionary(def => def.Discriminator)));
        }
        public ApiResult AvailableWidgets(int siteId, bool isStage = true)
        {
            try
            {
                var content = _metaInfoRepository.GetContent("QPDiscriminator", siteId);
                if (content == null)
                {
                    return(ApiResult.Error(Response, $"Not found QPDiscriminator content in site {siteId}"));
                }

                var cacheTag = new string[1] {
                    _qpContentCacheTagNamingProvider.Get(content.ContentName, siteId, isStage)
                };

                var widgetDefinitions = _cacheProvider.GetOrAdd($"AvailableWidgets_{siteId}_{isStage}", cacheTag, TimeSpan.FromSeconds(30), () => {
                    var result = _itemDefinitionRepository
                                 .GetAllItemDefinitions(siteId, isStage)
                                 .Where(d => !d.IsPage)
                                 .ToList();

                    var baseIconUrl = _qpUrlResolver.UrlForImage(siteId, content.ContentId, "IconUrl");

                    foreach (var w in result)
                    {
                        w.IconUrl = (baseIconUrl ?? "") + "/" + w.IconUrl;
                    }

                    return(result);
                });

                return(ApiResult.Success <IEnumerable <ItemDefinitionPersistentData> >(widgetDefinitions));
            }
            catch (Exception ex)
            {
                return(ApiResult.Error(Response, ex.Message));
            }
        }