static private void ExportCommentsBody(Journal.OptionsRow or, ILJServer iLJ, SessionGenerateResponse sgr, int serverMaxID, int localMaxID, CommentCollection cc) { // note that the export comments body web request may be called more than once int maxID = localMaxID; while (maxID < serverMaxID) { Uri uri = new Uri(new Uri(or.ServerURL), string.Format(_exportcommentsbodypath, maxID + 1)); if (!or.IsUseJournalNull()) { uri = new Uri(uri.AbsoluteUri + string.Format("&authas={0}", or.UseJournal)); } HttpWebRequest w = HttpWebRequestFactory.Create(uri.AbsoluteUri, sgr.ljsession); socb(new SyncOperationEventArgs(SyncOperation.ExportCommentsBody, maxID - localMaxID, serverMaxID - localMaxID)); using (Stream s = w.GetResponse().GetResponseStream()) { System.Text.Encoding ec; if (System.Environment.Version.Major == 1) // .NET 2.0 utf8 cleans strings, so we don't have to { ec = new UTF8Clean(); } else { ec = System.Text.Encoding.UTF8; } StreamReader sr = new StreamReader(s, ec); XmlCommentReader xcr = new XmlCommentReader(sr); while (xcr.Read()) { cc.Add(xcr.Comment); } xcr.Close(); } maxID = cc.GetMaxID(); } }
static public string GetDefaultPicURL(string journalName, string serverURL, bool community) { Uri uri = new Uri(new Uri(serverURL), string.Format(_foafpath, (community ? "community" : "users"), journalName)); HttpWebRequest w = HttpWebRequestFactory.Create(uri.AbsoluteUri, null); string picURL = null; using (System.IO.Stream s = w.GetResponse().GetResponseStream()) { System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(s); while (xr.Read()) { if (xr.NodeType == System.Xml.XmlNodeType.Element && xr.Name == "foaf:img") { picURL = xr.GetAttribute("rdf:resource"); break; } } xr.Close(); } return(picURL); }
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(); } }