示例#1
0
        static private void ExportCommentsMeta(Journal.OptionsRow or, ILJServer iLJ, SessionGenerateResponse sgr,
                                               ref int serverMaxID, int localMaxID, UserMapCollection umc, CommentCollection cc)
        {
            // this is a an unfortunately necessary step
            // we call export comments meta is to get the user map and to check if comment state has changed
            // it would be better to be able to provide a lastsync, but alas
            // see http://www.livejournal.com/developer/exporting.bml for more info
            int maxID = -1;

            while (maxID < serverMaxID)
            {
                Uri uri = new Uri(new Uri(or.ServerURL), string.Format(_exportcommentsmetapath, maxID + 1));
                if (!or.IsUseJournalNull())
                {
                    uri = new Uri(uri.AbsoluteUri + string.Format("&authas={0}", or.UseJournal));
                }
                HttpWebRequest w = HttpWebRequestFactory.Create(uri.AbsoluteUri, sgr.ljsession);
                using (Stream s = w.GetResponse().GetResponseStream())
                {
                    XmlTextReader xtr = new XmlTextReader(s);
                    while (xtr.Read())
                    {
                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "usermap")
                        {
                            string id   = xtr.GetAttribute("id");
                            string user = xtr.GetAttribute("user");
                            if (id != null && user != null && !umc.ContainsID(XmlConvert.ToInt32(id)))
                            {
                                umc.Add(new UserMap(XmlConvert.ToInt32(id), user));
                            }
                        }
                        else if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "maxid")
                        {
                            xtr.Read();
                            serverMaxID = XmlConvert.ToInt32(xtr.Value);
                            socb(new SyncOperationEventArgs(SyncOperation.ExportCommentsMeta, Math.Max(maxID, 0), serverMaxID));
                        }
                        else if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "comment")
                        {
                            string id       = xtr.GetAttribute("id");
                            string posterid = xtr.GetAttribute("posterid");
                            string state    = xtr.GetAttribute("state");
                            if (posterid == null)
                            {
                                posterid = "0";
                            }
                            if (state == null)
                            {
                                state = "A";
                            }
                            if (id != null)
                            {
                                cc.Add(new Comment(XmlConvert.ToInt32(id), XmlConvert.ToInt32(posterid),
                                                   state, 0, 0, string.Empty, string.Empty, DateTime.MinValue));
                            }
                        }
                        else if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "h2")
                        {
                            xtr.Read();
                            if (xtr.Value == "Error" && !or.IsUseJournalNull())
                            {
                                throw new ExpectedSyncException(ExpectedError.CommunityAccessDenied, null);
                            }
                        }
                    }
                    xtr.Close();
                }
                maxID = cc.GetMaxID();
            }
        }