public AtomEntry updateWebpage(String path, String title, String html, String pageName, DateTime lastModified, bool isIndexPage, string indexHtmlPath = "") { if (cancel()) { return(null); } String url = "https://sites.google.com/feeds/content/site/" + m_siteName + "?path=" + path + (pageName == "" ? "" : "/") + pageName; printMessage(url); try { AtomEntry entry = m_service.Get(url); if (entry == null) { return(createWebPage(url, path, title, html, pageName, lastModified, isIndexPage)); } if (html != "") { double diff = 0; if (m_lastRunTimes.ContainsKey(url)) { DateTime lastRunTime = DateTime.Parse((String)m_lastRunTimes[url]); TimeSpan dt = lastModified - lastRunTime; diff = Math.Abs(dt.TotalSeconds); } if (!m_lastRunTimes.ContainsKey(url) || diff > 1) { AtomContent newContent = new AtomContent(); newContent.Type = "html"; newContent.Content = m_replaceLinks ? replaceLinks(html, url, isIndexPage, indexHtmlPath) : html; entry.Content = newContent; entry.Title.Text = m_convertCase ? IndianBridge.Common.Utilities.ConvertCaseString(title) : title; m_service.Update(entry); if (!m_lastRunTimes.ContainsKey(url)) { printMessage("UPDATED. No entry was found for last run time."); } else { DateTime lastRunTime = DateTime.Parse((String)m_lastRunTimes[url]); printMessage("UPDATED. (Last Modified Time " + lastModified.ToString() + " is later than last update time " + lastRunTime.ToString() + ")"); } m_lastRunTimes[url] = lastModified; } else { DateTime lastRunTime = DateTime.Parse((String)m_lastRunTimes[url]); printMessage("NOT UPDATED. (Last Modified Time " + lastModified.ToString() + " is earlier than (or equal to) last update time " + lastRunTime.ToString() + ")"); } } numberOfPagesAlreadyUploaded++; reportProgress(title); return(entry); } catch (Exception) { return(createWebPage(url, path, title, html, pageName, lastModified, isIndexPage, indexHtmlPath)); } }
public static Boolean checkCredentials(String url, String username, String password) { SitesService service = new SitesService(APP_NAME); service.setUserCredentials(username, password); try { AtomEntry entry = service.Get(url); if (entry.Title.Text.EndsWith(" ")) { entry.Title.Text = entry.Title.Text.Substring(0, entry.Title.Text.Length - 1); } else { entry.Title.Text += " "; } service.Update(entry); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); return(false); } return(true); }