/// Synchronous submission api method. public SubmissionResponse SubmitScore(string level, Score score) { // Ensure arguments are valid if (level == null) { throw new ArgumentNullException(); } score.Validate(); Connect(); // form a submission message and send it to the server string request = SubmissionRequest.ToJson(level, score); WriteLine(request); // get the response and convert back to an object string response = ReadLine(); SubmissionResponse position = SubmissionResponse.FromJson(response); Disconnect(); // report back to user return(position); }
/// Asynchronous submission api method. /// Most work is pushed off to an OnConnect callback. public void SubmitScoreAsync(string level, Score score, Action <SubmissionResponse, ServerException> callback) { // Ensure arguments are valid if (level == null) { throw new ArgumentNullException(); } score.Validate(); // external callback and argument container SubmitScoreState state = new SubmitScoreState(level, score, callback); // make the async connection with the onconnect callback ConnectAsync(new AsyncCallback(SubmitScoreOnConnectCallback), state); }