private int CreateDekiPage(Plug p, string pagePath, string pageTitle, DateTime?modified, string content, out string dekiPageUrl) { Log.DebugFormat("Creating page: '{0}' Content? {1}", XUri.DoubleDecode(pagePath), !string.IsNullOrEmpty(content)); Plug pagePlug = p.At("pages", "=" + pagePath, "contents"); pagePlug = pagePlug.With("abort", "never"); modified = modified ?? DateTime.Now; string editTime = Utils.FormatPageDate(modified.Value.ToUniversalTime()); pagePlug = pagePlug.With("edittime", editTime); pagePlug = pagePlug.With("comment", "Created at " + modified.Value.ToShortDateString() + " " + modified.Value.ToShortTimeString()); if (pageTitle != null) { pagePlug = pagePlug.With("title", pageTitle); } DreamMessage msg = DreamMessage.Ok(MimeType.TEXT_UTF8, content); DreamMessage res = pagePlug.PostAsync(msg).Wait(); if (res.Status != DreamStatus.Ok) { WriteLineToConsole("Error converting page \"" + XUri.DoubleDecode(pagePath) + "\""); WriteLineToLog("Edit time: " + editTime); WriteLineToLog("Page title: " + pageTitle); WriteErrorResponse(res); WriteErrorRequest(msg); } else { XDoc createdPage = res.AsDocument(); int pageId = createdPage["page/@id"].AsInt.Value; //dekiPageUrl = createdPage["page/path"].AsText; //Using the uri.ui instead of path to not worry about encodings for links //But this makes the values (mt urls) in the link mapping table unsuitable for page paths //(such as those used in dekiscript for macros). Those need to be converted to paths // via Utils.ConvertPageUriToPath dekiPageUrl = createdPage["page/uri.ui"].AsText; return(pageId); } dekiPageUrl = null; return(-1); }
public static string GetPageName(Plug p, string pageid) // name == final path segment { DreamMessage msg = p.At("pages", pageid).Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed"); string uri = msg.ToDocument()["uri.ui"].AsText ?? String.Empty; int lastSlashIndex = uri.LastIndexOf("/"); if (lastSlashIndex == -1) { return(String.Empty); } string name = XUri.DoubleDecode(uri.Substring(lastSlashIndex + 1)); return(name); }
private int CreateDekiPageHistory(Plug p, string pagePath, string pageTitle, DateTime?modified, string content, out string dekiPageUrl) { Log.DebugFormat("Creating page history: '{0}' Content? {1}", XUri.DoubleDecode(pagePath), !string.IsNullOrEmpty(content)); Plug pagePlug = p.At("pages", "=" + pagePath, "revision"); pagePlug = pagePlug.With("abort", "never"); modified = modified ?? DateTime.Now; string editTime = Utils.FormatPageDate(modified.Value.ToUniversalTime()); pagePlug = pagePlug.With("edittime", editTime); if (pageTitle != null) { pagePlug = pagePlug.With("title", pageTitle); } DreamMessage msg = DreamMessage.Ok(MimeType.TEXT_UTF8, content); DreamMessage res = pagePlug.PostAsync(msg).Wait(); if (res.Status != DreamStatus.Ok) { WriteLineToConsole("Error converting page \"" + XUri.DoubleDecode(pagePath) + "\""); WriteLineToLog("Edit time: " + editTime); WriteLineToLog("Page title: " + pageTitle); WriteErrorResponse(res); WriteErrorRequest(msg); Log.WarnFormat("Error converting page: '{0}'. Request: {0} \nResponse: {1}", msg.ToString(), res.ToString()); } else { XDoc createdPage = res.AsDocument(); int pageId = createdPage["page/@id"].AsInt.Value; dekiPageUrl = createdPage["page/path"].AsText; return(pageId); } dekiPageUrl = null; return(-1); }
public static string DoubleUrlDecode(string url) { return(XUri.DoubleDecode(url)); }