Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Nov 10, 2014 @ 15:57
    Simon Dingley
    0

    Changes to PropertyEditorValueConverters in v6.2.4?

    I've just upgraded a site from v6.1.2 to v6.2.4 and all is working fine locally however on the remote server I am getting exceptions along the lines of the following for the MultiNodeTreePickerPropertyEditorValueConverter:

    Cannot implicitly convert type 'Umbraco.Core.Attempt<object>' to 'System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>'
    

    Here is the implementation of IPropertyEditorValueConverter:

    public class MultiNodeTreePickerPropertyEditorValueConverter : IPropertyEditorValueConverter
      {
        string _propertyTypeAlias = string.Empty;
        string _docTypeAlias = string.Empty;
    
        public bool IsConverterFor(Guid propertyEditorId, string docTypeAlias, string propertyTypeAlias)
        {
          _propertyTypeAlias = propertyTypeAlias;
          _docTypeAlias = docTypeAlias;
    
          return Guid.Parse("7e062c13-7c41-4ad9-b389-41d88aeef87c").Equals(propertyEditorId)
            || Guid.Parse("c2d6894b-e788-4425-bcf2-308568e3d38b").Equals(propertyEditorId);
        }
    
        public Attempt<object> ConvertPropertyValue(object value)
        {
          IEnumerable<IPublishedContent> multiNodeTreePicker = Enumerable.Empty<IPublishedContent>();
          if (UmbracoContext.Current != null)
          {
            int[] nodeIds = new int[0];
            if (XmlHelper.CouldItBeXml(value.ToString()))
            {
              nodeIds = uQuery.GetXmlIds(value.ToString());
            }
            else
            {
              nodeIds = value.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
            }
            var umbHelper = new UmbracoHelper(UmbracoContext.Current);
    
            IEnumerable<IPublishedContent> multiNodeTreePickerContent = Enumerable.Empty<IPublishedContent>();
    
            if (nodeIds != null && nodeIds.Length > 0)
            {
              if (uQuery.GetUmbracoObjectType(nodeIds[0]) == uQuery.UmbracoObjectType.Document)
              {
                multiNodeTreePickerContent = umbHelper.TypedContent(nodeIds).Where(x => x != null);
              }
              else if (uQuery.GetUmbracoObjectType(nodeIds[0]) == uQuery.UmbracoObjectType.Media)
              {
                multiNodeTreePickerContent = umbHelper.TypedMedia(nodeIds).Where(x => x != null);
              }
              else
              {
                return new Attempt<object>(true, multiNodeTreePicker);
              }
            }
    
            multiNodeTreePicker = multiNodeTreePickerContent;
    
            return new Attempt<object>(true, multiNodeTreePicker);
          }
    
          return new Attempt<object>(false, Enumerable.Empty<IPublishedContent>());
        }
    

    Any ideas, it's been a long week and it's only Monday!?

    Thanks, Simon

  • Tim 174 posts 398 karma points
    Dec 11, 2014 @ 16:34
    Tim
    0

    Hi Simon,

    We've just hit a similar issue but with the Where. Looking at the DLLs all looks in order. Did you sort it?

    Tim

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Dec 11, 2014 @ 17:07
    Simon Dingley
    0

    Right, I think the Attempt object changed between the versions so needed to update it's usage. See below is my current version:

      public class MultiNodeTreePickerPropertyEditorValueConverter : IPropertyEditorValueConverter
      {
        private string _propertyTypeAlias = string.Empty;
        private string _docTypeAlias = string.Empty;
    
        public bool IsConverterFor(Guid propertyEditorId, string docTypeAlias, string propertyTypeAlias)
        {
          _propertyTypeAlias = propertyTypeAlias;
          _docTypeAlias = docTypeAlias;
          return Guid.Parse("7e062c13-7c41-4ad9-b389-41d88aeef87c").Equals(propertyEditorId);
        }
    
        public Attempt<object> ConvertPropertyValue(object value)
        {
          IEnumerable<IPublishedContent> multiNodeTreePicker = Enumerable.Empty<IPublishedContent>();
          if (UmbracoContext.Current != null)
          {
            int[] nodeIds = new int[0];
            if (XmlHelper.CouldItBeXml(value.ToString()))
            {
              nodeIds = uQuery.GetXmlIds(value.ToString());
            }
            else
            {
              nodeIds =
                value.ToString()
                  .Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                  .Select(int.Parse)
                  .ToArray();
            }
            var umbHelper = new UmbracoHelper(UmbracoContext.Current);
    
            IEnumerable<IPublishedContent> multiNodeTreePickerContent = Enumerable.Empty<IPublishedContent>();
    
            if (nodeIds != null && nodeIds.Length > 0)
            {
              if (uQuery.GetUmbracoObjectType(nodeIds[0]) == uQuery.UmbracoObjectType.Document)
              {
                multiNodeTreePickerContent = umbHelper.TypedContent(nodeIds).Where(x => x != null);
              }
              else if (uQuery.GetUmbracoObjectType(nodeIds[0]) == uQuery.UmbracoObjectType.Media)
              {
                multiNodeTreePickerContent = umbHelper.TypedMedia(nodeIds).Where(x => x != null);
              }
              else
              {
                return Attempt<object>.Succeed(multiNodeTreePicker);
              }
            }
    
            if (multiNodeTreePickerContent != null)
            {
              multiNodeTreePicker = multiNodeTreePickerContent;
            }
    
            return Attempt<object>.Succeed(multiNodeTreePicker);
          }
    
          return Attempt<object>.Fail();
        }
      }
    

    Something else to be aware of also is that the MNTP was moved into the Core so make sure your doctype property is not referencing the legacy uComponents version and you are comparing the correct Guid for the propertyEditorId.

    Hopefully that helps.

    Simon

Please Sign in or register to post replies

Write your reply to:

Draft