Created
February 8, 2014 12:16
-
-
Save eternaltung/8882803 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Microsoft.Live; | |
using Windows.UI.Popups; | |
using System.Collections.Generic; | |
namespace LiveSDKSample | |
{ | |
public sealed partial class MainPage : Page | |
{ | |
LiveConnectClient liveClient; | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
} | |
private async void LoginButton_Click(object sender, RoutedEventArgs e) | |
{ | |
try | |
{ | |
LiveAuthClient auth = new LiveAuthClient(); | |
LiveLoginResult loginresult = await auth.LoginAsync(new string[] | |
{ | |
"wl.signin", | |
"wl.basic", | |
"wl.skydrive", | |
"wl.skydrive_update" | |
}); | |
if (loginresult.Status == LiveConnectSessionStatus.Connected) | |
{ | |
liveClient = new LiveConnectClient(loginresult.Session); | |
LiveOperationResult operationresult = await liveClient.GetAsync("me"); | |
MessageDialog msg = new MessageDialog(string.Format("Name:{0}", | |
operationresult.Result["name"] | |
)); | |
await msg.ShowAsync(); | |
} | |
} | |
catch (LiveAuthException ex) | |
{ | |
MessageDialog msg = new MessageDialog(ex.Message); | |
msg.ShowAsync(); | |
} | |
} | |
private async void CreateButton_Click(object sender, RoutedEventArgs e) | |
{ | |
try | |
{ | |
Dictionary<string, object> newfolder = new Dictionary<string, object>(); | |
newfolder.Add("name", "testfolder"); //testfolder是要建立的資料夾名稱 | |
LiveOperationResult operationresult = await liveClient.PostAsync("me/skydrive", newfolder); | |
MessageDialog msg = new MessageDialog(string.Format("FolderName:{0}\nID:{1}", | |
operationresult.Result["name"], | |
operationresult.Result["id"] | |
)); | |
await msg.ShowAsync(); | |
} | |
catch (LiveConnectException ex) | |
{ | |
MessageDialog msg = new MessageDialog(ex.Message); | |
msg.ShowAsync(); | |
} | |
} | |
private async void GetButton_Click(object sender, RoutedEventArgs e) | |
{ | |
try | |
{ | |
LiveOperationResult operationResult = await liveClient.GetAsync("me/skydrive/files"); | |
List<object> data = (List<object>)operationResult.Result["data"]; | |
FolderBox.Items.Clear(); | |
foreach (dynamic item in data) | |
{ | |
//將資料夾的ID記在Tag中方便做update和delete | |
FolderBox.Items.Add(new ListBoxItem() | |
{ | |
Content = item.name, | |
Tag = item.id | |
}); | |
} | |
} | |
catch (LiveConnectException ex) | |
{ | |
MessageDialog msg = new MessageDialog(ex.Message); | |
msg.ShowAsync(); | |
} | |
} | |
private async void DeleteButton_Click(object sender, RoutedEventArgs e) | |
{ | |
try | |
{ | |
if (FolderBox.SelectedItem != null) | |
{ | |
//DeleteAsync中傳入要刪除的資料夾ID | |
LiveOperationResult operationresult = await liveClient.DeleteAsync((FolderBox.SelectedItem as ListBoxItem).Tag.ToString()); | |
MessageDialog msg = new MessageDialog("Folder deleted"); | |
await msg.ShowAsync(); | |
} | |
} | |
catch (LiveConnectException ex) | |
{ | |
MessageDialog msg = new MessageDialog(ex.Message); | |
msg.ShowAsync(); | |
} | |
} | |
private async void UpdateButton_Click(object sender, RoutedEventArgs e) | |
{ | |
try | |
{ | |
if (FolderBox.SelectedItem != null) | |
{ | |
Dictionary<string, object> updatefolder = new Dictionary<string, object>(); | |
updatefolder.Add("name", "updatefolder"); | |
//PutAsync中傳入要更新的資料夾ID | |
LiveOperationResult operationresult = await liveClient.PutAsync((FolderBox.SelectedItem as ListBoxItem).Tag.ToString(), updatefolder); | |
MessageDialog msg = new MessageDialog("Folder updated"); | |
await msg.ShowAsync(); | |
} | |
} | |
catch (LiveConnectException ex) | |
{ | |
MessageDialog msg = new MessageDialog(ex.Message); | |
msg.ShowAsync(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment