Exemplo n.º 1
0
        public ActionResult Debug(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            bool isPath = id.StartsWith("/sitecore", StringComparison.OrdinalIgnoreCase);

            if (isPath)
            {
                var items = new List <Item>();

                foreach (var language in _allLanguages)
                {
                    Item itemOfPath = _itemManager.GetItem(id, language, Version.Latest, _webDatabase);
                    if (itemOfPath == null || itemOfPath.Versions.Count == 0)
                    {
                        continue;
                    }

                    items.Add(itemOfPath);
                }

                var entities = new List <IEnterspeedEntity>();

                foreach (Item item in items)
                {
                    entities.Add(Map(item));
                }

                return(Content(_jsonSerializer.Serialize(entities)));
            }

            EnterspeedSitecoreIdentity identity = _enterspeedIdentityService.Parse(id);

            if (identity == null)
            {
                return(null);
            }

            Item itemOfId = _itemManager.GetItem(identity.ID, identity.Language, Version.Latest, _webDatabase);

            if (itemOfId == null || itemOfId.Versions.Count == 0)
            {
                return(null);
            }

            return(Content(_jsonSerializer.Serialize(Map(itemOfId))));
        }
Exemplo n.º 2
0
        private void EnsureTemplates(Database masterDb, Database webDb, Language language)
        {
            // Assert / create template item
            Item templatesSystemRoot = _itemManager.GetItem("/sitecore/templates/System", language, Version.Latest, masterDb);

            if (templatesSystemRoot == null || templatesSystemRoot.Versions.Count == 0)
            {
                throw new InvalidOperationException("Unable to find System Root (/sitecore/templates/System) in Sitecore (master database) with the language \"en\".");
            }

            Item enterspeedConfigTemplateItem = EnsureEnterspeedConfigurationTemplate(EnsureEnterspeedTemplatesFolder(templatesSystemRoot));

            EnsureEnterspeedConfigurationTemplateFields(enterspeedConfigTemplateItem);

            Item enterspeedConfigSection = EnsureEnterspeedConfigurationTemplateDataSection(enterspeedConfigTemplateItem);

            EnsureEnterspeedConfigurationDataSectionFields(enterspeedConfigSection);

            _publishManager.PublishItem(templatesSystemRoot, new[] { webDb }, new[] { language }, true, false, true);
        }
 public IEnumerable <Item> GetCategories(Item parent)
 {
     using (var context = GetSearchContext(parent))
     {
         var results = context.GetQueryable <CategorySearchQuery>()
                       .Where(evnt => evnt.Paths.Contains(parent.ID) && evnt.Templates.Contains(Templates.Category.Id))
                       .Select(x => new {
             Uri      = x.UniqueId,
             Database = Factory.GetDatabase(x.UniqueId.DatabaseName)
         }).ToList();
         return(results.Select(x => ItemManager.GetItem(x.Uri.ItemID, x.Uri.Language, x.Uri.Version, x.Database)));
     }
 }
        public IEnterspeedProperty Convert(Item item, Field field, EnterspeedSiteInfo siteInfo, List <IEnterspeedFieldValueConverter> fieldValueConverters)
        {
            if (string.IsNullOrEmpty(field?.Value))
            {
                return(null);
            }

            NameValueCollection values = HttpUtility.ParseQueryString(field.Value);

            if (values.Count == 0)
            {
                return(null);
            }

            var items = new List <Item>();

            foreach (string key in values)
            {
                if (string.IsNullOrEmpty(key))
                {
                    continue;
                }

                string value = values[key];
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                if (!Guid.TryParse(value, out var itemId))
                {
                    continue;
                }

                Item referencedItem = _itemManager.GetItem(new ID(itemId), item.Language, Version.Latest, item.Database);
                if (referencedItem == null ||
                    referencedItem.Versions.Count == 0)
                {
                    continue;
                }

                items.Add(referencedItem);
            }

            var referenceIds = items.Select(x => new StringEnterspeedProperty(null, _enterspeedIdentityService.GetId(x))).ToArray();

            return(new ArrayEnterspeedProperty(_fieldService.GetFieldName(field), referenceIds));
        }
Exemplo n.º 5
0
        public IEnumerable <Item> GetEvents(Item parent, string keyword)
        {
            var searchWord = string.IsNullOrEmpty(keyword) ? "*" : keyword;

            using (var context = GetSearchContext(parent))
            {
                var results = context.GetQueryable <EventSearchQuery>()
                              .Where(evnt => evnt.Paths.Contains(parent.ID) && evnt.Templates.Contains(Templates.Event.Id) &&
                                     (evnt.Name.Contains(searchWord) || evnt.Description.Contains(searchWord)))
                              .Select(x => new {
                    Uri      = x.UniqueId,
                    Database = Factory.GetDatabase(x.UniqueId.DatabaseName)
                }).ToList();
                return(results.Select(x => ItemManager.GetItem(x.Uri.ItemID, x.Uri.Language, x.Uri.Version, x.Database)));
            }
        }
        private IEnterspeedProperty[] GetAvailableLanguagesOfItem(Item item)
        {
            var languages = new List <StringEnterspeedProperty>();

            foreach (Language language in item.Languages)
            {
                Item itemInLanguage = _itemManager.GetItem(item.ID, language, Version.Latest, item.Database);
                if (itemInLanguage == null ||
                    itemInLanguage.Versions.Count == 0)
                {
                    continue;
                }

                languages.Add(new StringEnterspeedProperty(null, language.Name));
            }

            return(languages.ToArray());
        }
Exemplo n.º 7
0
        public void OnItemProcessed(object sender, EventArgs args)
        {
            PublishItemContext context = args is ItemProcessedEventArgs itemProcessedEventArgs
                ? itemProcessedEventArgs.Context
                : null;

            if (context == null)
            {
                return;
            }

            EnterspeedSitecoreConfiguration configuration = _enterspeedConfigurationService.GetConfiguration();

            if (!configuration.IsEnabled)
            {
                return;
            }

            Language language = context.PublishOptions.Language;

            // Getting the source item first
            Item sourceItem = _itemManager.GetItem(context.ItemId, language, Version.Latest, context.PublishHelper.Options.SourceDatabase);

            if (sourceItem == null)
            {
                return;
            }

            if (!HasAllowedPath(sourceItem))
            {
                return;
            }

            // Handling if the item was deleted or unpublished
            bool itemIsDeleted = context.Action == PublishAction.DeleteTargetItem;

            if (itemIsDeleted)
            {
                HandleContentItem(sourceItem, configuration, true, false);
                HandleRendering(sourceItem, configuration, true, false);
                HandleDictionary(sourceItem, configuration, true, false);

                return;
            }

            // Handling if the item was published
            Item targetItem = _itemManager.GetItem(context.ItemId, language, Version.Latest, context.PublishHelper.Options.TargetDatabase);

            if (targetItem == null || targetItem.Versions.Count == 0)
            {
                return;
            }

            if (!HasAllowedPath(targetItem))
            {
                return;
            }

            HandleContentItem(targetItem, configuration, false, true);
            HandleRendering(targetItem, configuration, false, true);
            HandleDictionary(targetItem, configuration, false, true);
        }
Exemplo n.º 8
0
        public EnterspeedSitecoreConfiguration GetConfiguration()
        {
            Item enterspeedConfigurationItem = _itemManager.GetItem(EnterspeedIDs.Items.EnterspeedConfigurationID, Language.Parse("en"), Version.Latest, _factory.GetDatabase("web"));

            if (enterspeedConfigurationItem == null || enterspeedConfigurationItem.Versions.Count == 0)
            {
                return(new EnterspeedSitecoreConfiguration());
            }

            string enabled = enterspeedConfigurationItem[EnterspeedIDs.Fields.EnterspeedEnabledFieldID] ?? string.Empty;

            if (enabled != "1")
            {
                return(new EnterspeedSitecoreConfiguration());
            }

            if (!IsConfigurationUpdated(enterspeedConfigurationItem, out Guid currentRevisionId))
            {
                return(_configuration);
            }

            var config = new EnterspeedSitecoreConfiguration
            {
                IsEnabled = true
            };

            string configApiBaseUrl = enterspeedConfigurationItem[EnterspeedIDs.Fields.EnterspeedApiBaseUrlFieldID];

            config.BaseUrl = (configApiBaseUrl ?? string.Empty).Trim();

            string configApiKey = enterspeedConfigurationItem[EnterspeedIDs.Fields.EnterspeedApiKeyFieldID];

            config.ApiKey = (configApiKey ?? string.Empty).Trim();

            config.ItemNotFoundUrl = GetItemNotFoundUrl(_settings);

            MultilistField enabledSitesField = enterspeedConfigurationItem.Fields[EnterspeedIDs.Fields.EnterspeedEnabledSitesFieldID];

            var enabledSites = enabledSitesField?.GetItems()?.ToList() ?? new List <Item>();

            if (enabledSites.Any())
            {
                List <SiteInfo> allSiteInfos = _siteContextFactory.GetSites();

                foreach (Item enabledSite in enabledSites)
                {
                    SiteInfo matchingSite = allSiteInfos.FirstOrDefault(x => x.RootPath.Equals(enabledSite.Paths.FullPath, StringComparison.OrdinalIgnoreCase));
                    if (matchingSite == null)
                    {
                        continue;
                    }

                    SiteContext siteContext = _siteContextFactory.GetSiteContext(matchingSite.Name);

                    Language siteLanguage = _languageManager.GetLanguage(siteContext.Language);

                    Item homeItem = _itemManager.GetItem(siteContext.StartPath, siteLanguage, Version.Latest, siteContext.Database);
                    if (homeItem == null || homeItem.Versions.Count == 0)
                    {
                        // TODO - KEK: throw exception here?
                        continue;
                    }

                    string name         = siteContext.SiteInfo.Name;
                    string startPathUrl = _linkManager.GetItemUrl(homeItem, new ItemUrlBuilderOptions
                    {
                        SiteResolving          = true,
                        Site                   = siteContext,
                        AlwaysIncludeServerUrl = true,
                        LowercaseUrls          = true,
                        LanguageEmbedding      = LanguageEmbedding.Never
                    });

                    var enterspeedSiteInfo = new EnterspeedSiteInfo
                    {
                        Name         = name,
                        BaseUrl      = startPathUrl,
                        HomeItemPath = siteContext.StartPath,
                        SiteItemPath = siteContext.RootPath
                    };

                    if (siteContext.Properties["scheme"] != null &&
                        siteContext.Properties["scheme"].Equals("https", StringComparison.OrdinalIgnoreCase))
                    {
                        enterspeedSiteInfo.IsHttpsEnabled = true;
                    }

                    config.SiteInfos.Add(enterspeedSiteInfo);
                }
            }

            // Settings caching values
            _configuration           = config;
            _configurationRevisionId = currentRevisionId;

            return(_configuration);
        }