private static PageTemplateConfiguration LoadPageTemplateConfiguration(string configurationPath)
        {
            PageTemplateConfiguration rtnConfig = null;

            XmlSerializer serializer = new XmlSerializer(typeof(PageTemplateConfiguration));

            bool pageAssemblyInstructionXmlValid = true;

            pageAssemblyInstructionXmlValid = PageAssemblyInstructionFactory.ValidateXml(PageTemplateConfigurationPath,
                                                                                         HttpContext.Current.Server.MapPath(ContentDeliveryEngineConfig.PageAssembly.PageAssemblyInfoTypes.XsdPath));

            try
            {
                using (FileStream xmlFile = File.Open(configurationPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
                {
                    rtnConfig = (PageTemplateConfiguration)serializer.Deserialize(XmlReader.Create(xmlFile));
                }
            }
            catch (Exception ex)
            {
                //TODO: Do something here
            }

            return(rtnConfig);
        }
 private static void AddPageTemplateConfigurationToCache(PageTemplateConfiguration config, string configurationPath)
 {
     HttpContext.Current.Cache.Add(
         PageTemplateConfigurationKey,
         config,
         new CacheDependency(configurationPath),
         Cache.NoAbsoluteExpiration,
         Cache.NoSlidingExpiration,
         CacheItemPriority.NotRemovable,
         new CacheItemRemovedCallback(PTCCachedRemovalCallback));
 }
        private static void PTCCachedRemovalCallback(string key, object config, CacheItemRemovedReason reason)
        {
            //If the PageTemplateConfiguration was removed because of the dependency, then
            //reload the PageTemplateConfiguration
            if (
                key == PageTemplateConfigurationKey &&
                reason == CacheItemRemovedReason.DependencyChanged
                )
            {
                PageTemplateConfiguration reloadedConfig =
                    LoadPageTemplateConfiguration(PageTemplateConfigurationPath);

                AddPageTemplateConfigurationToCache(reloadedConfig, PageTemplateConfigurationPath);
            }
        }
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            PageTemplateConfiguration target = obj as PageTemplateConfiguration;

            if (target == null)
            {
                return(false);
            }

            if (
                (TemplateThemeCollection == null && target.TemplateThemeCollection != null) ||
                (TemplateThemeCollection != null && target.TemplateThemeCollection == null)
                )
            {
                return(false);
            }

            if (TemplateThemeCollection.Length != target.TemplateThemeCollection.Length)
            {
                return(false);
            }

            for (int i = 0; i < TemplateThemeCollection.Length; i++)
            {
                if (TemplateThemeCollection[i] == null)
                {
                    if (target.TemplateThemeCollection[i] != null)
                    {
                        return(false);
                    }

                    //If we did not return then we know that target.TemplateThemeCollection[i] is also null
                }
                else
                {
                    if (!TemplateThemeCollection[i].Equals(target.TemplateThemeCollection[i]))
                    {
                        return(false);
                    }
                }
            }

            if (
                (PageTemplateCollections == null && target.PageTemplateCollections != null) ||
                (PageTemplateCollections != null && target.PageTemplateCollections == null)
                )
            {
                return(false);
            }

            if (PageTemplateCollections.Length != target.PageTemplateCollections.Length)
            {
                return(false);
            }

            for (int i = 0; i < PageTemplateCollections.Length; i++)
            {
                if (PageTemplateCollections[i] == null)
                {
                    if (target.PageTemplateCollections[i] != null)
                    {
                        return(false);
                    }

                    //If we did not return then we know that target.PageTemplateCollections[i] is also null
                }
                else
                {
                    if (!PageTemplateCollections[i].Equals(target.PageTemplateCollections[i]))
                    {
                        return(false);
                    }
                }
            }


            return(true);
        }