views:

65

answers:

1

I tried to write some code to import a large customization containing 50+ entities. I used the microsoft article 'ImportXmlWithProgress Message (CrmService) as a bases, but was not getting the output I expected.

The 'job.data' in the following code was not changing from the original parameterxml data. So this implies to me that the import was not sucessful. I imported the same compressed importexportxml using the microsoft web ui, and it worked fine. So I'm wondering why my job.data is not being updated with 'result' attributes for each entity that is imported.

Below is my method to import.

private void ImportEntitySchema()
{
    const string parameterXml = @"<importexportxml>
    <entities>
      {0}
    </entities>
    <nodes/>
    <securityroles/>
    <settings/>
    <workflows/>
         </importexportxml>";
    var importRequest = new ImportCompressedXmlWithProgressRequest
       {
        ImportJobId = Guid.NewGuid(),
        CompressedCustomizationXml = GetCompressedCustomizationXmlFromEmbeddedResource(),
        ParameterXml = string.Format(parameterXml, string.Join("\n", _entitySchemaEntityNames.Select(item => string.Format("<entity>{0}</entity>", item)).ToArray()))
       };
    try
    {
     _crmService.Execute(importRequest);
    }
    catch (Exception e)
    {
     //Error resulted from import request
    }

    // Retrieve the results of the import.
    XmlNode node;
    do
    {
     Thread.Sleep(2000);
     var job = (importjob)_crmService.Retrieve(EntityName.importjob.ToString(), importRequest.ImportJobId, new AllColumns());
     var data = new XmlDocument();
     data.LoadXml(job.data);
     node = data.SelectSingleNode("importexportxml/entities/entity/@result");
    } while (node == null);

    //code below here never gets executed because the loop continues infinitely
}

I've been looking, but haven't found any/many [useful] examples on the net of the ImportXmlWithProgress being used. Hopefully someone has used it and has an idea of how to get it working.

A: 

I remember having trouble with this message, I just can't remember exactly what the trouble was. How big is your import file? We also brewed an import utility for importing our customizations and I use the ImportCompressedAllXmlRequest synchronously (no timeout) on a BackgroundWorker thread. For large amounts of customizations you may have to look at: http://support.microsoft.com/kb/918609. We typically split up our customizations into a bunch of small imports to avoid this.

Should the XPath be "importexportxml/entities/entity[@result]"?

benjynito
The compressed import file itself is only 1.5 meg. At present, we have resorted to importing about 10-20 entities using the CRM Web UI. Not our ideal, nor final, solution. The XPath is not the issue, as during debugging I have observed no changes in the data in 'job.data'. I have also read that article and attempted it as a solution. Using the ImportCompressedAllXmlRequest, is there a way to monitor progress, or failures? Considering this import can take 10-20 mins to import? How do you know whether all the entities have been imported correctly?
Luke Baulch
The ImportCompressedAllXmlRequest request gives no progress and is all or nothing. Everything is in a transaction, so any failures cause everything to rollback. Other than that, I'm not sure what to suggest. I was hoping one of the things I was familiar with might do the trick for you.
benjynito