public void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) { if (!e.Cancelled && e.Error == null) { try { ActionFacebookPostHighScoreArg arg = _waiting[(WebClient)sender]; string data = e.Result; ScoreInformation succeed = new ScoreInformation(); succeed = JsonConvert.DeserializeObject <ScoreInformation>(data); if (succeed != null) { if (succeed.success) { arg.score_inform = new ScoreInformation(); arg.score_inform = succeed; Done(arg); _waiting.Remove((WebClient)sender); } } } catch (Exception ex) { } } }
//Bo add static public void UpdateNewScore(int score, ServerStream stream, Actions.DelegateBegin onBegin, Actions.DelegateDone onDone, Actions.DelegateCancel onCancel) { Actions.ActionFacebookPostHighScoreArg arg_post_score = new Actions.ActionFacebookPostHighScoreArg(); Actions.ActionFacebookPostHighScore action_post_score = new Actions.ActionFacebookPostHighScore(); _stream_wating.Add(action_post_score, stream); try { if (onBegin != null) { action_post_score.OnBegin += onBegin; } action_post_score.OnDone += action_post_score_OnDone; if (onCancel != null) { action_post_score.OnCancel += onCancel; } arg_post_score.Score = score; stream.Status = (int)ServerStreamStatus.STREAM_STATUS_REQUESTING; action_post_score.Do(arg_post_score); } catch (Exception ex) { stream.ErrorCode = 1; stream.Status = (int)ServerStreamStatus.STREAM_STATUS_ERROR; } }
public override void Do(ActionArgs e) { Begin(e); if (precheckToDo(e)) { WebClient client = new WebClient(); _waiting.Add(client, e as ActionFacebookPostHighScoreArg); ActionFacebookPostHighScoreArg arg = new ActionFacebookPostHighScoreArg(); arg = e as ActionFacebookPostHighScoreArg; client.UploadStringCompleted += client_UploadStringCompleted; client.UploadStringAsync(new Uri("https://graph.facebook.com/me/scores"), "POST", "score=" + arg.Score.ToString() + "&access_token=" + FacebookClient.Instance.Token); } }
static public void action_post_score_OnDone(object sender, Actions.ActionArgs e) { Actions.ActionFacebookPostHighScoreArg arg = e as Actions.ActionFacebookPostHighScoreArg; if (arg != null) { if (arg.score_inform.success) { ServerStream svstream = _stream_wating[(Actions.Action)sender]; svstream.Status = (int)ServerStreamStatus.STREAM_STATUS_RESPONSED; _stream_wating.Remove((Actions.Action)sender); } else { ServerStream svstream = _stream_wating[(Actions.Action)sender]; svstream.Status = (int)ServerStreamStatus.STREAM_STATUS_ERROR; _stream_wating.Remove((Actions.Action)sender); } } }