public string Save(string title, string section, string text, string summary, MinorFlags minor, CreateFlags create, WatchFlags watch, SaveFlags mode, bool bot, string basetimestamp, string starttimestamp, string token) { if (string.IsNullOrEmpty(title)) { throw new ArgumentException("Title shouldn't be empty.", "title"); } if (string.IsNullOrEmpty(token)) { throw new ArgumentException("Token shouldn't be empty.", "token"); } ParameterCollection parameters = new ParameterCollection { { "title", title }, { "token", token } }; if (mode == SaveFlags.Replace && !string.IsNullOrEmpty(section)) { parameters.Add("section", section); } if (minor != MinorFlags.None) { parameters.Add(minor.ToString().ToLower()); } if (create != CreateFlags.None) { parameters.Add(create.ToString().ToLower()); } if (watch != WatchFlags.None) { parameters.Add("watchlist", watch.ToString().ToLower()); } if (mode == SaveFlags.Append) { parameters.Add("appendtext", text); } else if (mode == SaveFlags.Prepend) { parameters.Add("prependtext", text); } else { parameters.Add("text", text); } if (bot) { parameters.Add("bot"); } if (!string.IsNullOrEmpty(basetimestamp)) { parameters.Add("basetimestamp", basetimestamp); } if (!string.IsNullOrEmpty(starttimestamp)) { parameters.Add("starttimestamp", starttimestamp); } if (!string.IsNullOrEmpty(summary)) { parameters.Add("summary", summary); } try { XmlDocument xml = MakeRequest(Action.Edit, parameters); XmlNode result = xml.SelectSingleNode("//edit[@newrevid]"); if (result != null) { return result.Attributes["newrevid"].Value; } } catch (WebException e) { throw new WikiException("Saving failed", e); } return null; }
public void Upload(string filename, string comment, string text, string token, WatchFlags watch, byte[] data, string contentType, bool ignoreWarnings) { if (string.IsNullOrEmpty(filename)) { throw new ArgumentException("File name shouldn't be empty.", "filename"); } if (string.IsNullOrEmpty(token)) { throw new ArgumentException("Token shouldn't be empty.", "token"); } if (data == null || data.Length == 0) { throw new ArgumentException("Data shouldn't be empty.", "data"); } ParameterCollection parameters = new ParameterCollection { { "filename", filename }, { "token", token }, }; if (!string.IsNullOrEmpty(text)) { parameters.Add("text", text); } if (!string.IsNullOrEmpty(comment)) { parameters.Add("comment", comment); } if (watch != WatchFlags.None) { parameters.Add("watch", watch.ToString().ToLower()); } if (ignoreWarnings) { parameters.Add("ignorewarnings"); } try { MakeMultipartFormRequest(parameters, filename, contentType, data); } catch (WebException e) { throw new WikiException("Upload failed", e); } }