Tuesday, December 11, 2012

Umbraco Using Courier to Deploy Multi-Node Tree Pickers

The same problem that I mentioned relating to the Deploying MultiType data occurs with other uComponets data types as well.  The Multi-Node Tree Picker for example has the same problem if you user XML as the storage method.  You could get around this by using CSV but that is harder to work with in macro code.  The following is another sample data provider to add support for deploying MNTP-XML Data(Data Editor GUID: 7e062c13-7c41-4ad9-b389-41d88aeef87c).


using Umbraco.Courier.Core;
using Umbraco.Courier.Core.Enums;
using Umbraco.Courier.Core.Helpers;
using Umbraco.Courier.DataResolvers;
using Umbraco.Courier.ItemProviders;

using System.Collections.Generic;
using System.Linq;

namespace JSP {
    /// <summary>
    /// Custm Data Resolver for use with Multi-Node Tree Picker data objects.  Will convers a list of xml nodes to guids for deployment and back again.
    /// </summary>
 public class MNTPXml : PropertyDataResolverProvider
 {
  /// <summary>
        /// The datatype guid of the multitype item we are running on.
        /// </summary>
        public override Guid DataTypeId
        {
            get { return new Guid("7e062c13-7c41-4ad9-b389-41d88aeef87c"); }
        }

        /// <summary>
        /// Run when a property of the specified type is packaged up.
        /// </summary>
        public override void PackagingProperty(Item item, ContentProperty propertyData)
        {
            string nodeXpath = "//nodeId";

            // Document References
            List<string> replacedIds = new List<string>();
            propertyData.Value = XmlDependencies.ReplaceIds(propertyData.Value.ToString(), nodeXpath, IdentifierReplaceDirection.FromNodeIdToGuid, out replacedIds);

            // List all id's found and make them dependencies.
            foreach (string guid in replacedIds)
            {
                // Add as a dependency. (working?)
                item.Dependencies.Add(guid, ProviderIDCollection.documentItemProviderGuid);
            }
        }

        /// <summary>
        /// Run when a property of the specified type is extracted.
        /// </summary>
        public override void ExtractingProperty(Item item, ContentProperty propertyData)
        {
            string nodeXpath = "//nodeId";

            // Document References
            List<string> replacedIds = new List<string>();
            propertyData.Value = XmlDependencies.ReplaceIds(propertyData.Value.ToString(), nodeXpath, IdentifierReplaceDirection.FromGuidToNodeId, out replacedIds);
        }
}

No comments: