protected void ShowConfirm(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (!args.IsPostBack)
            {
                SheerResponse.Confirm("Personalize component settings will be removed. Are you sure you want to continue?");
                args.WaitForPostBack();
                return;
            }
            if (!args.HasResult || !(args.Result != "no"))
            {
                this.ComponentPersonalization.Checked = true;
                return;
            }
            SheerResponse.Eval("scTogglePersonalizeComponentSection()");
            XElement rulesSet = this.RulesSet;

            foreach (XElement xElement in rulesSet.Elements("rule"))
            {
                XElement actionById = PersonalizationFormWithActions.GetActionById(xElement, this.SetRenderingActionId);
                if (actionById == null)
                {
                    continue;
                }
                actionById.Remove();
                HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
                this.RenderSetRenderingAction(xElement, htmlTextWriter);
                ShortID shortID = ShortID.Parse(xElement.GetAttributeValue("uid"));
                Assert.IsNotNull(shortID, "ruleId");
                SheerResponse.SetInnerHtml(string.Concat(shortID, "_setrendering"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", shortID.ToString()));
            }
            this.RulesSet = rulesSet;
        }
 private bool IsComponentDisplayed(XElement rule)
 {
     Assert.ArgumentNotNull(rule, "rule");
     if (PersonalizationFormWithActions.GetActionById(rule, this.HideRenderingActionId) != null)
     {
         return(false);
     }
     return(true);
 }
        private static void RemoveAction(XElement rule, string id)
        {
            Assert.ArgumentNotNull(rule, "rule");
            Assert.ArgumentNotNull(id, "id");
            XElement actionById = PersonalizationFormWithActions.GetActionById(rule, id);

            if (actionById == null)
            {
                return;
            }
            actionById.Remove();
        }
        private void RenderSetRenderingAction(XElement rule, HtmlTextWriter writer)
        {
            Assert.ArgumentNotNull(rule, "rule");
            Assert.ArgumentNotNull(writer, "writer");
            string   itemID     = this.RenderingDefition.ItemID;
            XElement actionById = PersonalizationFormWithActions.GetActionById(rule, this.SetRenderingActionId);
            bool     flag       = true;

            if (actionById != null)
            {
                string attributeValue = actionById.GetAttributeValue("RenderingItem");
                if (!string.IsNullOrEmpty(attributeValue))
                {
                    itemID = attributeValue;
                    flag   = false;
                }
            }
            writer.Write(string.Concat("<div ", (!flag ? string.Empty : "class='default-values'"), ">"));
            if (string.IsNullOrEmpty(itemID))
            {
                writer.Write("</div>");
                return;
            }
            Item item = Client.ContentDatabase.GetItem(itemID);

            if (item == null)
            {
                writer.Write("</div>");
                return;
            }
            writer.Write("<span class='section-header' unselectable='on'>");
            writer.Write(Translate.Text("Presentation:"));
            writer.Write("</span>");
            string themedImageSource = Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id48x48);

            if (!string.IsNullOrEmpty(item.Appearance.Thumbnail) && item.Appearance.Thumbnail != Settings.DefaultThumbnail)
            {
                string thumbnailSrc = UIUtil.GetThumbnailSrc(item, 128, 128);
                if (!string.IsNullOrEmpty(thumbnailSrc))
                {
                    themedImageSource = thumbnailSrc;
                }
            }
            writer.Write("<div style=\"background-image:url('{0}')\" class='thumbnail-container'>", HttpUtility.HtmlEncode(themedImageSource));
            writer.Write("</div>");
            writer.Write("<div class='picker-container'>");
            this.RenderPicker(writer, item, "SetRenderingClick", "ResetRendering", false, false);
            writer.Write("</div>");
            writer.Write("</div>");
        }
        protected void SetRendering(ClientPipelineArgs args)
        {
            string result;

            Assert.ArgumentNotNull(args, "args");
            if (!args.IsPostBack)
            {
                string placeholder = this.RenderingDefition.Placeholder;
                Assert.IsNotNull(placeholder, "placeholder");
                string layout = this.Layout;
                GetPlaceholderRenderingsArgs getPlaceholderRenderingsArg = new GetPlaceholderRenderingsArgs(placeholder, layout, Client.ContentDatabase, ID.Parse(this.DeviceId))
                {
                    OmitNonEditableRenderings = true
                };
                getPlaceholderRenderingsArg.Options.ShowOpenProperties = false;
                CorePipeline.Run("getPlaceholderRenderings", getPlaceholderRenderingsArg);
                string dialogURL = getPlaceholderRenderingsArg.DialogURL;
                if (string.IsNullOrEmpty(dialogURL))
                {
                    SheerResponse.Alert("An error occurred.", new string[0]);
                    return;
                }
                SheerResponse.ShowModalDialog(dialogURL, "720px", "470px", string.Empty, true);
                args.WaitForPostBack();
                return;
            }
            if (args.HasResult)
            {
                if (args.Result.IndexOf(',') < 0)
                {
                    result = args.Result;
                }
                else
                {
                    string str      = args.Result;
                    char[] chrArray = new char[] { ',' };
                    result = str.Split(chrArray)[0];
                }
                XElement rulesSet = this.RulesSet;
                string   item     = args.Parameters["id"];
                XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, item);
                Assert.IsNotNull(ruleById, "rule");
                (PersonalizationFormWithActions.GetActionById(ruleById, this.SetRenderingActionId) ?? PersonalizationFormWithActions.AddAction(ruleById, this.SetRenderingActionId)).SetAttributeValue("RenderingItem", ShortID.DecodeID(result));
                this.RulesSet = rulesSet;
                HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
                this.RenderSetRenderingAction(ruleById, htmlTextWriter);
                SheerResponse.SetInnerHtml(string.Concat(item, "_setrendering"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", item));
            }
        }
        private void RenderSetDatasourceAction(XElement rule, HtmlTextWriter writer)
        {
            Assert.ArgumentNotNull(rule, "rule");
            Assert.ArgumentNotNull(writer, "writer");
            string   datasource = this.RenderingDefition.Datasource;
            XElement actionById = PersonalizationFormWithActions.GetActionById(rule, this.SetDatasourceActionId);
            bool     flag       = true;

            if (actionById == null)
            {
                datasource = string.Empty;
            }
            else
            {
                datasource = actionById.GetAttributeValue("DataSource");
                flag       = false;
            }
            Item contextItem = null;
            bool flag1       = false;

            if (string.IsNullOrEmpty(datasource))
            {
                contextItem = this.ContextItem;
                flag1       = true;
            }
            else
            {
                contextItem = Client.ContentDatabase.GetItem(datasource);
            }
            writer.Write(string.Concat("<div ", (!flag ? string.Empty : "class='default-values'"), ">"));
            writer.Write("<span class='section-header' unselectable='on'>");
            writer.Write(Translate.Text("Content:"));
            writer.Write("</span>");
            if (contextItem != null)
            {
                this.RenderPicker(writer, contextItem, "SetDatasourceClick", "ResetDatasource", !flag1, flag1);
            }
            else
            {
                this.RenderPicker(writer, datasource, "SetDatasourceClick", "ResetDatasource", !flag1, flag1);
            }
            writer.Write("</div>");
        }
        protected void SetDatasource(ClientPipelineArgs args)
        {
            Language language;

            Assert.ArgumentNotNull(args, "args");
            string   item     = args.Parameters["id"];
            XElement rulesSet = this.RulesSet;
            XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, item);

            Assert.IsNotNull(ruleById, "rule");
            if (args.IsPostBack)
            {
                if (args.HasResult)
                {
                    (PersonalizationFormWithActions.GetActionById(ruleById, this.SetDatasourceActionId) ?? PersonalizationFormWithActions.AddAction(ruleById, this.SetDatasourceActionId)).SetAttributeValue("DataSource", args.Result);
                    this.RulesSet = rulesSet;
                    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
                    this.RenderSetDatasourceAction(ruleById, htmlTextWriter);
                    SheerResponse.SetInnerHtml(string.Concat(item, "_setdatasource"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", item));
                }
                return;
            }
            XElement actionById = PersonalizationFormWithActions.GetActionById(ruleById, this.SetRenderingActionId);
            Item     item1      = null;

            if (actionById != null && !string.IsNullOrEmpty(actionById.GetAttributeValue("RenderingItem")))
            {
                item1 = Client.ContentDatabase.GetItem(actionById.GetAttributeValue("RenderingItem"));
            }
            else if (!string.IsNullOrEmpty(this.RenderingDefition.ItemID))
            {
                item1 = Client.ContentDatabase.GetItem(this.RenderingDefition.ItemID);
            }
            if (item1 == null)
            {
                SheerResponse.Alert("Item not found.", new string[0]);
                return;
            }
            Item contextItem = this.ContextItem;
            GetRenderingDatasourceArgs getRenderingDatasourceArg = new GetRenderingDatasourceArgs(item1)
            {
                FallbackDatasourceRoots = new List <Item>()
                {
                    Client.ContentDatabase.GetRootItem()
                }
            };
            GetRenderingDatasourceArgs getRenderingDatasourceArg1 = getRenderingDatasourceArg;

            if (contextItem != null)
            {
                language = contextItem.Language;
            }
            else
            {
                language = null;
            }
            getRenderingDatasourceArg1.ContentLanguage = language;
            getRenderingDatasourceArg.ContextItemPath  = (contextItem != null ? contextItem.Paths.FullPath : string.Empty);
            getRenderingDatasourceArg.ShowDialogIfDatasourceSetOnRenderingItem = true;
            GetRenderingDatasourceArgs datasource = getRenderingDatasourceArg;
            XElement xElement = PersonalizationFormWithActions.GetActionById(ruleById, this.SetDatasourceActionId);

            if (xElement == null || string.IsNullOrEmpty(xElement.GetAttributeValue("DataSource")))
            {
                datasource.CurrentDatasource = this.RenderingDefition.Datasource;
            }
            else
            {
                datasource.CurrentDatasource = xElement.GetAttributeValue("DataSource");
            }
            if (string.IsNullOrEmpty(datasource.CurrentDatasource))
            {
                datasource.CurrentDatasource = contextItem.ID.ToString();
            }
            CorePipeline.Run("getRenderingDatasource", datasource);
            if (string.IsNullOrEmpty(datasource.DialogUrl))
            {
                SheerResponse.Alert("An error occurred.", new string[0]);
                return;
            }
            SheerResponse.ShowModalDialog(datasource.DialogUrl, "960px", "660px", string.Empty, true);
            args.WaitForPostBack();
        }
        private bool PersonalizeComponentActionExists()
        {
            XElement rulesSet = this.RulesSet;

            return(rulesSet.Elements("rule").Any <XElement>((XElement rule) => PersonalizationFormWithActions.GetActionById(rule, this.SetRenderingActionId) != null));
        }