में कॉल करता है मैं आज WP7 ऐप्स के साथ प्रयोग कर रहा हूं और एक दीवार को थोड़ा सा मारा है। मुझे यूआई और मुख्य ऐप कोड के बीच पृथक्करण होना पसंद है लेकिन मैंने दीवार को मारा।Async WP7
मैंने सफलतापूर्वक एक वेब क्लाइंट अनुरोध लागू किया है और परिणाम प्राप्त किया है, लेकिन क्योंकि कॉल as ascc है, मुझे नहीं पता कि यह बैकअप यूआई स्तर पर कैसे पास किया जाए। मैं पूर्ण या कुछ भी प्रतिक्रिया के इंतजार में हैक लगाना प्रतीत नहीं कर सकता। मुझे कुछ गलत करना होगा।
(यह मैं अपनी वेबसाइट पर डाउनलोड के लिए है कि xbox360Voice पुस्तकालय है: http://www.jamesstuddart.co.uk/Projects/ASP.Net/Xbox_Feeds/ जो मैं एक परीक्षण के रूप WP7 के लिए पोर्टिंग हूँ):
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;
}
}
और इस
यहाँबैकएंड कोड स्निपेट है
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";
}
}
अब मैं समझता हूँ मैं ClientDownloadStringCompleted
में कुछ जगह की जरूरत है, लेकिन मैं अनिश्चित क्या हूँ: सामने के छोर कोड है।
"जैसा कि आप एसिंक प्रोग्रामिंग देख सकते हैं वास्तव में गन्दा हो सकता है।" ... जो एफ # का उपयोग करने का एक कारण है। एफ # के साथ आप सभी कॉलबैक-इनवर्जन-ऑफ-कंट्रोल somersaults किए बिना कोड को एसिंक को दोबारा कर सकते हैं। – Brian
@ ब्रायन: मैं पूरी तरह से सहमत हूं। मैं बस काम करता हूं कि कार्यात्मक प्रोग्रामिंग को और अधिक सुलभ बनाया जा सकता है, शायद यह युवा दिमागों के लिए है, लेकिन इससे कोई फर्क नहीं पड़ता कि मैं कितनी मेहनत करता हूं, मुझे अवधारणाओं को मेरे अंदर रखने के लिए नहीं मिल सकता है। – AnthonyWJones
बीमार यह कल जाने के लिए धन्यवाद – JamesStuddart