Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
EWS C#ExchangeService.MoveItems问题_C#_Exchangewebservices - Fatal编程技术网

EWS C#ExchangeService.MoveItems问题

EWS C#ExchangeService.MoveItems问题,c#,exchangewebservices,C#,Exchangewebservices,我有一个EWS MoveItems问题,希望有人能帮我解决。在sent文件夹中有1300封电子邮件,我调用MoveItems方法将它们全部移动到备份文件夹中,只有一部分邮件被移动!为了寻找模式,我记录了以下测试编号: 测试#1:初始计数:1300;实际移动:722 测试#2:初始计数:1300;实际移动:661 测试#3:初始计数:1300;实际移动:738 对于每个测试用例,我的日志输出显示找到了1300个并将其传递给MoveItems方法,但是,检查Sent Items文件夹显示并非所有13

我有一个EWS MoveItems问题,希望有人能帮我解决。在sent文件夹中有1300封电子邮件,我调用MoveItems方法将它们全部移动到备份文件夹中,只有一部分邮件被移动!为了寻找模式,我记录了以下测试编号:

测试#1:初始计数:1300;实际移动:722

测试#2:初始计数:1300;实际移动:661

测试#3:初始计数:1300;实际移动:738

对于每个测试用例,我的日志输出显示找到了1300个并将其传递给MoveItems方法,但是,检查Sent Items文件夹显示并非所有1300个都已移动(如上面的测试所示)

以下是我的代码片段:

...
do
{
    ItemView view = new ItemView(pageSize, offset);
    findResults = service.FindItems(folder, emailFilter, view);

    Logger.Write("Email count on this page to be archived: " + findResults.Items.Count);

    foreach (Item email in findResults)
    {
        itemIds.Add(email.Id);
    }

    offset += pageSize;
}
while (findResults.MoreAvailable);

Logger.Write("Total email Ids to be archived: " + itemIds.Count());

if (itemIds.Count() > 0)
{
    Logger.Write("Archiving emails...");
    service.MoveItems(itemIds, folder5.Folders[0].Id);
    Logger.Write("Archive call complete.");
}
else 
{
    Logger.Write("No emails found to archive.");
}
...
所有这些都被包装在一个try/catch块中。没有发现错误

唯一值得注意的是,“存档电子邮件…”日志和“存档呼叫完成”之间的时间总是在1分钟的一两秒内。可能表示通话超时?这是我的一小段日志:

8/15/2014 4:29:43 PM - Information - Archiving emails... 
8/15/2014 4:29:44 PM - Information - Creating search filters...
8/15/2014 4:29:48 PM - Information - Email count on this page to be archived: 1000
8/15/2014 4:29:49 PM - Information - Email count on this page to be archived: 300
8/15/2014 4:29:49 PM - Information - Total email Ids to be archived: 1300
8/15/2014 4:29:49 PM - Information - Archiving emails...
8/15/2014 4:30:51 PM - Information - Archive call complete.
8/15/2014 4:30:51 PM - Information - Email archival completed without errors

我已经筋疲力尽了,所以我非常感谢您能提供的任何帮助。

我在使用EWS时也遇到过同样的问题。我不确定“正确”的解决方案是什么,但我的变通方法似乎奏效了。我分析了这次移动,一次移动几百个项目似乎效果不错。尝试在每次调用MoveItems时移动~250。您应该尝试处理运行MoveItems方法时返回的ServiceResponses,例如

            if (itemIds.Count() > 0)
        {                
           ServiceResponseCollection<MoveCopyItemResponse> Responses =  service.MoveItems(itemIds, folder5.Id);
            Int32 Success = 0;
            Int32 Error = 0;
            foreach (MoveCopyItemResponse respItem in Responses) {
                switch (respItem.Result) {
                    case ServiceResult.Success: Success++;
                        break;
                    case ServiceResult.Error: Error++;
                        Console.WriteLine("Error with Item " + respItem.ErrorMessage);
                        break;
                }                  
           }
            Console.WriteLine("Results Processed " + itemIds.Count + " Success " + Success + " Failed " + Error);
        }
if(itemIds.Count()>0)
{                
ServiceResponseCollection Responses=service.MoveItems(ItemId,folder5.Id);
Int32成功=0;
Int32错误=0;
foreach(MoveCopyItemResponse响应中的respItem){
开关(respItem.Result){
案例服务结果。成功:成功++;
打破
案例服务结果。错误:Error++;
Console.WriteLine(“项错误”+respItem.ErrorMessage);
打破
}                  
}
Console.WriteLine(“已处理结果”+ItemId.Count+“成功”+Success+“失败”+错误);
}
这将告诉你发生了什么,以及为什么你的一些行动失败了。我会怀疑它的节流,所以克里斯建议降低批量大小。在过去,当我写东西在邮箱和存档之间进行大规模移动时,我选择了100个项目的批量大小,从来没有遇到过问题。当我将批量设置得太大时,我看到超时和节流错误

干杯
格伦

克里斯,谢谢你的建议。我可能会利用你的作品。我会给原创文章更多的时间。希望有人能为我们两人提供一个“正确”的解决方案。我想知道这个电话返回的项目是否少于
pageSize
FindItemsResult
具有
NextPageOffset
属性。您是否可以将其用于下一个
偏移量
,而不是通过
页面大小
增加它?好的,感谢您提供有关检查服务响应的提示!