2009-10-06 27 views
0

我試圖編寫一些代碼來導入包含50多個實體的大型自定義。我用微軟的文章'ImportXmlWithProgress Message (CrmService)作爲基礎,但沒有得到我期望的輸出結果。ImportXmlWithProgress不更新importjob的結果屬性

以下代碼中的'job.data'未從原始參數xml數據更改。所以這意味着進口並不成功。我使用microsoft web ui導入了相同的壓縮importexportxml,並且它工作正常。所以我想知道爲什麼我的job.data沒有被導入的每個實體的'result'屬性更新。

以下是我的導入方法。

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淨任何/很多[實用]例子。希望有人使用它,並有一個如何讓它工作的想法。

回答

0

我記得有這個消息的麻煩,我只是不記得究竟是什麼麻煩。您的導入文件有多大?我們還釀造了一個用於導入我們的定製的導入工具,我在BackgroundWorker線程上同步使用ImportCompressedAllXmlRequest(沒有超時)。對於大量的定製,您可能需要查看:http://support.microsoft.com/kb/918609。我們通常會將我們的定製分割成一堆小型導入,以避免這種情況。

XPath應該是"importexportxml/entities/entity[@result]"

+0

壓縮的導入文件本身只有1.5兆。目前,我們已經使用CRM Web UI來進口大約10-20個實體。不是我們的理想,也不是最終解決方案。 XPath不是問題,因爲在調試過程中,我發現'job.data'中的數據沒有變化。我也讀過那篇文章並試圖將其作爲解決方案。 使用ImportCompressedAllXmlRequest,有沒有辦法監視進度或失敗?考慮到這一進口可能需要10-20分鐘才能進口?你怎麼知道所有的實體是否被正確導入? – 2009-10-08 02:31:02

+0

ImportCompressedAllXmlRequest請求不提供任何進度,全部或全部無效。一切都在交易中,所以任何失敗都會導致一切回滾。除此之外,我不知道該建議什麼。我希望我熟悉的其中一件事可能會對你有所裨益。 – 2009-10-08 13:06:29