private IList <object> MultiqueryParsed(FqlMultiQueryInfo[] queries, bool isAsync, MultiqueryParsedCallback callback, Object state) { var parameterList = new Dictionary <string, string> { { "method", "facebook.fql.multiquery" } }; var qdict = new Dictionary <string, string>(); MultiQueryInfoState qstate = new MultiQueryInfoState() { Queries = queries, Callback = callback, }; foreach (FqlMultiQueryInfo query in queries) { qdict.Add(query.Key, query.Query); } Utilities.AddJSONAssociativeArray(parameterList, "queries", qdict); if (isAsync) { AsyncResult result = new AsyncResult(OnMultiQueryCompleted, qstate, state); SendRequestAsync(parameterList, !string.IsNullOrEmpty(Session.SessionKey), result); return(null); } var response = SendRequest <IList <object> >(parameterList, !string.IsNullOrEmpty(Session.SessionKey)); return(response == null ? null : response); }
void OnMultiQueryCompleted(IAsyncResult ar) { AsyncResult asyncResult = (AsyncResult)ar; MultiQueryInfoState qstate = (MultiQueryInfoState)asyncResult.AsyncState; Object[] results = new Object[qstate.Queries.Length]; FacebookException[] exceptions = new FacebookException[qstate.Queries.Length]; FacebookException ex = asyncResult.Exception; if (ex == null) { try { IList <fql_result> parsedResults = Utilities.DeserializeXML <fql_multiquery_response>(asyncResult.Result).fql_result; for (int i = 0; i < qstate.Queries.Length; i++) { string result = null; foreach (var parsedResult in parsedResults) { if (qstate.Queries[i].Key == parsedResult.name) { result = parsedResult.fql_result_set.ToString(); break; } } if (string.IsNullOrEmpty(result)) { exceptions[i] = new FacebookException("Could not deserialize data returned from server"); } else { try { results[i] = Utilities.DeserializeXML(result, qstate.Queries[i].Type); } catch (System.Reflection.TargetInvocationException e) { exceptions[i] = new FacebookException("Could not deserialize data", e.InnerException); } catch (FacebookException e) { exceptions[i] = e; } } } } catch (InvalidDataContractException e) { ex = new FacebookException("Could not deserialize data returned from server", e); } } if (ex != null) { for (int i = 0; i < exceptions.Length; i++) { exceptions[i] = asyncResult.Exception; } } if (qstate.Callback != null) { qstate.Callback(results, asyncResult.AsyncExternalState, exceptions); } }