Skip to content

Instantly share code, notes, and snippets.

@kenegozi
Created August 29, 2012 00:38
Show Gist options
  • Save kenegozi/3505665 to your computer and use it in GitHub Desktop.
Save kenegozi/3505665 to your computer and use it in GitHub Desktop.
First glance on my unofficial Windows Phone SDK for Azure Mobile Services
// in App.xaml.cs
public partial class App : Application
{
public static readonly MobileServiceClient MobileServiceClient;
public static User CurrentUser;
static App()
{
// Get this data from the management portal's quickstart page
// in the 'connect to existing apps' section
MobileServiceClient = new MobileServiceClient(
"https://YOUR_APP.azure-mobile.net/",
"YOUR_APP_KEY"
);
}
// the rest of App.xaml.cs here ...
}
// elsewhere:
MobileServiceTable<TodoItem> todoItemTable = App.MobileServiceClient.GetTable<TodoItem>();
// insert
var item = new TodoItem { Text = "Do this!" };
todoItemTable.Insert(item, (res, err) => {
if (err != null) {
//handle it
return;
}
item = res;
});
// Update (sorry, no typed version yet):
var updates = new JObject();
updates["text"] = "The text";
todoItemTable.Update(updates, err => {
if (err != null) {
//handle it
}
});
// Get all
todoItemTable.GetAll((res, err) => {
if (err != null) {
//handle it
return;
}
foreach (TodoItem in res) {
}
});
// OData query
var query = new MobileServiceQuery()
.Filter("text eq 'whatever'")
.Top(1)
.Skip(2)
.OrderBy("id desc");
todoItemTable.Get(query, (res, err) => {
if (err != null) {
//handle it
return;
}
foreach (TodoItem in res) {
}
});
// delete
testStuffTable.Delete(item.Id, err => {
if (err != null) {
//handle it
}
});
// login to Azure Mobile Services with the AuthenticationToken returned
// from LiveAuthClient or the LiveLoginButton's SessionChanged event
App.MobileServiceClient.Login(e.Session.AuthenticationToken, (userId, err) => {
// do something with userId, perhaps call to LiveConnect for user details, etc.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment