【问题标题】:ImportXmlWithProgress not updating result attribute of importjobImportXmlWithProgress 不更新 importjob 的结果属性
【发布时间】:2009-10-06 03:37:16
【问题描述】:

我尝试编写一些代码来导入包含 50 多个实体的大型自定义项。我使用了 microsoft 文章 'ImportXmlWithProgress Message (CrmService) 作为基础,但没有得到我期望的输出。

以下代码中的“job.data”与原始 parameterxml 数据没有变化。所以这对我来说意味着导入不成功。我使用 microsoft web ui 导入了相同的压缩 importexportxml,它运行良好。所以我想知道为什么我的 job.data 没有更新为每个导入的实体的“结果”属性。

以下是我的导入方法。

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
}

我一直在寻找,但在使用 ImportXmlWithProgress 的网络上没有找到任何/许多 [有用的] 示例。希望有人使用过它并知道如何让它发挥作用。

【问题讨论】:

    标签: c# xml import dynamics-crm dynamics-crm-4


    【解决方案1】:

    我记得这条消息有问题,我只是不记得到底是什么问题。你的导入文件有多大?我们还制作了一个导入实用程序来导入我们的自定义设置,我在BackgroundWorker 线程上同步使用ImportCompressedAllXmlRequest(无超时)。对于大量自定义,您可能需要查看:http://support.microsoft.com/kb/918609。为了避免这种情况,我们通常会将我们的自定义项拆分成一堆小的导入。

    XPath 应该是"importexportxml/entities/entity[@result]"

    【讨论】:

    • 压缩后的导入文件本身只有1.5兆。目前,我们已经使用 CRM Web UI 导入了大约 10-20 个实体。不是我们理想的,也不是最终的解决方案。 XPath 不是问题,因为在调试过程中我观察到“job.data”中的数据没有变化。我也阅读了那篇文章并尝试将其作为解决方案。使用 ImportCompressedAllXmlRequest,有没有办法监控进度或失败?考虑到此导入可能需要 10-20 分钟才能导入?你怎么知道所有的实体是否都被正确导入了?
    • ImportCompressedAllXmlRequest 请求没有任何进展,要么全有,要么全无。一切都在事务中,因此任何失败都会导致一切回滚。除此之外,我不确定该建议什么。我希望我熟悉的其中一件事情能帮到你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    相关资源
    最近更新 更多