使用SkyDrive的API多文件下载 [英] multiple file download using SkyDrive API

查看:148
本文介绍了使用SkyDrive的API多文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码,我试图从用户下载3个不同的文件的SkyDrive帐户。



我使用的Windows Phone开发SkyDrive的API

  client.DownloadCompleted + =新的EventHandler< LiveDownloadCompletedEventArgs>(OnDownloadCompletedVI); 
client.DownloadAsync(fileIdVehicleItems);


client.DownloadCompleted + =新的EventHandler< LiveDownloadCompletedEventArgs>(OnDownloadCompletedHI);
client.DownloadAsync(fileIdHistoryItems);


client.DownloadCompleted + =新的EventHandler< LiveDownloadCompletedEventArgs>(OnDownloadCompletedRI);
client.DownloadAsync(fileIdRepairItems);

当我运行这个,那个被调用的唯一方法就是OnDownloadCompletedVI。所有正在下载的文件是通过这种方法,这是造成错误运行。



我在做什么错误?



更新



我有以下的方法,但我有其他类似的2 。除了它加载不同的对象(基于关闭的下载的文件)做同样的事情的方法。



目前我收到的错误:




类型'System.ArgumentException'的异常出现在
mscorlib.ni.dll但在用户代码中没有处理




 无效OnDownloadCompletedVI(对象发件人,LiveDownloadCompletedEventArgs E)
{
如果(e.Result!=使用空)
{
(VAR stream_vi = e.Result)
{
StreamReader的SRVI =新的StreamReader(stream_vi);
串contentVI =;
contentVI = SRVI.ReadToEnd();

StringReader rdr_vi =新StringReader(contentVI);

XmlSerializer的序列化=新的XmlSerializer(typeof运算(的ObservableCollection<车辆GT;));

&的ObservableCollection LT;车辆GT; importedVehicles =新的ObservableCollection<车辆GT;();
importedVehicles =(的ObservableCollection<车辆GT;)serializer.Deserialize(rdr_vi);

StorageHelper.Save<&的ObservableCollection LT;车辆GT;>(App.vehicleData,importedVehicles);
}
//e.Result.Close();
}
,否则
{
infoTextBlock.Text =下载文件出错:+ e.Error.ToString();
}
}


解决方案

其实所有三种方法应该被调用。当然,如果第一种方法被调用,并抛出一个异常,另外两个不会触发。



您可以做的是创建一个新的客户端每次调用,或下载,以便他们,所以当 OnDownloadCompletedVI 方法完成后,取出的事件处理程序 OnDownloadCompletedVI 并添加一为 OnDownloadCompletedHI ,然后触发 client.DownloadAsync(fileIdHistoryItems); 在方法结束


I have the following code where I'm trying to download 3 different files from the users SkyDrive Account.

I'm using the SkyDrive API for Windows Phone development.

client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedVI);
client.DownloadAsync(fileIdVehicleItems);


client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedHI);
client.DownloadAsync(fileIdHistoryItems);


client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedRI);
client.DownloadAsync(fileIdRepairItems);

When I run this, the only method that gets called is the OnDownloadCompletedVI. All the files that are being downloaded are running through this method which is causing an error.

What am I doing incorrectly?

Update

I have the following method, but I have 2 other similar methods that do the exact same thing except it loads different objects (based off of the downloaded files).

The error I'm currently receiving:

An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll but was not handled in user code

    void OnDownloadCompletedVI(object sender, LiveDownloadCompletedEventArgs e)
    {
        if (e.Result != null)
        {
            using (var stream_vi = e.Result)
            {
                StreamReader SRVI = new StreamReader(stream_vi);
                string contentVI = "";
                contentVI = SRVI.ReadToEnd();

                StringReader rdr_vi = new StringReader(contentVI);

                XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<vehicle>));

                ObservableCollection<vehicle> importedVehicles = new ObservableCollection<vehicle>();
                importedVehicles = (ObservableCollection<vehicle>)serializer.Deserialize(rdr_vi);

                StorageHelper.Save<ObservableCollection<vehicle>>(App.vehicleData, importedVehicles);
            }
            //e.Result.Close();
        }
        else
        {
            infoTextBlock.Text = "Error downloading file: " + e.Error.ToString();
        }
    }

解决方案

Actually all three methods should be called. Of course, if the first method is called and throws an exception the other two won't trigger.

What you can do is either create a new client for each call, or download them in order, so when the OnDownloadCompletedVI method is complete, remove the event handler for OnDownloadCompletedVI and add the one for OnDownloadCompletedHI and then trigger the client.DownloadAsync(fileIdHistoryItems); at the end of the method.

这篇关于使用SkyDrive的API多文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆