Пример #1
0
        protected virtual void ResolveDatasource(GetRenderingDatasourceArgs args)
        {
            var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath);
            var source      = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation];
            var name        = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(source);

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            var datasources = new Item[] {};
            var provider    = providerFactory.GetProvider(args.ContentDatabase);

            if (provider != null)
            {
                datasources = provider.GetDatasources(name, contextItem);
            }

            if (!datasources.Any())
            {
                provider = providerFactory.GetFallbackProvider(args.ContentDatabase);
                if (provider == null)
                {
                    return;
                }

                datasources = provider.GetDatasources(name, contextItem);
            }

            args.DatasourceRoots.AddRange(datasources);
        }
Пример #2
0
        protected virtual void ResolveDatasourceTemplate(GetRenderingDatasourceArgs args)
        {
            var contextItem        = args.ContentDatabase.GetItem(args.ContextItemPath);
            var datasourceLocation = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation];
            var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocation);

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            Item datasourceTemplate = null;
            var  provider           = providerFactory.GetProvider(args.ContentDatabase);

            if (provider != null)
            {
                datasourceTemplate = provider.GetDatasourceTemplate(name, contextItem);
            }

            if (datasourceTemplate == null)
            {
                provider = providerFactory.GetFallbackProvider(args.ContentDatabase);
                if (provider != null)
                {
                    datasourceTemplate = provider.GetDatasourceTemplate(name, contextItem);
                }
            }

            args.Prototype = datasourceTemplate;
        }
        public void GetSiteDatasourceConfigurationName_IncorrectSettings_NullOrEmpty()
        {
            var setting     = "med.ia";
            var name        = $"site:{setting}";
            var settingName = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(name);

            settingName.Should().BeNullOrEmpty();
        }
        public void GetSiteDatasourceConfigurationName_CorrectSettingsString_ReturnSettingName()
        {
            var setting     = "media";
            var name        = $"site:{setting}";
            var settingName = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(name);

            settingName.Should().BeEquivalentTo(setting);
        }
Пример #5
0
        private static string GetDatasourceConfigurationName(Item renderingItem)
        {
            var datasourceLocationValue     = renderingItem[DatasourceLocationFieldName];
            var datasourceConfigurationName = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocationValue);

            if (string.IsNullOrEmpty(datasourceConfigurationName))
            {
                datasourceConfigurationName = renderingItem.Name;
            }
            return(datasourceConfigurationName);
        }
Пример #6
0
        protected virtual void ResolveDatasourceTemplate(GetRenderingDatasourceArgs args)
        {
            var contextItem        = args.ContentDatabase.GetItem(args.ContextItemPath);
            var datasourceLocation = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation];
            var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocation);

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            args.Prototype = this.provider.GetDatasourceTemplate(contextItem, name);
        }
Пример #7
0
        public void Process(GetRenderingDatasourceArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            var datasource = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation];

            if (!DatasourceConfigurationService.IsSiteDatasourceLocation(datasource))
            {
                return;
            }

            ResolveDatasource(args);
            ResolveDatasourceTemplate(args);
        }
Пример #8
0
        protected virtual void ResolveDatasource(GetRenderingDatasourceArgs args)
        {
            var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath);
            var source      = args.RenderingItem[Templates.RenderingOptions.Fields.DatasourceLocation];
            var name        = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(source);

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            var datasourceLocations = this.provider.GetDatasourceLocations(contextItem, name);

            args.DatasourceRoots.AddRange(datasourceLocations);
        }