/// <summary>
 /// Initialises a result of a successful query
 /// </summary>
 /// <param name="responseString">String (possibly an XML code) returned by the query</param>
 public QueryResult(HttpFetcher fetcher, String responseString, Object tag)
 {
     this.fetcher = fetcher;
     this.responseString = responseString;
     this.exception = null;
     this.tag = tag;
 }
 /// <summary>
 /// Initialises a result of a query which ended with an exception
 /// </summary>
 /// <param name="exception">Exception which has occurred</param>
 public QueryResult(HttpFetcher fetcher, Exception exception, Object tag)
 {
     this.fetcher = fetcher;
     this.responseString = null;
     this.exception = exception;
     this.tag = tag;
 }
        private void HttpQueryExecutedCallback(HttpFetcher.QueryResult result)
        {
            FetchData fetchData = (FetchData)result.Tag;
            List<RecentChange> changes = new List<RecentChange>();
            if (result.WasSuccessful())
            {
                try
                {
                    XmlReaderSettings xmlSettings = new XmlReaderSettings { IgnoreComments = true, IgnoreWhitespace = true };
                    XmlReader xmlReader = XmlReader.Create(new System.IO.StringReader(result.ResponseString), xmlSettings);

                    String listRootElement;
                    String listItemElement;
                    if (fetchData.isItWatchlistQuery)
                    {
                        listRootElement = "watchlist";
                        listItemElement = "item";
                    }
                    else
                    {
                        listRootElement = "recentchanges";
                        listItemElement = "rc";
                    }

                    if (!xmlReader.ReadToDescendant(listRootElement))
                        throw new Exception("MediaWiki API returned an error"); //TODO better exception
                    xmlReader.ReadToDescendant(listItemElement);
                    while (xmlReader.NodeType != XmlNodeType.EndElement)
                    {
                        RecentChange change = new RecentChange();
                        while (xmlReader.MoveToNextAttribute())
                        {
                            switch (xmlReader.Name)
                            {
                                case "title":
                                    change.Title = xmlReader.Value;
                                    break;
                                case "pageid":
                                    change.PageId = xmlReader.ReadContentAsInt();
                                    break;
                                case "revid":
                                    change.RevId = xmlReader.ReadContentAsInt();
                                    break;
                                case "old_revid":
                                    change.OldRevId = xmlReader.ReadContentAsInt();
                                    break;
                                case "user":
                                    change.User = xmlReader.Value;
                                    break;
                                case "timestamp":
                                    change.Timestamp = xmlReader.ReadContentAsDateTime();
                                    break;
                                case "comment":
                                    change.Comment = xmlReader.Value;
                                    break;
                                case "bot":
                                    change.IsBot = true;
                                    break;
                                case "minor":
                                    change.IsMinor = true;
                                    break;
                                case "new":
                                    change.IsNew = true;
                                    break;
                            }//switch
                        }//while xmlReader.MoveToNextAttribute()
                        changes.Add(change);
                        xmlReader.ReadToNextSibling(listItemElement);
                    }//while xmlReader.NodeType != XmlNodeType.EndElement
                    Result rcResult = new Result(this, changes, fetchData.callerData);
                    fetchData.callback(rcResult);
                }//try
                catch (Exception e)
                {
                    Result rcResult = new Result(this, e, fetchData.callerData);
                    fetchData.callback(rcResult);
                }
            }//if
            else
            {
                fetchData.callback(new Result(this, result.OccurredException, fetchData.callerData));
            }
        }