private void InitializeSites()
        {
            if (DynamicSiteSettings.GetSiteCache.Count() > 0 && _sites != null && _dynamicSiteDictionary.Count > 0)
            {
                return;
            }

            Assert.IsNotNullOrEmpty(_dynamicConfigPath, "No siteConfig specified in DynamicSiteProvider configuration.");
            var collection = new SiteCollection();

            var nodes = Factory.GetConfigNodes(FileUtil.MakePath(_dynamicConfigPath, "defaultsite", '/'));

            Assert.IsFalse((nodes.Count > 1 ? 1 : 0) != 0, "Duplicate Dynamic Default Site Definition.");

            if (nodes.Count == 0)
            {
                return;
            }

            var defaultSite = ParseDefaultNode(nodes[0]);

            //Create Dictionary
            var siteDictionary = DynamicSiteManager.GetDynamicSitesDictionary(defaultSite);

            //Set Site Collection
            foreach (var keyValuePair in siteDictionary)
            {
                collection.Add(keyValuePair.Value);
            }

            ResolveInheritance(collection, siteDictionary);

            _sites = collection;
            _dynamicSiteDictionary = siteDictionary;
        }
        private void AddInheritedProperties(Site site, List <KeyValuePair <string, Site> > siteDictionary)
        {
            var index         = site.Properties["inherits"];
            var inheritedSite = siteDictionary.GetSiteByKey(DynamicSiteManager.CleanCacheKeyName(index));

            Assert.IsNotNull(inheritedSite, "Could not find base site '{0}' for site '{1}'.", DynamicSiteManager.CleanCacheKeyName(index), site.Name);

            foreach (var keyValuePair in inheritedSite.Properties.Where(keyValuePair => !site.Properties.ContainsKey(keyValuePair.Key)))
            {
                site.Properties[keyValuePair.Key] = keyValuePair.Value;
            }
        }
        protected new void Run(ClientPipelineArgs args)
        {
            var contentItem = Database.GetItem(ItemUri.Parse(args.Parameters["uri"]));

            if (contentItem == null)
            {
                SheerResponse.Alert("Item not found.");
            }
            else
            {
                var itemId = contentItem.ID.ToString();
                if (args.IsPostBack)
                {
                    if (args.Result != "yes")
                    {
                        return;
                    }
                    var startItem = Context.ContentDatabase.GetItem(Context.Site.StartPath);
                    if (startItem == null)
                    {
                        SheerResponse.Alert("Start item not found.");
                        return;
                    }
                    if (!HasPresentationPipeline.Run(startItem))
                    {
                        SheerResponse.Alert("The start item cannot be previewed because it has no layout for the current device.\n\nPreview cannot be started.");
                        return;
                    }
                    itemId = startItem.ID.ToString();
                }
                else if (!HasPresentationPipeline.Run(contentItem))
                {
                    SheerResponse.Confirm("The current item cannot be previewed because it has no layout for the current device.\n\nDo you want to preview the start Web page instead?");
                    args.WaitForPostBack();
                    return;
                }
                SheerResponse.CheckModified(false);

                //Dynamically Speaking, we want the site of the item as it relates to a home Item.
                //If not found, fallback to default functionalty.
                var site = DynamicSiteManager.GetSiteContextByContentItem(contentItem) ??
                           Factory.GetSite(Settings.Preview.DefaultSite);
                Assert.IsNotNull(site, "Site \"{0}\" not found", Settings.Preview.DefaultSite);
                WebUtil.SetCookieValue(site.GetCookieKey("sc_date"), string.Empty);
                PreviewManager.StoreShellUser(Settings.Preview.AsAnonymous);
                var webSiteUrl = SiteContext.GetWebSiteUrl();
                webSiteUrl["sc_itemid"] = itemId;
                webSiteUrl["sc_mode"]   = "preview";
                webSiteUrl["sc_lang"]   = contentItem.Language.ToString();
                DeviceSimulationUtil.DeacitvateSimulators();
                SheerResponse.Eval("window.open('" + webSiteUrl + "', '_blank')");
            }
        }
        private static void DoBaseTemplateUpdates([NotNull] Item item, ItemChanges itemChanges)
        {
            var siteSettings = (DynamicSiteSettingsItem)item;

            if (itemChanges == null ||
                !itemChanges.IsFieldModified(siteSettings.SiteDefinitionTemplate.Field.InnerField.ID))
            {
                DynamicSiteManager.PublishItemChanges(item);
                return;
            }

            var changedField = itemChanges.FieldChanges[siteSettings.SiteDefinitionTemplate.Field.InnerField.ID];
            var oldValue     = changedField.OriginalValue;
            var newValue     = changedField.Value;

            if (oldValue.Equals(newValue))
            {
                return;
            }

            if (newValue.IsNullOrEmpty())
            {
                if (item.Fields[changedField.FieldID].ContainsStandardValue)
                {
                    newValue = item.Fields[changedField.FieldID].GetStandardValue();
                }
            }

            if (!newValue.IsNullOrEmpty())
            {
                var newTemplateItem = DynamicSiteSettings.GetCurrentDatabase.GetTemplate(new ID(newValue));

                if (newTemplateItem != null)
                {
                    DynamicSiteManager.AddBaseTemplate(newTemplateItem);
                }
            }

            if (oldValue.IsNullOrEmpty())
            {
                return;
            }
            var oldTemplateItem = DynamicSiteSettings.GetCurrentDatabase.GetTemplate(new ID(oldValue));

            if (oldTemplateItem != null)
            {
                DynamicSiteManager.RemoveBaseTemplate(oldTemplateItem);
            }
        }
Beispiel #5
0
        public void Process(PipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            //Is Module Disabled at the config level?
            if (DynamicSiteSettings.Disabled)
            {
                return;
            }

            //Is Module Initialized, if not, Initialize. Exit on failure.
            if (!DynamicSiteSettings.IsInitialized)
            {
                DynamicSiteManager.InitializeSettings();
            }
        }
        private void ResetDynamicSitesCache([NotNull] Item item)
        {
            //Is Module Disabled at the config level?
            if (DynamicSiteSettings.Disabled)
            {
                return;
            }

            //If Item being deleted is a Dynamic Site, clear the Dynamic Site cache.
            if (!DynamicSiteManager.HasBaseTemplate(item))
            {
                return;
            }

            DynamicSiteManager.PublishItemChanges(item);
            DynamicSiteManager.ClearCache();
        }
 public override Site GetSite(string siteName)
 {
     Assert.ArgumentNotNullOrEmpty(siteName, "siteName");
     InitializeSites();
     return(_dynamicSiteDictionary.GetSiteByKey(DynamicSiteManager.CleanCacheKeyName(siteName)));
 }