当前位置: 首页>>代码示例>>C#>>正文


C# LiveConnectClient.CreateBackgroundDownloadAsync方法代码示例

本文整理汇总了C#中Microsoft.Live.LiveConnectClient.CreateBackgroundDownloadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# LiveConnectClient.CreateBackgroundDownloadAsync方法的具体用法?C# LiveConnectClient.CreateBackgroundDownloadAsync怎么用?C# LiveConnectClient.CreateBackgroundDownloadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Live.LiveConnectClient的用法示例。


在下文中一共展示了LiveConnectClient.CreateBackgroundDownloadAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadProfileImage

 private async Task LoadProfileImage(LiveConnectClient connectClient)
 {
     try
     {
         LiveDownloadOperation downloadOperation = await connectClient.CreateBackgroundDownloadAsync("me/picture");
         LiveDownloadOperationResult result = await downloadOperation.StartAsync();
         if (result != null && result.Stream != null)
         {
             using (IRandomAccessStream ras = await result.GetRandomAccessStreamAsync())
             {
                 BitmapImage imgSource = new BitmapImage();
                 imgSource.SetSource(ras);
                 profileImage.Source = imgSource;
             }
         }
     }
     catch (LiveConnectException)
     {
         // Handle error cases.
     }
 }
开发者ID:d20021,项目名称:LiveSDK-for-Windows,代码行数:21,代码来源:MainPage.xaml.cs

示例2: downButton_Click_1

        private async  void downButton_Click_1(object sender, RoutedEventArgs e)//下载
        {
            try
            {
                msgText.Text = "亲:正在下载";
                string id = string.Empty;
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive" });
                if (authResult.Session != null)
                {
                    var connectClient = new LiveConnectClient(authResult.Session);




                    LiveOperationResult operationResult = await connectClient.GetAsync("me/skydrive/search?q=WorkBook.xml");
                    List<object> items = operationResult.Result["data"] as List<object>;
                    IDictionary<string, object> file = items.First() as IDictionary<string, object>;
                    id = file["id"].ToString();

                    LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(string.Format("{0}/content", id));
                    var result = await operation.StartAsync();
                    Stream stream = result.Stream.AsStreamForRead();

                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    StorageFile files = await localFolder.GetFileAsync(App.WordBookFileName);

                    XDocument xBook = XDocument.Load(stream);
                    await FileIO.WriteTextAsync(files, xBook.ToString());

                    msgText.Text = "恭喜:您已成功从OneDrive下载生词!";


                }
            }
            catch (Exception ex)
            {
                msgText.Text = ex.Message;
            }
        }
开发者ID:x01673,项目名称:BCMeng_Project,代码行数:40,代码来源:OneDrive.xaml.cs

示例3: RunButton_Click

        private async void RunButton_Click(object sender, RoutedEventArgs e)
        {
            string message = null;
            try
            {
                // Ensure that the user has consented the wl.skydrive and wl.skydrive_update scopes
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });
                if (authResult.Session == null)
                {
                    throw new InvalidOperationException("You need to sign in and give consent to the app.");
                }

                var liveConnectClient = new LiveConnectClient(authResult.Session);
                // Validate parameters
                var imageSourceUrl = imgSourceUrlTextBox.Text;
                if (string.IsNullOrWhiteSpace(imageSourceUrl))
                {
                    throw new InvalidOperationException("Image Url is empty.");
                }

                var uploadPath = uploadPathTextBox.Text;
                if (string.IsNullOrWhiteSpace(uploadPath))
                {
                    throw new InvalidOperationException("Upload location is empty.");
                }

                // Download the image from the Internet                
                var networkFileDownloader = new BackgroundDownloader();
                DownloadOperation networkFileDownloadOperation = networkFileDownloader.CreateDownload(new Uri(imageSourceUrl), null);
                await networkFileDownloadOperation.StartAsync();
                IInputStream uploadInputStream = networkFileDownloadOperation.GetResultStreamAt(0);


                // Upload to OneDrive
                LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(uploadPath, "ImageFromInternet.jpg", uploadInputStream, OverwriteOption.Rename);
                LiveOperationResult uploadResult = await uploadOperation.StartAsync();
                dynamic uploadedResource = uploadResult.Result;
                string uploadedResourceId = uploadedResource.id;
                string uploadedResourceName = uploadedResource.name;
                string uploadedResourceLink = uploadedResource.source;
                uploadedResourceTextBox.Text = string.Format("{0}\r\n{1}\r\n{2}", uploadedResourceId, uploadedResourceName, uploadedResourceLink);

                // Download from the OneDrive
                LiveDownloadOperation downloadOperation = await liveConnectClient.CreateBackgroundDownloadAsync(uploadedResourceId + "/content");
                LiveDownloadOperationResult downloadResult = await downloadOperation.StartAsync();
                if (downloadResult != null && downloadResult.Stream != null)
                {
                    using (IRandomAccessStream ras = await downloadResult.GetRandomAccessStreamAsync())
                    {
                        BitmapImage imgSource = new BitmapImage();
                        imgSource.SetSource(ras);
                        skydriveImage.Source = imgSource;
                    }
                }
            }
            catch (Exception ex)
            {
                message = "Operation failed: " + ex.Message;
            }

            if (message != null)
            {
                var dialog = new Windows.UI.Popups.MessageDialog(message);
                await dialog.ShowAsync();
            }
        }
开发者ID:d20021,项目名称:LiveSDK-for-Windows,代码行数:67,代码来源:UploadDownload.xaml.cs

示例4: RestoreAsync

        public async Task<bool> RestoreAsync(string fileName)
        {
            bool result = false;
            LastError = null;
            RestoreData = null;

            IsInProgress = true;

            try
            {
                var client = new LiveConnectClient(session);

                dynamic resultList = (await client.GetAsync("me/skydrive/files")).Result;
                foreach (dynamic res in resultList.data)
                    if (res.name == fileName)
                    {
                        string resourceId = res.id.ToString();

                        var operation = await client.CreateBackgroundDownloadAsync(string.Format("{0}/content", resourceId));
                        var downloadResult = await operation.StartAsync();

                        using (var s = downloadResult.Stream.AsStreamForRead())
                            using (var reader = new StreamReader(s, Encoding.UTF8))
                            RestoreData = reader.ReadToEnd();

                        result = true;
                        break;
                    }
            }
            catch (Exception ex)
            {
                LastError = ex.Message;
            }

            IsInProgress = false;

            return result;
        }
开发者ID:KonstantinKolesnik,项目名称:EcosHub,代码行数:38,代码来源:LiveManager.cs

示例5: downButton_Click_1

        private async void downButton_Click_1(object sender, RoutedEventArgs e)//下载
        {
            try
            {
                msgText.Text = "亲:正在下载";
                string id = string.Empty;
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive" });
                if (authResult.Session != null)
                {
                    var connectClient = new LiveConnectClient(authResult.Session);
                    LiveOperationResult operationResult = await connectClient.GetAsync("me/skydrive/search?q=notes.json");
                    List<object> items = operationResult.Result["data"] as List<object>;
                    IDictionary<string, object> file = items.First() as IDictionary<string, object>;
                    id = file["id"].ToString();
                    LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(string.Format("{0}/content", id));
                    var result = await operation.StartAsync();
                    Stream stream = result.Stream.AsStreamForRead();
                    Notes = (ObservableCollection<Note>)jsonSerializer.ReadObject(stream);
                    StorageFile files = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
                    using (var streamJson = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(fileName,
                        CreationCollisionOption.ReplaceExisting))
                    {
                        jsonSerializer.WriteObject(streamJson, Notes);
                    }
                    msgText.Text = "恭喜:您已成功从OneDrive下载记事!";
                    
                    Frame.Navigate(typeof(MainPage));

                }
            }
            catch (Exception ex)
            {
                msgText.Text = ex.Message;
            }
        }
开发者ID:x01673,项目名称:BCMeng_Project,代码行数:36,代码来源:OneDriveView.xaml.cs

示例6: downFromOnedriveButton_Click

        //다운로드 버튼
        private async void downFromOnedriveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //live 클라이언트 생성
                var liveConnectClient = new LiveConnectClient(loginResult.Session);
                //Onedrive file 목록을 불러온다.
                LiveOperationResult getResult = await liveConnectClient.GetAsync("me/skydrive/files");
                //raw result 받아오기
                dynamic rawResult = getResult.RawResult;
                //JSON 형태로 받아온 아이템을 Deserialize 한다.
                var resultItems = JsonConvert.DeserializeObject<OneDriveFiles>(rawResult);
                //MoneyNote.db파일을 찾는다.
                foreach (var innerItem in resultItems.data)
                {
                    if (innerItem.name == "MoneyNote.db")
                    {
                        //다운로드해서 대체 할 파일 위치
                        StorageFile downFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("MoneyNote.db", CreationCollisionOption.ReplaceExisting);
                        //이전버전
                        //var result = await liveConnectClient.BackgroundDownloadAsync(innerItem.id + "/content", downFile);
                        //messagePrint(true,"download");

                        //다운로드 시작
                        LiveDownloadOperation download = await liveConnectClient.CreateBackgroundDownloadAsync(innerItem.id + "/content", downFile);
                        LiveDownloadOperationResult downloadResult = await download.StartAsync();
                        messagePrint(true, "download");
                    }
                }
            }
            catch(Exception ex)
            {
                // Handle errors.
                ex.Message.ToString();
                messagePrint(false, "download");
            }
        }
开发者ID:sviom,项目名称:MoneyNote,代码行数:38,代码来源:BackupControl.xaml.cs


注:本文中的Microsoft.Live.LiveConnectClient.CreateBackgroundDownloadAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。