/// <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;
        }
        /// <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;
        }