Deprecated/obsolete properties and methods in Episerver 11

Vote:
 

Hi!

Getting warnings as follow:

IContentExtensions.PublicUrl(IContent)' is obsolete: 'Will remain at least until jan 2017.

and 

'PermanentLinkMapStore' is obsolete: 'Use IPermanentLinkMapper instead'

and we cant find any solution to fix these warnings

Thanks in advance

/Fredrik and Mats

#218466
Mar 13, 2020 10:09
Vote:
 

Hi Fredrik,

What are you using the PermanentLinkMapStore for?

If you're not already, you should be using constructor injection, then it's a case of switching to using IUrlResolver and IPermanentLinkMapper. I don't know exactly what PermanentLinkMapStore method you're using, but I'd expect it to look something like this:

using EPiServer.Web;
using EPiServer.Web.Routing;

public class ExampleClass
{
   private IUrlResolver _urlResolver;
   private IPermanentLinkMapper _permanentLinkMapper;

   public ExampleClass(IUrlResolver urlResolver, IPermanentLinkMapper permanentLinkMapper)
   {
      _urlResolver = urlResolver;
      _permanentLinkMapper = permanentLinkMapper;
   }

   public void ExampleMethod(IContent content)
   {
      var url = _urlResolver.GetUrl(content.ContentLink);
      var permanentLinkMap = _permanentLinkMapper.Find(content.ContentLink);
   }
}

Let me know if you have questions.

#218488
Edited, Mar 13, 2020 14:28
Vote:
 

So this is the code I'm trying to get my head around regardaring PermanentLinkMapStore, 

and the warning I'm getting is: Warning CS0618: 'PermanentLinkMapStore' is obsolete: 'Use IPermanentLinkMapper instead'

    public static class LinkItemExtensions
    {
        public static IEnumerable<IContent> ContentData(this LinkItemCollection linkItemCollection)
        {
            var pages = new List<IContent>();
            if (linkItemCollection == null) return pages;
            var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
            foreach (var linkItem in linkItemCollection.Where(linkItem => !string.IsNullOrEmpty(linkItem.Href)))
            {
                string linkUrl;
                if (!PermanentLinkMapStore.TryToPermanent(linkItem.Href, out linkUrl)) continue;
                var urlBuilder = new UrlBuilder(linkUrl);
                var page = urlResolver.Route(urlBuilder) as PageData;

                if (page != null) pages.Add(page);
            }
            return pages;
        }

    }

#218629
Edited, Mar 17, 2020 12:41
Vote:
 

Hi again,

Fairly sure you can just dispense with using the PermanentLinkMapStore or IPermanentLinkMapper at all in this scenario.

I think the following should work:

public static IEnumerable<IContent> ContentData(this LinkItemCollection linkItemCollection)
{
    var pages = new List<IContent>();

    if (linkItemCollection == null)
    {
        return pages;
    }

    var urlResolver = ServiceLocator.Current.GetInstance<IUrlResolver>();

    foreach (var linkItem in linkItemCollection.Where(linkItem => !string.IsNullOrEmpty(linkItem.Href)))
    {
        var page = urlResolver.Route(new UrlBuilder(linkItem.Href)) as PageData;

        if (page != null)
        {
            pages.Add(page);
        }
    }

    return pages;
}
#218631
Mar 17, 2020 13:30
Vote:
 
                if (!PermanentLinkMapStore.TryToPermanent(linkItem.Href, out linkUrl)) continue;

you can use UrlResolver.TryToPermanent instead. Same parameters 

#218633
Mar 17, 2020 14:11
Vote:
 

Sorry for being a bit late and thanks both of you

I ended up like this, see below:

    public static class LinkItemExtensions
    {
        public static IEnumerable<IContent> ContentData(this LinkItemCollection linkItemCollection)
        {
            var pages = new List<IContent>();
            if (linkItemCollection == null) return pages;
            var urlResolver = ServiceLocator.Current.GetInstance<IUrlResolver>();

            foreach (var linkItem in linkItemCollection.Where(linkItem => !string.IsNullOrEmpty(linkItem.Href)))
            {
                string linkUrl;
                if (!urlResolver.TryToPermanent(linkItem.Href, out linkUrl)) continue;
                var page = urlResolver.Route(new UrlBuilder(linkUrl)) as PageData;
                if (page != null) pages.Add(page);
            }
            return pages;
        }
    }
#219140
Edited, Mar 30, 2020 7:52
Vote:
 

I would engourage you to create extension method on top of IUrlResolver interface instead. That way you are able to eliminate access to ServiceLocator. Collection of link items you can then pass in as parameter.

#219197
Mar 31, 2020 7:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.