コード例 #1
0
 public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
 {
     if (context.Parameters != null && context.Parameters.Count > 0)
     {
         try
         {
             string itemID = context.Parameters["itemID"] ?? "";
             itemID = Util.FormatID(itemID);
             string dsID = context.Parameters["dataSourceID"] ?? "";
             dsID = Util.FormatID(dsID);
             string renderingID = context.Parameters["renderingID"] ?? "";
             renderingID = Util.FormatID(renderingID);
             string deviceID = context.Parameters["deviceID"] ?? "";
             deviceID = Util.FormatID(deviceID);
             string dbName             = context.Parameters["dbName"] ?? "";
             Sitecore.Data.Database db = Sitecore.Data.Database.GetDatabase(dbName);
             if (db != null)
             {
                 Item i = db.GetItem(itemID);
                 try
                 {
                     string name = i.Name;
                 }
                 catch { }
                 if (i != null && Sitecore.Data.ID.IsID(renderingID) && Sitecore.Data.ID.IsID(dsID))
                 {
                     using (new EditContext(i))
                     {
                         Sitecore.Data.Fields.LayoutField  layoutField      = new Sitecore.Data.Fields.LayoutField(i.Fields[Sitecore.FieldIDs.LayoutField]);
                         Sitecore.Layouts.LayoutDefinition layoutDefinition = Sitecore.Layouts.LayoutDefinition.Parse(layoutField.Value);
                         Sitecore.Layouts.DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(deviceID);
                         foreach (Sitecore.Layouts.RenderingDefinition rd in deviceDefinition.Renderings)
                         {
                             if (HealthIS.Apps.Util.FormatID(rd.UniqueId) == renderingID)
                             {
                                 rd.Datasource     = HealthIS.Apps.Util.FormatID(dsID);
                                 layoutField.Value = layoutDefinition.ToXml();
                             }
                         }
                     }
                 }
                 else
                 {
                     Exception ex = new Exception("Update Datasource Issue with id: " + itemID + " or dsID: " + dsID + " or i: " + i);
                     Util.LogError(ex.Message, ex, this);
                 }
             }
         }
         catch (Exception ex)
         {
             Util.LogError(ex.Message, ex, this);
         }
     }
 }
コード例 #2
0
 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;
 }
コード例 #3
0
        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));
        }