Skip to content

Instantly share code, notes, and snippets.

@soarez
Created Aug 29, 2012
Embed
What would you like to do?
.NET async method
public async Task<string> UsersLoginAsync(string login, string password)
{
var url = "login.xml";
var template = @"
<?xml version=""1.0"" encoding=""UTF-8""?>
<credentials>
<login>{0}</login>
<password>{1}</password>
</credentials>
";
var request = string.Format(template, login, password);
var response = await this.PostAsync(url, request);
var accounts = response.Root.Elements("account").Select(Account.Parse);
return "accounts";
}
// WinR version
public IAsyncOperation<string> UsersLoginAsync(string login, string password)
{
return AsyncInfo.Run(async (ct) => {
var url = "login.xml";
var template = @"
<?xml version=""1.0"" encoding=""UTF-8""?>
<credentials>
<login>{0}</login>
<password>{1}</password>
</credentials>
";
var request = string.Format(template, login, password);
var response = await this.PostAsync(url, request);
var accounts = response.Root.Elements("account").Select(Account.Parse);
return "accounts";
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment