private void ReplacePropertyDataIds(Item item, ContentProperty propertyData, Direction direction)
        {
            if (propertyData != null && propertyData.Value != null)
            {
                // just look at the amount of dancing around we have to do in order to fake a `PublishedPropertyType`?!
                var dataTypeId       = PersistenceManager.Default.GetNodeId(propertyData.DataType, NodeObjectTypes.DataType);
                var fakePropertyType = this.CreateDummyPropertyType(dataTypeId, this.EditorAlias);

                var converter = new ArchetypeValueConverter();
                var archetype = (ArchetypeModel)converter.ConvertDataToSource(fakePropertyType, propertyData.Value, false);

                if (archetype != null)
                {
                    // create a 'fake' provider, as ultimately only the 'Packaging' enum will be referenced.
                    var fakeItemProvider = new PropertyItemProvider();

                    foreach (var property in archetype.Fieldsets.SelectMany(x => x.Properties))
                    {
                        if (property == null || string.IsNullOrWhiteSpace(property.PropertyEditorAlias))
                        {
                            continue;
                        }

                        // create a 'fake' item for Courier to process
                        var fakeItem = new ContentPropertyData()
                        {
                            ItemId = item.ItemId,
                            Name   = string.Format("{0} [{1}: Nested {2} ({3})]", new[] { item.Name, this.EditorAlias, property.PropertyEditorAlias, property.Alias }),
                            Data   = new List <ContentProperty>
                            {
                                new ContentProperty
                                {
                                    Alias               = property.Alias,
                                    DataType            = PersistenceManager.Default.GetUniqueId(property.DataTypeId, NodeObjectTypes.DataType),
                                    PropertyEditorAlias = property.PropertyEditorAlias,
                                    Value               = property.Value
                                }
                            }
                        };

                        if (direction == Direction.Packaging)
                        {
                            try
                            {
                                // run the 'fake' item through Courier's data resolvers
                                ResolutionManager.Instance.PackagingItem(fakeItem, fakeItemProvider);
                            }
                            catch (Exception ex)
                            {
                                LogHelper.Error <ArchetypeDataResolver>(string.Concat("Error packaging data value: ", fakeItem.Name), ex);
                            }

                            // pass up the dependencies and resources
                            item.Dependencies.AddRange(fakeItem.Dependencies);
                            item.Resources.AddRange(fakeItem.Resources);
                        }
                        else if (direction == Direction.Extracting)
                        {
                            try
                            {
                                // run the 'fake' item through Courier's data resolvers
                                ResolutionManager.Instance.ExtractingItem(fakeItem, fakeItemProvider);
                            }
                            catch (Exception ex)
                            {
                                LogHelper.Error <ArchetypeDataResolver>(string.Concat("Error extracting data value: ", fakeItem.Name), ex);
                            }
                        }

                        if (fakeItem.Data != null && fakeItem.Data.Any())
                        {
                            var firstDataType = fakeItem.Data.FirstOrDefault();
                            if (firstDataType != null)
                            {
                                // set the resolved property data value
                                property.Value = firstDataType.Value;

                                // (if packaging) add a dependency for the property's data-type
                                if (direction == Direction.Packaging)
                                {
                                    item.Dependencies.Add(firstDataType.DataType.ToString(), ProviderIDCollection.dataTypeItemProviderGuid);
                                }
                            }
                        }
                    }

                    if (item.Name.Contains(string.Concat(this.EditorAlias, ": Nested")))
                    {
                        // if the Archetype is nested, then we only want to return the object itself - not a serialized string
                        propertyData.Value = archetype;
                    }
                    else
                    {
                        // if the Archetype is the root/container, then we can serialize it to a string
                        propertyData.Value = archetype.SerializeForPersistence();
                    }
                }
            }
        }
        private void ReplacePropertyDataIds(Item item, ContentProperty propertyData, Direction direction)
        {
            if (propertyData != null && propertyData.Value != null)
            {
                // just look at the amount of dancing around we have to do in order to fake a `PublishedPropertyType`?!
                var dataTypeId = PersistenceManager.Default.GetNodeId(propertyData.DataType, NodeObjectTypes.DataType);
                var fakePropertyType = this.CreateDummyPropertyType(dataTypeId, this.EditorAlias);

                var converter = new ArchetypeValueConverter();
                var archetype = (ArchetypeModel)converter.ConvertDataToSource(fakePropertyType, propertyData.Value, false);

                if (archetype != null)
                {
                    // create a 'fake' provider, as ultimately only the 'Packaging' enum will be referenced.
                    var fakeItemProvider = new PropertyItemProvider();

                    foreach (var property in archetype.Fieldsets.SelectMany(x => x.Properties))
                    {
                        if (property == null || string.IsNullOrWhiteSpace(property.PropertyEditorAlias))
                            continue;

                        // create a 'fake' item for Courier to process
                        var fakeItem = new ContentPropertyData()
                        {
                            ItemId = item.ItemId,
                            Name = string.Format("{0} [{1}: Nested {2} ({3})]", new[] { item.Name, this.EditorAlias, property.PropertyEditorAlias, property.Alias }),
                            Data = new List<ContentProperty>
                            {
                                new ContentProperty
                                {
                                    Alias = property.Alias,
                                    DataType = PersistenceManager.Default.GetUniqueId(property.DataTypeId, NodeObjectTypes.DataType),
                                    PropertyEditorAlias = property.PropertyEditorAlias,
                                    Value = property.Value
                                }
                            }
                        };

                        if (direction == Direction.Packaging)
                        {
                            try
                            {
                                // run the 'fake' item through Courier's data resolvers
                                ResolutionManager.Instance.PackagingItem(fakeItem, fakeItemProvider);
                            }
                            catch (Exception ex)
                            {
                                LogHelper.Error<ArchetypeDataResolver>(string.Concat("Error packaging data value: ", fakeItem.Name), ex);
                            }

                            // pass up the dependencies and resources
                            item.Dependencies.AddRange(fakeItem.Dependencies);
                            item.Resources.AddRange(fakeItem.Resources);
                        }
                        else if (direction == Direction.Extracting)
                        {
                            try
                            {
                                // run the 'fake' item through Courier's data resolvers
                                ResolutionManager.Instance.ExtractingItem(fakeItem, fakeItemProvider);
                            }
                            catch (Exception ex)
                            {
                                LogHelper.Error<ArchetypeDataResolver>(string.Concat("Error extracting data value: ", fakeItem.Name), ex);
                            }
                        }

                        if (fakeItem.Data != null && fakeItem.Data.Any())
                        {
                            var firstDataType = fakeItem.Data.FirstOrDefault();
                            if (firstDataType != null)
                            {
                                // set the resolved property data value
                                property.Value = firstDataType.Value;

                                // (if packaging) add a dependency for the property's data-type
                                if (direction == Direction.Packaging)
                                    item.Dependencies.Add(firstDataType.DataType.ToString(), ProviderIDCollection.dataTypeItemProviderGuid);
                            }
                        }
                    }

                    if (item.Name.Contains(string.Concat(this.EditorAlias, ": Nested")))
                    {
                        // if the Archetype is nested, then we only want to return the object itself - not a serialized string
                        propertyData.Value = archetype;
                    }
                    else
                    {
                        // if the Archetype is the root/container, then we can serialize it to a string
                        propertyData.Value = archetype.SerializeForPersistence();
                    }
                }
            }
        }