Example #1
0
        private List <MultipleJsonImage> ConvertImagesToList(string serializedString)
        {
            var images = new List <MultipleJsonImage>();

            if (!string.IsNullOrEmpty(serializedString))
            {
                images = JsonConvert.DeserializeObject <List <MultipleJsonImage> >(serializedString);
            }

            var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>();

            foreach (var item in images)
            {
                try
                {
                    var guid       = PermanentLinkUtility.GetGuid(item.PermanentUrl);
                    var contentRef = PermanentLinkUtility.FindContentReference(guid);
                    var image      = contentLoader.Get <ImageFile>(contentRef);

                    item.ContentLink = contentRef;
                    item.Image       = image;
                }
                catch (Exception e)
                {
                    //TODO: log exception...
                }
            }
            return(images);
        }
Example #2
0
        public static ContentReference GetContentReference(this LinkItem linkItem)
        {
            string extension;
            var    guid = PermanentLinkUtility.GetGuid(new UrlBuilder(linkItem.GetMappedHref()), out extension);

            return(PermanentLinkUtility.FindContentReference(guid));
        }
Example #3
0
        private void ModifyIContentProperties(LinkItem serverModel, ExtendedEPiLinkModel clientModel)
        {
            var mappedHref = serverModel.GetMappedHref();

            if (string.IsNullOrEmpty(mappedHref))
            {
                return;
            }
            var hrefWithoutHash = mappedHref;
            var anchorOnPage    = "";
            var indexOfHash     = mappedHref.IndexOf('#');

            if (indexOfHash > 0)
            {
                hrefWithoutHash = mappedHref.Substring(0, indexOfHash - 1);
                anchorOnPage    = mappedHref.Substring(indexOfHash + 1);
            }

            clientModel.Href         = hrefWithoutHash;
            clientModel.AnchorOnPage = anchorOnPage;
            var      contentGuid      = PermanentLinkUtility.GetGuid(hrefWithoutHash);
            var      contentReference = PermanentLinkUtility.FindContentReference(contentGuid);
            IContent content;

            if (!(contentReference != ContentReference.EmptyReference) || !_contentRepository.TryGet(contentReference, out content))
            {
                return;
            }
            clientModel.TypeIdentifier = _uiDescriptors.GetTypeIdentifiers(content.GetType()).FirstOrDefault();
            var friendlyUrl           = _urlHelper.ContentUrl(content.ContentLink);
            var absoluteUriBySettings = UriSupport.AbsoluteUrlBySettings(friendlyUrl);

            clientModel.PublicUrl = indexOfHash > 0 ?
                                    string.Format("{0}#{1}", absoluteUriBySettings, anchorOnPage) :
                                    absoluteUriBySettings;
        }