public void Copy_OnlyCopiesGraphProperties()
        {
            //Arrange

            var options = new GetOptionsSc();

            options.TemplateId      = ID.NewID;
            options.EnforceTemplate = SitecoreEnforceTemplate.TemplateAndBase;
            options.VersionCount    = true;

            options.Cache     = Cache.Disabled;
            options.Type      = this.GetType();
            options.Lazy      = LazyLoading.Enabled;
            options.InferType = true;

            var copy = new GetOptionsSc();

            //Act
            copy.Copy(options);

            //Assert
            Assert.AreEqual(options.VersionCount, copy.VersionCount);
            Assert.AreEqual(options.InferType, copy.InferType);
            Assert.AreEqual(options.Lazy, copy.Lazy);
            Assert.AreEqual(options.Type, copy.Type);
            Assert.AreEqual(options.Cache, copy.Cache);

            Assert.AreNotEqual(options.TemplateId, copy.TemplateId);
            Assert.IsNull(copy.TemplateId);

            Assert.AreEqual(SitecoreEnforceTemplate.Default, copy.EnforceTemplate);
        }
Example #2
0
        protected virtual string RunPipeline(Field field, GetOptionsSc options)
        {
            RenderFieldArgs renderFieldArgs = new RenderFieldArgs
            {
                Item           = field.Item,
                FieldName      = field.ID.ToString(),
                DisableWebEdit = true,
            };

            try
            {
                if (options.Site != null)
                {
                    using (new SiteContextSwitcher(options.Site))
                    {
                        CorePipeline.Run("renderField", renderFieldArgs);
                    }
                }
                else
                {
                    CorePipeline.Run("renderField", renderFieldArgs);
                }
            }
            catch (Exception ex)
            {
                throw new MapperException("Failed to render field {0} on item {1}".Formatted(field.ID, field.Item.ID), ex);
            }

            return(renderFieldArgs.Result.FirstPart + renderFieldArgs.Result.LastPart);
        }
        protected virtual string GetResult(Field field, bool isRichText, GetOptionsSc getOptions)
        {
            if (!isRichText)
            {
                return(field.Value);
            }

            return(RunPipeline(field, getOptions));
        }
 public override UrlOptions CreateUrlOptions(SitecoreInfoUrlOptions urlOptions, GetOptionsSc options)
 {
     return(base.CreateUrlOptions(urlOptions, new UrlOptions(), options));
 }
Example #5
0
        protected void MapToLinkModel(Link link, LinkField linkField, SitecoreFieldConfiguration config, GetOptionsSc getOptions)
        {
            link.Anchor = linkField.Anchor;
            link.Class  = linkField.Class;
            link.Style  = linkField.GetAttribute("style");
            link.Text   = linkField.Text;
            link.Title  = linkField.Title;
            link.Target = linkField.Target;
            link.Query  = HttpUtility.UrlDecode(linkField.QueryString);

            switch (linkField.LinkType)
            {
            case "anchor":
                link.Url  = linkField.Anchor;
                link.Type = LinkType.Anchor;
                break;

            case "external":
                link.Url  = linkField.Url;
                link.Type = LinkType.External;
                break;

            case "mailto":
                link.Url  = linkField.Url;
                link.Type = LinkType.MailTo;
                break;

            case "javascript":
                link.Url  = linkField.Url;
                link.Type = LinkType.JavaScript;
                break;

            case "media":
                if (linkField.TargetItem == null)
                {
                    link.Url = string.Empty;
                }
                else
                {
                    global::Sitecore.Data.Items.MediaItem media =
                        new global::Sitecore.Data.Items.MediaItem(linkField.TargetItem);
                    link.Url = SitecoreVersionAbstractions.GetMediaUrl(media);
                }
                link.Type     = LinkType.Media;
                link.TargetId = linkField.TargetID.Guid;
                break;

            case "internal":
                var urlOptions = _urlOptionsResolver.CreateUrlOptions(config.UrlOptions, getOptions);
                link.Url      = linkField.TargetItem == null ? string.Empty : SitecoreVersionAbstractions.GetItemUrl(linkField.TargetItem, urlOptions);
                link.Type     = LinkType.Internal;
                link.TargetId = linkField.TargetID.Guid;
                link.Text     = linkField.Text.IsNullOrEmpty() ? (linkField.TargetItem == null ? string.Empty : linkField.TargetItem.DisplayName) : linkField.Text;
                break;

            default:
                link = null;
                break;
            }
        }
Example #6
0
        protected void MapToLinkModel(Link link, InternalLinkField field, SitecoreFieldConfiguration config, GetOptionsSc getOptions)
        {
            var urlOptions = _urlOptionsResolver.CreateUrlOptions(config.UrlOptions, getOptions);

            link.Url      = field.TargetItem == null ? string.Empty : SitecoreVersionAbstractions.GetItemUrl(field.TargetItem, urlOptions);
            link.Type     = LinkType.Internal;
            link.TargetId = field.TargetItem == null ? Guid.Empty : field.TargetItem.ID.Guid;
            link.Text     = field.TargetItem == null ? string.Empty : field.TargetItem.DisplayName;
        }