简体   繁体   中英

multiple file download using SkyDrive API

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM