protected override void ProcessRenderings(Item item, LayoutDefinition layout, DeviceDefinition device,
            IEnumerable<RenderingDefinition> renderings)
        {
            if (renderings.Any())
            {
                if (!ShouldProcess(item.GetProviderPath(),
                    $"Remove rendering(s) '{renderings.Select(r => r.ItemID.ToString()).Aggregate((seed, curr) => seed + ", " + curr)}' from device {Device.Name}"))
                    return;

                foreach (
                    var instanceRendering in
                        renderings.Select(rendering => device.Renderings.Cast<RenderingDefinition>()
                            .FirstOrDefault(r => r.UniqueId == rendering.UniqueId))
                            .Where(instanceRendering => instanceRendering != null)
                            .Reverse())
                {
                    device.Renderings.Remove(instanceRendering);
                }

                item.Edit(p =>
                {
                    var outputXml = layout.ToXml();
                    Item[LayoutFieldId] = outputXml;
                });
            }
            else
            {
                WriteError(typeof(ObjectNotFoundException), "Cannot find a rendering to remove",
                    ErrorIds.RenderingNotFound, ErrorCategory.ObjectNotFound, null);
            }
        }
Beispiel #2
0
        protected override void ProcessLayout(Item item, LayoutDefinition layout, DeviceDefinition device)
        {
            if (!ShouldProcess(item.GetProviderPath(), "Add rendering " + Instance.ItemID))
            {
                return;
            }
            var rendering = new RenderingDefinition
            {
                ItemID = Instance.ItemID,
                Placeholder = PlaceHolder ?? Instance.Placeholder,
                Datasource = DataSource ?? Instance.Datasource,
                Cachable = Instance.Cachable,
                VaryByData = Instance.VaryByData,
                VaryByDevice = Instance.VaryByDevice,
                VaryByLogin = Instance.VaryByLogin,
                VaryByParameters = Instance.VaryByParameters,
                VaryByQueryString = Instance.VaryByQueryString,
                VaryByUser = Instance.VaryByUser
            };

            if (Parameter != null)
            {
                var parameters = new UrlString(rendering.Parameters ?? string.Empty);
                foreach (string name in Parameter.Keys)
                    if (parameters.Parameters.AllKeys.Contains(name))
                    {
                        parameters.Parameters[name] = Parameter[name].ToString();
                    }
                    else
                    {
                        parameters.Add(name, Parameter[name].ToString());
                    }
                rendering.Parameters = parameters.ToString();
            }

            //todo: add support for conditions
            //renderingDefinition.Conditions
            //todo: add support for multivariate tests
            //rendering.MultiVariateTest

            if (Index > -1)
            {
                device.Insert(index, rendering);
            }
            else
            {
                device.AddRendering(rendering);
            }

            item.Edit(p =>
            {
                var outputXml = layout.ToXml();
                Item["__Renderings"] = outputXml;
            });
        }
 public static IEnumerable<RenderingDefinition> GetTestingRenderings(LayoutDefinition layout, ID deviceID, Database database)
 {
     Assert.ArgumentNotNull((object)layout, "layout");
     Assert.ArgumentNotNull((object)deviceID, "deviceID");
     Assert.ArgumentNotNull((object)database, "database");
     List<RenderingDefinition> list = new List<RenderingDefinition>();
     ArrayList renderings = layout.GetDevice(deviceID.ToString()).Renderings;
     if (renderings == null)
         return (IEnumerable<RenderingDefinition>)list;
     foreach (RenderingDefinition rendering in renderings)
     {
         //if (Enumerable.Count<MultivariateTestValueItem>(TestingUtil.MultiVariateTesting.GetVariableValues(rendering, database)) > 1)
         list.Add(rendering);
     }
     return (IEnumerable<RenderingDefinition>)list;
 }
        protected override void ProcessRenderings(Item item, LayoutDefinition layout, DeviceDefinition device,
            IEnumerable<RenderingDefinition> renderings)
        {
            if (ShouldProcess(item.GetProviderPath(),
                string.Format("Remove rendering(s) '{0}' from device {1}",
                    renderings.Select(r => r.ItemID.ToString()).Aggregate((seed, curr) => seed + ", " + curr),
                    Device.Name)))
            {
                foreach (
                    var instanceRendering in
                        renderings.Select(rendering => device.Renderings.Cast<RenderingDefinition>()
                            .FirstOrDefault(r => r.UniqueId == rendering.UniqueId))
                            .Where(instanceRendering => instanceRendering != null))
                {
                    device.Renderings.Remove(instanceRendering);
                }

                item.Edit(p =>
                {
                    var outputXml = layout.ToXml();
                    Item["__Renderings"] = outputXml;
                });
            }
        }
Beispiel #5
0
 protected override void ProcessRenderings(Item item, LayoutDefinition layout, DeviceDefinition device,
     IEnumerable<RenderingDefinition> renderings)
 {
     renderings.ToList().ForEach(r => WriteObject(ItemShellExtensions.WrapInItemOwner(SessionState, item, r)));
 }
        private void SetLayoutFieldValueIfValidDevice(LayoutDefinition layoutDefinition, Item item)
        {
            bool isDeviceValid = layoutDefinition != null && layoutDefinition.Devices != null && layoutDefinition.Devices.Count > 0;
            if (isDeviceValid)
            {
                var renderings = (layoutDefinition.Devices[0] as DeviceDefinition).Renderings;

                foreach (RenderingDefinition rendering in renderings)
                {
                    SetLayoutFieldValueIfApplicable(rendering, layoutDefinition, item);
                }
            }
        }
 private void SetLayoutFieldValueIfEditMode(RenderingDefinition renderingDefinition, LayoutDefinition layoutDefinition, Item item)
 {
     if (IsEditMode)
     {
         SetLayoutFieldValue(renderingDefinition, layoutDefinition, item);
     }
 }
 private void SetLayoutFieldValueIfApplicable(RenderingDefinition renderingDefinition, LayoutDefinition layoutDefinition, Item item)
 {
     if (renderingDefinition.ItemID == _renderingId.ToString())
     {
         SetLayoutFieldValueIfEditMode(renderingDefinition, layoutDefinition, item);
     }
 }
        private void SetLayoutFieldValue(RenderingDefinition renderingDefinition, LayoutDefinition layoutDefinition, Item item)
        {
            Assert.ArgumentNotNull(item, "item");

            using (new Sitecore.Data.Items.EditContext(item))
            {
                renderingDefinition.Datasource = _datasourceId.ToString();
                item[Sitecore.FieldIDs.LayoutField] = layoutDefinition.ToXml();
            }
        }
Beispiel #10
0
 protected abstract void ProcessLayout(Item item, LayoutDefinition layout, DeviceDefinition device);
        private void SetLayoutFieldValueIfEditMode(RenderingDefinition renderingDefinition, LayoutDefinition layoutDefinition, Item item)
        {
            if (_processingResults.ContainsKey(item.ID))
            {
                _processingResults[item.ID].Updated = true;
            }

            if (IsEditMode)
            {
                SetLayoutFieldValue(renderingDefinition, layoutDefinition, item);
            }
        }
 /// <summary>
 /// Sets the definition.
 /// </summary>
 /// <param name="layout">
 /// The layout.
 /// </param>
 private static void SetDefinition(LayoutDefinition layout)
 {
     Assert.ArgumentNotNull(layout, "layout");
     string xml = layout.ToXml();
     WebUtil.SetSessionValue(AdvancedDeviceEditorForm.GetSessionHandle(), xml);
 }
 protected abstract void ProcessRenderings(Item item, LayoutDefinition layout, DeviceDefinition device,
     IEnumerable<RenderingDefinition> renderings);
        protected override void ProcessLayout(Item item, LayoutDefinition layout, DeviceDefinition device)
        {
            if (device == null || device.Renderings == null)
            {
                return;
            }

            var renderings = device.Renderings.Cast<RenderingDefinition>();

            if (Instance != null)
            {
                renderings = new[] {Instance};
            }
            else if (!string.IsNullOrEmpty(UniqueId))
            {
                renderings =
                    renderings.Where(r => string.Equals(r.UniqueId, UniqueId, StringComparison.OrdinalIgnoreCase));
            }
            else
            {
                if (Rendering != null)
                {
                    renderings = renderings.Where(r => r.ItemID == Rendering.ID.ToString());
                }

                if (!string.IsNullOrEmpty(DataSource))
                {
                    renderings = WildcardFilter(DataSource, renderings, r => r.Datasource);
                }

                if (!string.IsNullOrEmpty(PlaceHolder))
                {
                    renderings = WildcardFilter(PlaceHolder, renderings, r => r.Placeholder);
                }

                if (Index > -1)
                {
                    renderings = renderings.Skip(index).Take(1);
                }
            }

            if (paramPatterns != null)
            {
                var paramFilteredRenderings = new List<RenderingDefinition>();
                foreach (var rendering in renderings)
                {
                    if (string.IsNullOrEmpty(rendering.Parameters))
                    {
                        continue;
                    }
                    var parsedParams = new UrlString(rendering.Parameters);
                    var match = true;
                    foreach (var param in paramPatterns)
                    {
                        if (!parsedParams.Parameters.AllKeys.Contains(param.Key, StringComparer.OrdinalIgnoreCase))
                        {
                            match = false;
                            break;
                        }
                        if (!param.Value.IsMatch(parsedParams.Parameters[param.Key]))
                        {
                            match = false;
                            break;
                        }
                    }
                    if (match)
                    {
                        paramFilteredRenderings.Add(rendering);
                    }
                }
                renderings = paramFilteredRenderings;
            }
            ProcessRenderings(item, layout, device, renderings);
        }
        private void BuildDevice(GridPanel grid, LayoutDefinition layout, DeviceItem deviceItem)
        {
            Assert.ArgumentNotNull(grid, "grid");
            Assert.ArgumentNotNull(deviceItem, "deviceItem");

            var xmlControl = string.IsNullOrEmpty(OpenDeviceClick)
                ? Resource.GetWebControl("LayoutFieldDeviceReadOnly") as XmlControl
                : Resource.GetWebControl("LayoutFieldDevice") as XmlControl;

            Assert.IsNotNull(xmlControl, typeof(XmlControl));

            grid.Controls.Add(xmlControl);

            string str1 = StringUtil.GetString(OpenDeviceClick).Replace("$Device", deviceItem.ID.ToString());
            string str2 = StringUtil.GetString(CopyToClick).Replace("$Device", deviceItem.ID.ToString());

            ReflectionUtil.SetProperty(xmlControl, "DeviceName", deviceItem.DisplayName);
            ReflectionUtil.SetProperty(xmlControl, "DeviceIcon", deviceItem.InnerItem.Appearance.Icon);
            ReflectionUtil.SetProperty(xmlControl, "DblClick", str1);
            ReflectionUtil.SetProperty(xmlControl, "Copy", str2);

            string str3 = string.Format("<span style=\"color:#999999\">{0}</span>", Translate.Text("[No layout specified]"));

            int index = 0;
            int num = 0;
            var parent1 = xmlControl["ControlsPane"] as System.Web.UI.Control;
            var parent2 = xmlControl["PlaceholdersPane"] as System.Web.UI.Control;

            if (layout != null)
            {
                DeviceDefinition device = layout.GetDevice(deviceItem.ID.ToString());
                string layout1 = device.Layout;

                if (!string.IsNullOrEmpty(layout1))
                {
                    Item obj = Client.ContentDatabase.GetItem(layout1);
                    if (obj != null)
                    {
                        str3 = Images.GetImage(obj.Appearance.Icon, 16, 16, "absmiddle", "0px 4px 0px 0px", obj.ID.ToString()) + obj.DisplayName;
                    }
                }

                ArrayList renderings = device.Renderings;
                if (renderings != null && renderings.Count > 0)
                {
                    Border border = new Border();
                    Context.ClientPage.AddControl(parent1, border);
                    foreach (RenderingDefinition renderingDefinition in renderings)
                    {
                        int conditionsCount = 0;

                        if (renderingDefinition.Rules != null && !renderingDefinition.Rules.IsEmpty)
                        {
                            conditionsCount = Enumerable.Count(renderingDefinition.Rules.Elements("rule"));
                        }

                        BuildRendering(border, device, renderingDefinition, index, conditionsCount);
                        ++index;
                    }
                }

                ArrayList placeholders = device.Placeholders;
                if (placeholders != null && placeholders.Count > 0)
                {
                    Border border = new Border();
                    Context.ClientPage.AddControl(parent2, border);

                    foreach (PlaceholderDefinition placeholderDefinition in placeholders)
                    {
                        BuildPlaceholder(border, device, placeholderDefinition);
                        ++num;
                    }
                }
            }

            ReflectionUtil.SetProperty(xmlControl, "LayoutName", str3);

            if (index == 0)
            {
                var noRenderingsLabel = string.Format("<span style=\"color:#999999\">{0}</span>", Translate.Text("[No renderings specified.]"));
                Context.ClientPage.AddControl(parent1, new LiteralControl(noRenderingsLabel));
            }

            if (num != 0)
            {
                return;
            }

            var noPlaceholdersLabel = string.Format("<span style=\"color:#999999\">{0}</span>", Translate.Text("[No placeholder settings were specified]"));
            Context.ClientPage.AddControl(parent2, new LiteralControl(noPlaceholdersLabel));
        }