Exemplo n.º 1
0
        public string Render(ImageFieldWrapperOptions options)
        {
            string param = "";

            param += (options.Width > 0) ? "&width=" + options.Width : string.Empty;
            param += (options.Height > 0) ? "&height=" + options.Height : string.Empty;
            param += (options.Crop) ? "&crop=1" : string.Empty;

            if (options.CornerRadii.Length > 0)
            {
                if (options.CornerRadii.Length == 4)
                {
                    param += "&rc=" + options.CornerRadii[0] + "," + options.CornerRadii[1] + "," + options.CornerRadii[2] + "," + options.CornerRadii[3];
                }
                else if (options.CornerRadii.Length == 1 && options.CornerRadii[0] > 0)
                {
                    param += "&rc=" + options.CornerRadii[0];
                }
            }
            if (param.StartsWith("&"))
            {
                param = param.Substring(1);
            }

            var fieldRenderer = new FieldRenderer();
            fieldRenderer.Item = Field.Item;
            fieldRenderer.FieldName = Field.Key;
            fieldRenderer.Parameters = param;

            var result = fieldRenderer.RenderField();

            return result.FirstPart + result.LastPart;
        }
        public static HtmlString RenderAroundHtml(this IFieldWrapper fieldWrapper, string innerHtml)
        {
            var fieldRenderer = new FieldRenderer
                                    {
                                        Item = ((Field)fieldWrapper.Original).Item,
                                        FieldName = ((Field)fieldWrapper.Original).Key
                                    };

            var result = fieldRenderer.RenderField();

            return new HtmlString(result.FirstPart + innerHtml + result.LastPart);
        }
	    /// <summary>
	    /// Gets translated phrase for context language by specified translation key.
	    /// With option of formatting like string.Format() method functionality.
	    /// Dictionary entry item will be created if it doesn't exist with default phrase value 
	    /// equals to passed parameter (or it will be equal to translation key in case default value is null or empty).
	    /// </summary>
	    /// <param name="key">The key.</param>
	    /// <param name="defaultValue">The default value.</param>
	    /// <param name="language"></param>
	    /// <param name="formatParams">The format params.</param>
	    /// <returns>System.String.</returns>
	    public virtual string Text(string key, string defaultValue, Language language, params object[] formatParams)
        {
            try
            {
                if (string.IsNullOrEmpty(key))
                {
                    return string.Empty;
                }

				var translationItem = GetTranslationItem(key, defaultValue, language ?? Context.Language);

                if (translationItem == null)
                {
                    return string.Empty;
                }

                var fieldRenderer = new FieldRenderer
                {
                    Item = translationItem,
                    FieldName = Constants.DICTIONARY_ENTRY_PHRASE_FIELD_NAME,
                };

                var result = fieldRenderer.Render();

                if (formatParams != null && formatParams.Length > 0 && !_siteContext.IsPageEditor)
                {
                    return string.Format(result, formatParams);
                }

                return result;
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error during translating the key '{0}'. {1}", key, ex.Message), ex, this);

                return string.Empty;
            }
        }
Exemplo n.º 4
0
        public override string GetFieldValue(DataRow dr, string fieldidentifier, string before, string after, string parameters)
        {
            string result = string.Empty;

            // Try to get the value directly from the sitecore item if possible,
            // otherwise just use the value in the DataRow
            if (!IsSpecialField(fieldidentifier) && dr.Table.Columns.Contains("_ItemId"))
            {
                Item item = this.InnerItem.Database.GetItem(new ID((string)dr["_ItemId"]));

                var fieldID = string.Empty;
                if (Sitecore.Data.ID.IsID(fieldidentifier))
                    fieldID = fieldidentifier;
                else if (dr.Table.Columns.Contains(fieldidentifier))
                    fieldID = (string)dr.Table.Columns[fieldidentifier].ExtendedProperties["_FieldKey"];
                else
                {
                    Log.Info(string.Format("ItemDataset does not contain the field. [ds:{0}][field:{1}]", this.InnerItem.Paths.Path, fieldidentifier), this);
                    return string.Empty;
                }

                if (item[fieldID].IsNullOrEmpty())
                    result = item.RenderField(fieldID, parameters);
                else
                {
                    FieldRenderer fr = new FieldRenderer();
                    fr.Before = before;
                    fr.After = after;
                    fr.Parameters = parameters;
                    fr.FieldName = fieldID;
                    fr.Item = item;
                    result = fr.Render();
                }
            }
            else
            {
                result = dr[fieldidentifier].ToString();
            }

            return result;
        }
        void rptSlides_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.IsItem())
            {
                TextTipPageItem dataItem       = e.Item.DataItem as TextTipPageItem;
                Panel           pnlSlide       = e.FindControlAs <Panel>("pnlSlide");
                Literal         ltlSlideNumber = e.FindControlAs <Literal>("ltlSlideNumber");
                Literal         ltlSlideCount  = e.FindControlAs <Literal>("ltlSlideCount");
                Label           lblCircle      = e.FindControlAs <Label>("lblCircle");
                FieldRenderer   frTipTitle     = e.FindControlAs <FieldRenderer>("frTipTitle");
                FieldRenderer   frTipText      = e.FindControlAs <FieldRenderer>("frTipText");

                ltlSlideNumber.Text = (e.Item.ItemIndex + 1).ToString();
                ltlSlideCount.Text  = count.ToString();
                frTipTitle.Item     = dataItem;
                frTipText.Item      = dataItem;

                if (dataItem.Backgroundcolor.Item != null)
                {
                    if (dataItem.Backgroundcolor.Item.IsOfType(MetadataItem.TemplateId))
                    {
                        MetadataItem color = dataItem.Backgroundcolor.Item;

                        if (!string.IsNullOrEmpty(color.ContentTitle.Raw))
                        {
                            pnlSlide.CssClass += " " + color.ContentTitle.Raw;
                        }
                    }
                }

                if (dataItem.Circlecolor.Item != null)
                {
                    if (dataItem.Circlecolor.Item.IsOfType(MetadataItem.TemplateId))
                    {
                        MetadataItem color = dataItem.Circlecolor.Item;

                        if (!string.IsNullOrEmpty(color.ContentTitle.Raw))
                        {
                            lblCircle.CssClass = color.ContentTitle.Raw;
                        }
                    }
                }
            }

            if (e.Item.ItemType == ListItemType.Footer)
            {
                var         parent  = DataSource.Parent;
                List <Item> parents = new List <Item>();

                while (parent != null)
                {
                    parents.Add(parent);
                    parent = parent.Parent;
                }


                Item subtopic = null;
                Item topic    = null;

                foreach (var p in parents)
                {
                    if (p.IsOfType(SubtopicLandingPageItem.TemplateId))
                    {
                        subtopic = p;
                    }
                    else if (p.IsOfType(TopicLandingPageItem.TemplateId))
                    {
                        topic = p;
                    }
                }

                var randomSlides = SearchHelper.GetLastSlide(DataSource.ID, subtopic, topic, TextOnlyTipsArticlePageItem.TemplateId);

                FieldRenderer frPageSummary1                    = e.FindControlAs <FieldRenderer>("frPageSummary1");
                FieldRenderer frPageSummary2                    = e.FindControlAs <FieldRenderer>("frPageSummary2");
                HyperLink     hypLink1                          = e.FindControlAs <HyperLink>("hypLink1");
                HyperLink     hypLink2                          = e.FindControlAs <HyperLink>("hypLink2");
                Literal       ltlSlideshowRestartLabel          = e.FindControlAs <Literal>("ltlSlideshowRestartLabel");
                Literal       ltlSlideshowRestartAlternateLabel = e.FindControlAs <Literal>("ltlSlideshowRestartAlternateLabel");

                if (randomSlides.Count >= 2)
                {
                    var slide = randomSlides[1];
                    if (slide != null)
                    {
                        hypLink2.NavigateUrl = slide.GetUrl();
                        hypLink2.Text        = slide.Name;
                        frPageSummary2.Item  = slide;
                        Panel  pnlThumbnail2 = e.FindControlAs <Panel>("pnlThumbnail2");
                        string url           = slide.GetArticleThumbnailUrl(380, 220);
                        string style         = string.Format("background-image: url('{0}')", url);
                        pnlThumbnail2.Attributes.Add("style", style);
                        e.FindControlAs <System.Web.UI.WebControls.PlaceHolder>("phSlideshow2").Visible = true;
                    }
                }

                if (randomSlides.Count >= 1)
                {
                    var slide = randomSlides[0];
                    if (slide != null)
                    {
                        hypLink1.NavigateUrl = slide.GetUrl();
                        hypLink1.Text        = slide.Name;
                        frPageSummary1.Item  = slide;
                        Panel  pnlThumbnail1 = e.FindControlAs <Panel>("pnlThumbnail1");
                        string url           = slide.GetArticleThumbnailUrl(380, 220);
                        string style         = string.Format("background-image: url('{0}')", url);
                        pnlThumbnail1.Attributes.Add("style", style);
                        e.FindControlAs <System.Web.UI.WebControls.PlaceHolder>("phSlideshow1").Visible = true;
                    }
                }

                ltlSlideshowRestartLabel.Text = DictionaryConstants.TextTipsRestartLabel;
                //ltlSlideshowRestartAlternateLabel.Text = DictionaryConstants.SlideshowRestartAlternateLabel;
            }
        }
        /// <summary>
        /// The render.
        /// </summary>
        /// <param name="field">
        /// The field.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="enclosingTag">
        /// The enclosing tag.
        /// </param>
        /// <param name="before">
        /// The before.
        /// </param>
        /// <param name="after">
        /// The after.
        /// </param>
        /// <param name="disableWebEdit">
        /// The disable web edit.
        /// </param>
        /// <returns>
        /// The <see cref="HtmlString"/>.
        /// </returns>
        public static HtmlString Render(
            this CustomField field, 
            string parameters, 
            string enclosingTag, 
            string before, 
            string after, 
            bool disableWebEdit = false)
        {
            if (field == null || field.InnerField == null || field.InnerField.Item == null)
            {
                return new HtmlString(string.Empty);
            }

            var renderer = new FieldRenderer()
                               {
                                   Item = field.InnerField.Item, 
                                   FieldName = field.InnerField.Name, 
                                   Parameters = parameters, 
                                   EnclosingTag = enclosingTag, 
                                   Before = before, 
                                   After = after, 
                                   DisableWebEditing = disableWebEdit
                               };

            return new HtmlString(renderer.Render());
        }
Exemplo n.º 7
0
 public string Render(string fieldname)
 {
     return(FieldRenderer.Render(_item, fieldname));
 }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="output"></param>
        protected override void DoRender(HtmlTextWriter output)
        {
            Item galleryItem = GetSingleSlide(this.GetItem());

            output.AddAttribute(HtmlTextWriterAttribute.Class, headerImageClass);
            output.RenderBeginTag(HtmlTextWriterTag.Div);

            if (galleryItem != null)
            {
                /* The banner can take a single gallery item, or an entire gallery - in which case it will pick a random slide. */

                // Example banner HTML:
                //
                // <div class="headerImage">
                //      <div>
                //        <img src="/~/media/BaseCore/Galleries/slide-forset.ashx?mw=960" alt="Forest cycling" width="960" height="400">
                //        <div class="slideContent">
                //            <span class="heading">Go abroad with your bike</span>
                //            <p>Challenge yourself by planning your next trip abroad.</p>
                //            <p><a href="/holidays/cycle-south-east-asia.aspx">Cycle South-East Asia</a></p>
                //        </div>
                //      </div>
                // </div>

                // <div class="headerImage">


                if (Heading != null)
                {
                    headingElement = FieldRenderer.Render(Heading, element);
                    headingClass   = FieldRenderer.Render(Heading, cssClass);
                }

                // <div>
                output.RenderBeginTag(HtmlTextWriterTag.Div);

                // <img src="/~/media/BaseCore/Galleries/slide-forset.ashx?mw=960" alt="Forest cycling" width="960" height="400">
                output.Write(FieldRenderer.Render(galleryItem, galleryItemImage, maxWidth));

                // <div class="slideContent">
                output.AddAttribute(HtmlTextWriterAttribute.Class, slideContent);
                output.RenderBeginTag(HtmlTextWriterTag.Div);

                // <h2 class="heading">
                output.AddAttribute(HtmlTextWriterAttribute.Class, headingClass);
                output.RenderBeginTag(headingElement);

                output.Write(FieldRenderer.Render(galleryItem, galleryItemHeading));

                // </h2>
                output.RenderEndTag();

                // <p>
                output.RenderBeginTag(HtmlTextWriterTag.P);

                output.Write(FieldRenderer.Render(galleryItem, galleryItemText));

                // </p>
                output.RenderEndTag();

                string link = FieldRenderer.Render(galleryItem, galleryItemLink);

                if (!String.IsNullOrEmpty(link))
                {
                    // <p>
                    output.RenderBeginTag(HtmlTextWriterTag.P);

                    output.Write(FieldRenderer.Render(galleryItem, galleryItemLink));

                    // </p>
                    output.RenderEndTag();
                }

                // </div>
                output.RenderEndTag();

                // </div>
                output.RenderEndTag();
            }

            // </div>
            output.RenderEndTag();
        }
Exemplo n.º 9
0
 public static string RenderField(Item item, string fieldName)
 {
     return(FieldRenderer.Render(item, fieldName));
 }
Exemplo n.º 10
0
        private string MakeEditable <T>(Expression <Func <T, object> > field, Expression <Func <T, string> > standardOutput, T target, Database database, string parameters)
        {
            if (standardOutput == null || IsInEditingMode)
            {
                if (field.Parameters.Count > 1)
                {
                    throw new MapperException("To many parameters in linq expression {0}".Formatted(field.Body));
                }



                MemberExpression memberExpression;

                if (field.Body is UnaryExpression)
                {
                    memberExpression = ((UnaryExpression)field.Body).Operand as MemberExpression;
                }
                else if (!(field.Body is MemberExpression))
                {
                    throw new MapperException("Expression doesn't evaluate to a member {0}".Formatted(field.Body));
                }
                else
                {
                    memberExpression = (MemberExpression)field.Body;
                }



                //we have to deconstruct the lambda expression to find the
                //correct target object
                //For example if we have the lambda expression x =>x.Children.First().Content
                //we have to evaluate what the first Child object is, then evaluate the field to edit from there.

                //this contains the expression that will evaluate to the object containing the property
                var objectExpression = memberExpression.Expression;

                var finalTarget = Expression.Lambda(objectExpression, field.Parameters.ToArray()).Compile().DynamicInvoke(target);

                var site = global::Sitecore.Context.Site;


                InstanceContext context = Context.GetContext();


                //if the class a proxy then we have to get it's base type
                Type type;
                if (finalTarget is IProxyTargetAccessor)
                {
                    //first try the base type
                    type = finalTarget.GetType().BaseType;

                    //if it doesn't contain the base type then we need to check the interfaces
                    if (!context.Classes.ContainsKey(type))
                    {
                        var interfaces = finalTarget.GetType().GetInterfaces();

                        string name = finalTarget.GetType().Name;
                        //be default castle will use the name of the class it is proxying for it's own name
                        foreach (var inter in interfaces)
                        {
                            if (name.StartsWith(inter.Name))
                            {
                                type = inter;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    type = finalTarget.GetType();
                }


                Guid id = Guid.Empty;

                try
                {
                    id = context.GetClassId(type, finalTarget);
                }
                catch (SitecoreIdException ex)
                {
                    throw new MapperException("Page editting error. Type {0} can not be used for editing. Could not find property with SitecoreID attribute. See inner exception".Formatted(typeof(T).FullName), ex);
                }

                var scClass = context.GetSitecoreClass(type);

                //lambda expression does not always return expected memberinfo when inheriting
                //c.f. http://stackoverflow.com/questions/6658669/lambda-expression-not-returning-expected-memberinfo
                var prop = type.GetProperty(memberExpression.Member.Name);

                //interfaces don't deal with inherited properties well
                if (prop == null && type.IsInterface)
                {
                    Func <Type, PropertyInfo> interfaceCheck = null;
                    interfaceCheck = (inter) =>
                    {
                        var interfaces = inter.GetInterfaces();
                        var properties =
                            interfaces.Select(x => x.GetProperty(memberExpression.Member.Name)).Where(
                                x => x != null);
                        if (properties.Any())
                        {
                            return(properties.First());
                        }
                        else
                        {
                            return(interfaces.Select(x => interfaceCheck(x)).FirstOrDefault(x => x != null));
                        }
                    };
                    prop = interfaceCheck(type);
                }

                if (prop != null && prop.DeclaringType != prop.ReflectedType)
                {
                    //properties mapped in data handlers are based on declaring type when field is inherited, make sure we match
                    prop = prop.DeclaringType.GetProperty(prop.Name);
                }

                if (prop == null)
                {
                    throw new MapperException("Page editting error. Could not find property {0} on type {1}".Formatted(memberExpression.Member.Name, type.FullName));
                }

                //ME - changed this to work by name because properties on interfaces do not show up as declared types.
                var dataHandler = scClass.DataHandlers.FirstOrDefault(x => x.Property.Name == prop.Name);
                if (dataHandler == null)
                {
                    throw new MapperException(
                              "Page editting error. Could not find data handler for property {2} {0}.{1}".Formatted(
                                  prop.DeclaringType, prop.Name, prop.MemberType));
                }

                var item = database.GetItem(new ID(id));

                using (new ContextItemSwitcher(item))
                {
                    FieldRenderer renderer = new FieldRenderer();
                    renderer.Item       = item;
                    renderer.FieldName  = ((AbstractSitecoreField)dataHandler).FieldName;
                    renderer.Parameters = parameters;
                    return(renderer.Render());
                }
            }
            else
            {
                return(standardOutput.Compile().Invoke(target));
            }
            //return field.Compile().Invoke(target).ToString();
        }
        protected void rptPageQuestions_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.IsItem())
            {
                FieldRenderer   frQuestionTitle     = e.FindControlAs <FieldRenderer>("frQuestionTitle");
                Panel           pnlQuestion         = e.FindControlAs <Panel>("pnlQuestion");
                Panel           pnlTrueFalse        = e.FindControlAs <Panel>("pnlTrueFalse");
                Panel           pnlRadioQuestion    = e.FindControlAs <Panel>("pnlRadioQuestion");
                Panel           pnlDropDown         = e.FindControlAs <Panel>("pnlDropDown");
                HtmlButton      btnTrue             = e.FindControlAs <HtmlButton>("btnTrue");
                HtmlButton      btnFalse            = e.FindControlAs <HtmlButton>("btnFalse");
                DropDownList    ddlQuestion         = e.FindControlAs <DropDownList>("ddlQuestion");
                RadioButtonList rblAnswer           = e.FindControlAs <RadioButtonList>("rblAnswer");
                RadioButtonList rblHiddenButtonList = e.FindControlAs <RadioButtonList>("rblHiddenButtonList");

                foreach (ListItem l in rblHiddenButtonList.Items)
                {
                    l.Attributes.Add("hidden", "");
                }

                Dictionary <string, QuestionAnswer> AnswerTracker = new Dictionary <string, QuestionAnswer>();

                if (Session["AnsweredQuestions"] != null)
                {
                    AnswerTracker = (Dictionary <string, QuestionAnswer>)Session["AnsweredQuestions"];
                }

                Item question = (Item)e.Item.DataItem;

                bool alreadyAnswered = AnswerTracker.ContainsKey(question.ID.ToString()) && AnswerTracker[question.ID.ToString()].Answer != "";

                if (frQuestionTitle != null)
                {
                    frQuestionTitle.Item = question;
                }

                if (question.IsOfType(AssessmentTrueFalseItem.TemplateId))
                {
                    btnTrue.Attributes.Add("data-id", question.ID.ToString());
                    btnFalse.Attributes.Add("data-id", question.ID.ToString());

                    if (alreadyAnswered)
                    {
                        string selected     = "button answer-choice-true rs_skip selected";
                        string not_selected = "button gray answer-choice-false rs_skip disabled";

                        if (AnswerTracker[question.ID.ToString()].Answer == "True")
                        {
                            rblHiddenButtonList.Items.FindByText("True").Selected = true;
                            btnTrue.Attributes.Add("class", selected);
                            btnFalse.Attributes.Add("class", not_selected);
                        }
                        else
                        {
                            rblHiddenButtonList.Items.FindByText("False").Selected = true;
                            btnTrue.Attributes.Add("class", not_selected);
                            btnFalse.Attributes.Add("class", selected);
                        }
                    }
                    pnlTrueFalse.Visible = true;
                }
                else if (question.IsOfType(AssessmentMultipleChoiceItem.TemplateId))
                {
                    AssessmentMultipleChoiceItem Question = (AssessmentMultipleChoiceItem)question;
                    if (Question.IsDropDownList.Checked)
                    {
                        ddlQuestion.Attributes.Add("data-id", question.ID.ToString());
                        ddlQuestion.Items.Add(new ListItem(Question.DropDownDefaultText));

                        foreach (Item i in Question.InnerItem.Children)
                        {
                            ddlQuestion.Items.Add(new ListItem(i.Fields["Answer"].ToString()));
                        }

                        if (alreadyAnswered)
                        {
                            ddlQuestion.Items.FindByText(AnswerTracker[question.ID.ToString()].Answer).Selected = true;
                        }

                        ddlQuestion.Items.FindByText(Question.DropDownDefaultText).Value = "";

                        pnlDropDown.Visible = true;
                    }
                    else
                    {
                        rblAnswer.Attributes.Add("data-id", question.ID.ToString());

                        foreach (Item i in Question.InnerItem.Children)
                        {
                            rblAnswer.Items.Add(new ListItem(i.Fields["Answer"].ToString()));
                        }

                        if (alreadyAnswered)
                        {
                            rblAnswer.Items.FindByText(AnswerTracker[question.ID.ToString()].Answer).Selected = true;
                        }

                        pnlRadioQuestion.Visible = true;
                    }
                }
            }
        }
 public HtmlString GetField(Item item, string fieldName, string parm = null)
 {
     return(new HtmlString(FieldRenderer.Render(item, fieldName, parm)));
 }
Exemplo n.º 13
0
 public ApplicationSection(string id, string applicationName,
                           bool @abstract, string label, string attribute, string resourcepath,
                           string parameters, List <IApplicationDisplayable> displayables, string showExpression,
                           string toolTip, string orientation, ApplicationHeader header, FieldRenderer renderer)
 {
     Id = id;
     ApplicationName   = applicationName;
     Abstract          = @abstract;
     Resourcepath      = resourcepath;
     _parametersString = parameters;
     Parameters        = PropertyUtil.ConvertToDictionary(parameters);
     _displayables     = displayables;
     Label             = label;
     Attribute         = attribute;
     ShowExpression    = showExpression;
     ToolTip           = toolTip;
     ValidateOrientation(orientation);
     Header    = header;
     _renderer = renderer;
 }
Exemplo n.º 14
0
        private string MakeEditable <T>(Expression <Func <T, object> > field, Expression <Func <T, string> > standardOutput, T target, Database database)
        {
            try
            {
                if (this.IsInEditingMode)
                {
                    if (field.Parameters.Count > 1)
                    {
                        throw new MapperException("To many parameters in linq expression {0}".Formatted(field.Body));
                    }

                    var  site = global::Sitecore.Context.Site;
                    Type type = typeof(T);

                    InstanceContext context = Context.GetContext();

                    Guid id = Guid.Empty;

                    try
                    {
                        id = context.GetClassId(type, target);
                    }
                    catch (SitecoreIdException ex)
                    {
                        throw new MapperException("Page editting error. Type {0} can not be used for editing. See inner exception".Formatted(typeof(T).FullName), ex);
                    }

                    var scClass = context.GetSitecoreClass(typeof(T));

                    var prop = Utility.GetPropertyInfo(type, field.Body);

                    if (prop == null)
                    {
                        throw new MapperException("Page editting error. Could not find property {0} on type {1}".Formatted(field.Body, type.FullName));
                    }

                    var dataHandler = scClass.DataHandlers.FirstOrDefault(x => x.Property == prop);

                    var item = database.GetItem(new ID(id));

                    using (new ContextItemSwitcher(item))
                    {
                        FieldRenderer renderer = new FieldRenderer();
                        renderer.Item       = item;
                        renderer.FieldName  = ((AbstractSitecoreField)dataHandler).FieldName;
                        renderer.Parameters = "";
                        return(renderer.Render());
                    }
                }
                else
                {
                    if (standardOutput != null)
                    {
                        return(standardOutput.Compile().Invoke(target));
                    }
                    else
                    {
                        return(field.Compile().Invoke(target).ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                return("The following exception occured: {0} \n\r {1}".Formatted(ex.Message, ex.StackTrace));
            }
        }
Exemplo n.º 15
0
    /// <summary>
    /// Gets the FLD from database.
    /// </summary>
    /// <param name="fieldName">Name of the field.</param>
    /// <param name="databaseName">Name of the database.</param>
    /// <param name="iterator">The iterator.</param>
    /// <returns></returns>
    public string GetFldFromDatabase(string fieldName, string databaseName, XPathNodeIterator iterator)
    {
      ID id;
      if (!iterator.MoveNext())
      {
        return null;
      }

      if (!ID.TryParse(iterator.Current.GetAttribute("id", string.Empty), out id))
      {
        return null;
      }

      Database database = Factory.GetDatabase(databaseName);
      if (database == null)
      {
        return null;
      }

      Item itm = ItemManager.GetItem(id, Language.Current, Sitecore.Data.Version.Latest, database);

      var renderer = new FieldRenderer
      {
        Item = itm,
        FieldName = fieldName
      };
      return renderer.Render();
    }
 public string DataItems(Item item2, string fieldName)
 {
     return(FieldRenderer.Render(item2, fieldName));
 }
 public string Render <TProperty>(Expression <Func <TDomainEntity, TProperty> > expression)
 {
     return(FieldRenderer.Render(GetItem(), GetFieldName(expression)));
 }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="output"></param>
        protected override void DoRender(HtmlTextWriter output)
        {
            string uniqueID = slides + "-" + this.ClientID;

            Item datasource = this.GetItem();

            // <div id="slides">
            output.AddAttribute(HtmlTextWriterAttribute.Id, uniqueID);
            output.AddAttribute(HtmlTextWriterAttribute.Class, "slides");
            output.RenderBeginTag(HtmlTextWriterTag.Div);

            if (datasource != null)
            {
                if (datasource.TemplateID == TemplateReferences.Gallery)
                {
                    // Example gallery HTML:
                    //
                    // <div id="slides">
                    //  <div class="slides_container">
                    //      <div>
                    //          <img src="/~/media/BaseCore/Galleries/slide-canyon.ashx?mw=960" alt="Canyon cycling" width="960" height="400" />
                    //          <div class="slideContent">
                    //              <span class="heading">Active family holidays in Wales</span><p>Whisk the family away to an active weekend in the Welsh mountains.</p>
                    //          </div>
                    //      </div>
                    //      <div>
                    //          <img src="/~/media/BaseCore/Galleries/slide-forset.ashx?mw=960" alt="Forest cycling" width="960" height="400" /><div class="slideContent">
                    //          <span class="heading">Go abroad with your bike</span>
                    //          <p>Challenge yourself by planning your next trip abroad.</p>
                    //          <p><a href="/holidays/cycle-south-east-asia.aspx">Cycle South-East Asia</a></p>
                    //      </div>
                    //  </div>
                    //  <div>
                    //      <img src="/~/media/BaseCore/Galleries/slide-bike.ashx?mw=960" alt="Red bike" width="960" height="400" /><div class="slideContent">
                    //      <span class="heading">Try a new bike</span><p>Try a bike you  might not have chosen for yourself.</p><p><a href="/bikes/the-allrounder.aspx">Welsh mountain biking adventure</a></p>
                    //  </div>
                    // </div>

                    // <div class="slides_container">
                    output.AddAttribute(HtmlTextWriterAttribute.Class, slidesContainer);
                    output.RenderBeginTag(HtmlTextWriterTag.Div);

                    if (Heading != null)
                    {
                        headingElement = FieldRenderer.Render(Heading, element);
                        headingClass   = FieldRenderer.Render(Heading, cssClass);
                    }

                    foreach (Item galleryItem in datasource.Children.Where(x => x.TemplateID == TemplateReferences.GalleryItem && x.Versions.Count > 0))
                    {
                        // <div>
                        output.RenderBeginTag(HtmlTextWriterTag.Div);
                        output.Write(FieldRenderer.Render(galleryItem, galleryItemImage, maxWidth));

                        // <div class="slideContent">
                        output.AddAttribute(HtmlTextWriterAttribute.Class, slideContent);
                        output.RenderBeginTag(HtmlTextWriterTag.Div);

                        // <h2 class="headingClass">
                        output.AddAttribute(HtmlTextWriterAttribute.Class, headingClass);
                        output.RenderBeginTag(headingElement);

                        // Heading text
                        output.Write(FieldRenderer.Render(galleryItem, galleryItemHeading));

                        // </h2>
                        output.RenderEndTag();

                        // <p>
                        output.RenderBeginTag(HtmlTextWriterTag.P);
                        output.Write(FieldRenderer.Render(galleryItem, galleryItemText));

                        //</p>
                        output.RenderEndTag();

                        string link = FieldRenderer.Render(galleryItem, galleryItemLink);

                        if (!String.IsNullOrEmpty(link))
                        {
                            // <p>
                            output.RenderBeginTag(HtmlTextWriterTag.P);
                            output.Write(FieldRenderer.Render(galleryItem, galleryItemLink));

                            // </p>
                            output.RenderEndTag();
                        }

                        // </div>
                        output.RenderEndTag();

                        // </div>
                        output.RenderEndTag();
                    }

                    // </div>
                    output.RenderEndTag();
                }
            }

            // </div>
            output.RenderEndTag();
        }
Exemplo n.º 19
0
      private static string RenderTags(ClientPipelineArgs args) 
      {
        Assert.ArgumentNotNull(args, "args");
        string result = args.Result;
        string str3 = args.Parameters["itemid"];
        string name = args.Parameters["language"];
        string str5 = args.Parameters["version"];
        string str6 = args.Parameters["fieldid"];
        string currentValue = "|" + args.Parameters["currentValue"] + "|";

        Item item = Context.ContentDatabase.GetItem(ID.Parse(str3), Language.Parse(name), Sitecore.Data.Version.Parse(str5));
        if (item == null)
        {
          SheerResponse.Alert("The item was not found.\n\nIt may have been deleted by another user.", new string[0]);
          return null;
        }
        Field field = item.Fields[ID.Parse(str6)];
        if (field == null)
        {
          SheerResponse.Alert("The field was not found.\n\nIt may have been deleted by another user.", new string[0]);
          return null;
        }

        string newTag = string.Format("{0}:{1}", result, "{C1453A1D-9ED2-428A-8BB3-50B4A877BEA7}");
        if (args.Parameters["mode"] == "check")
        {
          string tagNotFound = string.Format("|{0}:{1}|", ID.Null, args.Parameters["tagNotFound"]);
          currentValue = args.HasResult && args.Result != "undefined" ? currentValue.Replace(tagNotFound, "|" + newTag + "|") : currentValue.Replace(tagNotFound, "|");
        }
        else
        {
          currentValue += string.Format("{0}|", newTag);
        }

        currentValue = currentValue.Trim("|".ToCharArray());
        args.Parameters["currentValue"] = currentValue;

        FieldRenderer renderer = new FieldRenderer();
        renderer.Item = item;
        renderer.FieldName = field.Name;
        renderer.OverrideFieldValue(currentValue);
        renderer.DisableWebEditing = false;
        return renderer.Render();         
      }
Exemplo n.º 20
0
 public string Render(string fieldname, string parameters)
 {
     return(FieldRenderer.Render(_item, fieldname, parameters));
 }
Exemplo n.º 21
0
 // Use this for initialization
 void Start()
 {
     render = new FieldRenderer(30, 30);
 }
Exemplo n.º 22
0
        /// <inheritdoc />
        public virtual FieldMapStatus Map(object modelInstance, Field field)
        {
            Model = modelInstance;
            Field = field;

            if (Property == null)
            {
                return(FieldMapStatus.NoProperty);
            }

            if (Property.GetCustomAttribute <DoNotMapAttribute>() != null)
            {
                return(FieldMapStatus.ExplicitIgnore);
            }

            if (Property.GetCustomAttribute <RawValueOnlyAttribute>() != null)
            {
                if (Property.IsHtml())
                {
                    Property.SetValue(Model, new HtmlString(Field.Value));
                    return(FieldMapStatus.Success);
                }

                Property.SetValue(Model, Field.Value);
                return(FieldMapStatus.Success);
            }

            var paramsAttribute = Property.GetCustomAttribute <FieldRendererParamsAttribute>();

            if (paramsAttribute != null)
            {
                if (Property.IsHtml())
                {
                    Property.SetValue(Model, new HtmlString(FieldRenderer.Render(Field.Item, Field.Name, paramsAttribute.Params)));
                    return(FieldMapStatus.Success);
                }

                Property.SetValue(Model, FieldRenderer.Render(Field.Item, Field.Name, paramsAttribute.Params));
                return(FieldMapStatus.Success);
            }

            // Place to handle more complex scenarios.
            try
            {
                if (Property.IsHtml())
                {
                    Property.SetValue(Model, new HtmlString(ExtractStringValueFromField()));
                    return(FieldMapStatus.Success);
                }

                if (Property.IsString())
                {
                    Property.SetValue(Model, ExtractStringValueFromField());
                    return(FieldMapStatus.Success);
                }

                return(FieldMapStatus.TypeMismatch);
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to map Field {Field.Name} of Item {Field.Item.Name}", ex, this);
                return(FieldMapStatus.Exception);
            }
        }
        public IEnterspeedProperty Convert(Item item, Field field, EnterspeedSiteInfo siteInfo, List <IEnterspeedFieldValueConverter> fieldValueConverters)
        {
            string value = FieldRenderer.Render(item, field.Name);

            return(new StringEnterspeedProperty(_fieldService.GetFieldName(field), value));
        }
Exemplo n.º 24
-1
 /// <summary>
 /// Gets the content of the field.
 /// </summary>
 /// <param name="editable">if set to <c>true</c> [editable].</param>
 /// <returns>System.String.</returns>
 private string GetFieldContent(bool editable = true)
 {
     FieldRenderer render = new FieldRenderer();
     render.FieldName = _fieldName;
     render.Item = _item;
     render.DisableWebEditing = !editable;
     return render.Render();
 }
Exemplo n.º 25
-1
        protected override void GetSummary(GetSummaryArgs args)
        {
            var renderer = new FieldRenderer();
            renderer.Item = args.Entry;
            renderer.FieldName = FieldName;

            args.Summary = renderer.Render();
        }
        public static string GetString(Item item, string fieldName, bool ignoreCase)
        {
            var field = item.Fields[fieldName];

            if (field == null) return string.Empty;

            FieldRenderer render = new FieldRenderer();
            render.Item = item;
            render.FieldName = field.Name;
            render.DisableWebEditing = !EditMode.UseEditMode;
            return render.Render();
        }
 public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
 {
     if (item.Fields[FieldName] != null && item.Fields[FieldName].Type.StartsWith("Rich Text") && Setting != SitecoreFieldSettings.RichTextRaw)
     {
         FieldRenderer renderer = new FieldRenderer();
         renderer.Item = item;
         renderer.FieldName = FieldName;
         renderer.Parameters = string.Empty;
         return renderer.Render();
     }
     else return item[FieldName];
 }
        public override object GetValue(global::Sitecore.Data.Items.Item item, ISitecoreService service)
        {
            var field = base.GetField(item);

            if (field == null)
                return string.Empty;

            if (field.Type.StartsWith("Rich Text") && Setting != SitecoreFieldSettings.RichTextRaw)
            {
                FieldRenderer renderer = new FieldRenderer();
                renderer.Item = item;
                renderer.FieldName = field.Name;
                renderer.Parameters = string.Empty;
                return renderer.Render();
            }
            else return field.Value ;
        }
        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            if (field == null)
                return string.Empty;

            if (config.Setting == SitecoreFieldSettings.RichTextRaw)
                return field.Value;

            if (field.Type.StartsWith("Rich Text"))
            {
                FieldRenderer renderer = new FieldRenderer();
                renderer.Item = field.Item;
                renderer.FieldName = field.Name;
                renderer.Parameters = string.Empty;
                return renderer.Render();
            }
            else return field.Value;
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            string name = binder.Name;


            if (_item.Fields[name] != null)
            {
                FieldRenderer render = new FieldRenderer();
                render.FieldName = name;
                render.Item = _item;

                result = render.Render();
                return true;
            }

            SitecoreInfoType infoType;

            if (Enum.TryParse<SitecoreInfoType>(name, out infoType))
            {
                result = SitecoreInfoHandler.GetItemInfo(infoType, _item, null);
                return true;
            }


            switch (name)
            {
                case "Parent":
                    result = new DynamicItem(_item.Parent);
                    break;
                case "Children":
                    result = new DynamicCollection<DynamicItem>(_item.Children.Select(x => new DynamicItem(x)).ToArray());
                    break;
            }
            if (result != null) return true;
            
            throw new NotSupportedException("No field of Sitecore info matches the name {0} for item {1}".Formatted(name, _item.Paths.FullPath));

        }