public void Initialize(InitializationEngine context)
        {
            if (_initialized || ContentReference.IsNullOrEmpty(GlobalNewsContainer) || context.HostType != HostType.WebApplication)
            {
                return;
            }

            var providerManager = ServiceLocator.Current.GetInstance<IContentProviderManager>();
            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
            var startPages = contentLoader.GetChildren<PageData>(SiteDefinition.Current.RootPage).OfType<StartPage>();

            // Attach content provider to each site's global news container
            foreach (var startPage in startPages.Where(startPage => !ContentReference.IsNullOrEmpty(startPage.GlobalNewsPageLink)))
            {
                try
                {
                    Logger.Debug("Attaching global news content provider to page {0} [{1}], global news will be retrieved from page {2} [{3}]",
                        contentLoader.Get<PageData>(startPage.GlobalNewsPageLink).Name, 
                        startPage.GlobalNewsPageLink.ID, 
                        contentLoader.Get<PageData>(GlobalNewsContainer).PageName, 
                        GlobalNewsContainer.ID);

                    var provider = new ClonedContentProvider(GlobalNewsContainer.ToPageReference(), startPage.GlobalNewsPageLink, startPage.Category);

                    providerManager.ProviderMap.AddProvider(provider);
                }
                catch (Exception ex)
                {
                    Logger.Error("Unable to create global news content provider for start page with ID {0}: {1}", startPage.PageLink.ID, ex.Message);
                }
            }

            _initialized = true;
        }
        public void Initialize(InitializationEngine context)
        {
            if (_initialized || ContentReference.IsNullOrEmpty(GlobalNewsContainer) || context.HostType != HostType.WebApplication)
            {
                return;
            }

            var providerManager = ServiceLocator.Current.GetInstance <IContentProviderManager>();
            var contentLoader   = ServiceLocator.Current.GetInstance <IContentLoader>();
            var startPages      = contentLoader.GetChildren <PageData>(SiteDefinition.Current.RootPage).OfType <StartPage>();

            // Attach content provider to each site's global news container
            foreach (var startPage in startPages.Where(startPage => !ContentReference.IsNullOrEmpty(startPage.GlobalNewsPageLink)))
            {
                try
                {
                    Logger.Debug("Attaching global news content provider to page {0} [{1}], global news will be retrieved from page {2} [{3}]",
                                 contentLoader.Get <PageData>(startPage.GlobalNewsPageLink).Name,
                                 startPage.GlobalNewsPageLink.ID,
                                 contentLoader.Get <PageData>(GlobalNewsContainer).PageName,
                                 GlobalNewsContainer.ID);

                    var provider = new ClonedContentProvider(GlobalNewsContainer.ToPageReference(), startPage.GlobalNewsPageLink, startPage.Category);

                    providerManager.ProviderMap.AddProvider(provider);
                }
                catch (Exception ex)
                {
                    Logger.Error("Unable to create global news content provider for start page with ID {0}: {1}", startPage.PageLink.ID, ex.Message);
                }
            }

            _initialized = true;
        }
        /// <summary>
        ///     Loads the provider.
        /// </summary>
        /// <returns>
        ///     [true] if the provider has been loaded.
        /// </returns>
        private static bool LoadProviders()
        {
            IContentProviderManager providerManager = ServiceLocator.Current.GetInstance <IContentProviderManager>();

            Collection <ClonedContentProviderSettings> providerCollection = SettingsRepository.Instance.GetAll();

            foreach (ClonedContentProviderSettings providerSettings in providerCollection)
            {
                try
                {
                    ContentProvider contentProvider = providerManager.GetProvider(providerSettings.Name);

                    if (contentProvider != null)
                    {
                        continue;
                    }

                    CategoryList categoryList =
                        new CategoryList(
                            providerSettings.CategoryList.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(int.Parse)
                            .ToArray());

                    ClonedContentProvider provider = new ClonedContentProvider(
                        providerSettings.Name,
                        new PageReference(providerSettings.Root),
                        new PageReference(providerSettings.EntryPoint),
                        categoryList);

                    providerManager.ProviderMap.AddProvider(provider);
                }
                catch (ArgumentNullException)
                {
                    return(false);
                }
                catch (ArgumentException)
                {
                    return(false);
                }
                catch (NotSupportedException)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Adds the provider.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryPoint">The entry point.</param>
        /// <param name="providerName">Name of the provider.</param>
        /// <param name="categoryList">The category list.</param>
        /// <returns>
        ///   <c>true</c> if [the provider has been attached]; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">Content provider for this node already attached.
        /// or
        /// Content provider with same name already attached.</exception>
        public static bool AddProvider(int root, int entryPoint, string providerName, CategoryList categoryList)
        {
            string name = string.Format(CultureInfo.InvariantCulture, "{0}-ClonedContent-{1}-{2}", providerName, root, entryPoint);

            IQueryable <ClonedContentProviderSettings> providerCollection = SettingsRepository.Instance.GetAll().AsQueryable();

            if (providerCollection.Count(pc => pc.EntryPoint.Equals(entryPoint)) > 0)
            {
                // A provider is already attached to this node.
                throw new InvalidOperationException("Content provider for this node already attached.");
            }

            if (providerCollection.Count(pc => pc.Name.Equals(name)) > 0)
            {
                // A provider with the same name already exists.
                throw new InvalidOperationException("Content provider with same name already attached.");
            }

            CategoryList categories = categoryList ?? new CategoryList();

            ClonedContentProvider provider = new ClonedContentProvider(
                name,
                new PageReference(root),
                new PageReference(entryPoint),
                categories);

            IContentProviderManager providerManager = ServiceLocator.Current.GetInstance <IContentProviderManager>();

            ClonedContentProviderSettings contentProviderSettings = new ClonedContentProviderSettings
            {
                Name         = name,
                EntryPoint   = entryPoint,
                Root         = root,
                CategoryList =
                    string.Join(
                        ",",
                        categories)
            };

            providerManager.ProviderMap.AddProvider(provider);

            SettingsRepository.Instance.SaveSettings(contentProviderSettings);

            CacheManager.Clear();

            return(true);
        }
        public void Initialize(InitializationEngine context)
        {
            if (_initialized || ContentReference.IsNullOrEmpty(GlobalNewsContainer) || context.HostType != HostType.WebApplication)
            {
                return;
            }

            var providerManager = ServiceLocator.Current.GetInstance<IContentProviderManager>();
            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
            var siteDefinitionRepository = ServiceLocator.Current.GetInstance<SiteDefinitionRepository>();
            var siteSettingsRepository = ServiceLocator.Current.GetInstance<ISiteSettingsRepository>();

            // Attach content provider to each site's global news container
            foreach (var site in siteDefinitionRepository.List())
            {
                var siteSettings = siteSettingsRepository.Get(site);
                if (ContentReference.IsNullOrEmpty(siteSettings.GlobalNewsPageLink))
                    continue;

                try
                {
                    Logger.Debug("Attaching global news content provider to page {0} [{1}], global news will be retrieved from page {2} [{3}]",
                        contentLoader.Get<PageData>(siteSettings.GlobalNewsPageLink).Name,
                        siteSettings.GlobalNewsPageLink.ID, 
                        contentLoader.Get<PageData>(GlobalNewsContainer).PageName, 
                        GlobalNewsContainer.ID);

                    var provider = new ClonedContentProvider(GlobalNewsContainer.ToPageReference(), siteSettings.GlobalNewsPageLink, siteSettings.Category);

                    providerManager.ProviderMap.AddProvider(provider);
                }
                catch (Exception ex)
                {
                    Logger.Error("Unable to create global news content provider for site with name {0}: {1}", site.Name, ex.Message);
                }
            }

            _initialized = true;
        }