Today I experimented with WP7 applications and came across a wall a bit. I like the separation between the user interface and the main application code, but I hit the wall.
I successfully executed the webclient request and got the result, but since the isync call, I don’t know how to transfer this backup to the user interface level. I can’t hack while waiting for an answer to everything or something else. I have to do something wrong.
(this is the xbox360Voice library that I have to download on my website: http://www.jamesstuddart.co.uk/Projects/ASP.Net/Xbox_Feeds/ , which I port to WP7 as a test)
here is a snippet of code:
internal const string BaseUrlFormat = "http://www.360voice.com/api/gamertag-profile.asp?tag={0}"; internal static string ResponseXml { get; set; } internal static WebClient Client = new WebClient(); public static XboxGamer? GetGamer(string gamerTag) { var url = string.Format(BaseUrlFormat, gamerTag); var response = GetResponse(url, null, null); return SerializeResponse(response); } internal static XboxGamer? SerializeResponse(string response) { if (string.IsNullOrEmpty(response)) { return null; } var tempGamer = new XboxGamer(); var gamer = (XboxGamer)SerializationMethods.Deserialize(tempGamer, response); return gamer; } internal static string GetResponse(string url, string userName, string password) { if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { Client.Credentials = new NetworkCredential(userName, password); } try { Client.DownloadStringCompleted += ClientDownloadStringCompleted; Client.DownloadStringAsync(new Uri(url)); return ResponseXml; } catch (Exception ex) { return null; } } internal static void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { ResponseXml = e.Result; } }
and this is the front end code:
public void GetGamerDetails() { var xboxManager = XboxFactory.GetXboxManager("DarkV1p3r"); var xboxGamer = xboxManager.GetGamer(); if (xboxGamer.HasValue) { var profile = xboxGamer.Value.Profile[0]; imgAvatar.Source = new BitmapImage(new Uri(profile.ProfilePictureMiniUrl)); txtUserName.Text = profile.GamerTag; txtGamerScore.Text = int.Parse(profile.GamerScore).ToString("G 0,000"); txtZone.Text = profile.PlayerZone; } else { txtUserName.Text = "Failed to load data"; } }
Now I understand that I need to put something in ClientDownloadStringCompleted , but I'm not sure what.
asynchronous windows-phone-7
Jamesstuddart
source share