示例#1
0
        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);
            }
        }