public async Task UploadAsync(IList<SkyDriveFile> files, IProgress<LiveOperationProgress> progress) { if (!IsInitialized) throw new InvalidOperationException("Live client was not authenticated or initialized. Initialize the client first by calling InitializeAsync()."); IsUploading = true; var dataSize = new List<ulong>(files.Count); var chartSize = new List<ulong>(files.Count); for (var i = 0; i < files.Count; ++i) { var file = files[i]; var coreMessage = string.Format("Uploading packages: {0}/{1}", i + 1, files.Count); Message = coreMessage + " (XML data)"; try { var currentFile = await folder.GetFileAsync(file.SourceFilePath); var basicProperties = await currentFile.GetBasicPropertiesAsync(); using (var stream = await currentFile.OpenStreamForReadAsync()) { await client.UploadAsync("me/skydrive", file.DestinationFilePath, stream, OverwriteOption.Overwrite, CancellationToken.None, progress); } dataSize.Add(basicProperties.Size); OnFileUploadFinished(); } catch (LiveConnectException ex) { var toast = new ToastPrompt { Title = "Connection error", TextOrientation = Orientation.Horizontal, Message = "File " + file.SourceFilePath + " was not uploaded" }; toast.Completed += (sender, args) => { if (args.PopUpResult == PopUpResult.Ok) { MessageBox.Show(ex.Message, "Connection error", MessageBoxButton.OK); } }; toast.Show(); } if (!shouldUploadPlots) continue; Message = coreMessage + " (SVG plot)"; try { var plotFile = await folder.GetFileAsync(file.PlotSourceFilePath); var basicProperties = await plotFile.GetBasicPropertiesAsync(); using (var stream = await plotFile.OpenStreamForReadAsync()) { await client.UploadAsync("me/skydrive", file.PlotDestinationFilePath, stream, OverwriteOption.Overwrite, CancellationToken.None, progress); } chartSize.Add(basicProperties.Size); OnFileUploadFinished(); } catch (LiveConnectException ex) { var toast = new ToastPrompt { Title = "Connection error", TextOrientation = Orientation.Horizontal, Message = "Plot file " + file.PlotSourceFilePath + " was not uploaded" }; toast.Completed += (sender, args) => { if (args.PopUpResult == PopUpResult.Ok) { MessageBox.Show(ex.Message, "Connection error", MessageBoxButton.OK); } }; toast.Show(); } } UploadSummary = new SkyDriveUploadSummary(dataSize, chartSize); IsUploading = false; }
public async Task UploadAsync(IList <SkyDriveFile> files, IProgress <LiveOperationProgress> progress) { if (!IsInitialized) { throw new InvalidOperationException("Live client was not authenticated or initialized. Initialize the client first by calling InitializeAsync()."); } IsUploading = true; var dataSize = new List <ulong>(files.Count); var chartSize = new List <ulong>(files.Count); for (var i = 0; i < files.Count; ++i) { var file = files[i]; var coreMessage = string.Format("Uploading packages: {0}/{1}", i + 1, files.Count); Message = coreMessage + " (XML data)"; try { var currentFile = await folder.GetFileAsync(file.SourceFilePath); var basicProperties = await currentFile.GetBasicPropertiesAsync(); using (var stream = await currentFile.OpenStreamForReadAsync()) { await client.UploadAsync("me/skydrive", file.DestinationFilePath, stream, OverwriteOption.Overwrite, CancellationToken.None, progress); } dataSize.Add(basicProperties.Size); OnFileUploadFinished(); } catch (LiveConnectException ex) { var toast = new ToastPrompt { Title = "Connection error", TextOrientation = Orientation.Horizontal, Message = "File " + file.SourceFilePath + " was not uploaded" }; toast.Completed += (sender, args) => { if (args.PopUpResult == PopUpResult.Ok) { MessageBox.Show(ex.Message, "Connection error", MessageBoxButton.OK); } }; toast.Show(); } if (!shouldUploadPlots) { continue; } Message = coreMessage + " (SVG plot)"; try { var plotFile = await folder.GetFileAsync(file.PlotSourceFilePath); var basicProperties = await plotFile.GetBasicPropertiesAsync(); using (var stream = await plotFile.OpenStreamForReadAsync()) { await client.UploadAsync("me/skydrive", file.PlotDestinationFilePath, stream, OverwriteOption.Overwrite, CancellationToken.None, progress); } chartSize.Add(basicProperties.Size); OnFileUploadFinished(); } catch (LiveConnectException ex) { var toast = new ToastPrompt { Title = "Connection error", TextOrientation = Orientation.Horizontal, Message = "Plot file " + file.PlotSourceFilePath + " was not uploaded" }; toast.Completed += (sender, args) => { if (args.PopUpResult == PopUpResult.Ok) { MessageBox.Show(ex.Message, "Connection error", MessageBoxButton.OK); } }; toast.Show(); } } UploadSummary = new SkyDriveUploadSummary(dataSize, chartSize); IsUploading = false; }