0
votes

I've created a custom part and attached it to the Site content type. In the driver for my custom part, I'm overriding the Importing and Exporting methods but when I perform an export or import while debugging they never get called.

My part has two bool properties and one complex type. When I examine the export file that get's produced my bool properties are present but my complex type is not so it seems that Orchard is automatically handling the simple types.

Any ideas why my Importing and Exporting methods are not being called?

Update:

After some more debugging I think I see why my complex type is not being exported. In the ExportSiteSettings method of the ImportExportService there is an explicit check done on the property type (line 151) and only properties of type string, bool and int have their values included in the site settings portion of the export. From what I can tell, the driver for my part is never involved in exporting site settings.

If I select the Site type and Data as export options my driver's Exporting method does get called and the properties are included in the Data section of the export file but when I go to import, they are ignored and my driver's Importing method is never called (I think because the Site element under Data has no Id attribute set).

export settings

I'm not sure what to do here. Is exporting complex types just not supported on the Site content type?

Here's the code for my part:

public class ProductSettingsPart : ContentPart {

        public bool DefineSiteDefaults {
            get { return this.Retrieve(p => p.DefineSiteDefaults); }
            set { this.Store(p => p.DefineSiteDefaults, value); }
        }

        public bool AllowProductOverrides {
            get { return this.Retrieve(p => p.AllowProductOverrides); }
            set { this.Store(p => p.AllowProductOverrides, value); }
        }

        public IEnumerable<PriceTier> PriceTiers {
            get {
                var rawTiers = Retrieve<string>("PriceTiers");
                return PriceTier.DeserializePriceTiers(rawTiers);
            }
            set {
                var serializedTiers = PriceTier.SerializePriceTiers(value);
                Store("PriceTiers", serializedTiers ?? "");
            }
        }
    }
1
I'm confused, because if the two bools are in the export file then Exporting does get called. Are you using infoset storage for your bool properties? - Piedone
Attach a debugger and find out where it fails. - Bertrand Le Roy
@Piedone - Yes, I am using infoset storage for all the properties on my part. - joshb
@Bertrand - I updated my question with some more info on what I found after further debugging. - joshb
That would be a bug, I think. Please file it. - Bertrand Le Roy

1 Answers

0
votes

I had the same problem, I needed to export SearchSettingsPart's SearchedFields property, a string[].

I fixed the issue and submitted a pull request.

https://orchard.codeplex.com/SourceControl/network/forks/StanleyGoldman/Issue20404/contribution/6048

There is a convenience method that exports the bool/int/string fields You should be able to use your Part Driver's Import Export method now.

protected override void Exporting(SearchSettingsPart part, ExportContentContext context) {
    DefaultSettingsPartImportExport.ExportSettingsPart(part, context);
    context.Element(part.PartDefinition.Name).Add(new XAttribute("SearchedFields", string.Join(",", part.SearchedFields)));
}

protected override void Importing(SearchSettingsPart part, ImportContentContext context) {
    var xElement = context.Data.Element(part.PartDefinition.Name);
    if (xElement == null) return;

    DefaultSettingsPartImportExport.ImportSettingPart(part, xElement);

    var searchedFields = xElement.Attribute("SearchedFields");
    part.SearchedFields = searchedFields.Value.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
}