IObservable <EventPattern <FileSystemEventArgs> > ForceRefresh(WatchOptions watchOptions, TimeSpan tick) { return(Observable.Timer(TimeSpan.Zero, tick) .SelectMany(_ => Directory.GetFiles(watchOptions.Directory, watchOptions.Pattern) .ToArray() .Select(f => new FileSystemEventArgs(WatcherChangeTypes.Changed, Path.GetDirectoryName(f), Path.GetFileName(f)))) .Select(e => new EventPattern <FileSystemEventArgs>(this, e))); }
/// <summary> /// Constructor. /// </summary> /// <param name="options">Watch CLI options.</param> public WatchAction(WatchOptions options) { _options = options; _compiler = new CompileAction(CompileOptions.FromWatchOptions(options), true); _logger = new WatcherLogger(); _timer = new Timer { AutoReset = true, Interval = 200 }; _timer.Elapsed += OnRecompile; }
/// <summary> /// Runs the watch action. /// </summary> /// <param name="options">CLI options for the watch action.</param> /// <param name="fromMain">Wheter or not this is called from the main method.</param> /// <returns>CLI return code.</returns> private static int Watch(WatchOptions options, bool fromMain = true) { WatchAction watcher = new WatchAction(options); int result = watcher.Run(); #if DEBUG if (fromMain == true) { Console.Read(); } #endif return(result); }
public SaveInfo Save(string pageText, string summary, bool minor, WatchOptions watch) { if (string.IsNullOrEmpty(pageText) && !Page.Exists) { throw new ArgumentException("Can't save empty pages", "pageText"); } //if (string.IsNullOrEmpty(summary)) //{ // throw new ArgumentException("Edit summary required", "summary"); //} if (Action != "edit") { throw new ApiException(this, "This page is not opened properly for editing"); } if (string.IsNullOrEmpty(Page.EditToken)) { throw new ApiException(this, "Edit token is needed to edit pages"); } pageText = Tools.ConvertFromLocalLineEndings(pageText); string result = HttpPost( new[, ] { { "action", "edit" }, { "title", Page.Title }, { minor ? "minor" : null, null }, { "watchlist", WatchOptionsToParam(watch) }, { User.IsBot ? "bot" : null, null } }, new[, ] { // order matters here - https://bugzilla.wikimedia.org/show_bug.cgi?id=14210#c4 { "md5", MD5(pageText) }, { "summary", summary }, { "basetimestamp", Page.Timestamp }, { "text", pageText }, { "starttimestamp", Page.TokenTimestamp }, { "token", Page.EditToken } }, ActionOptions.All); var xml = CheckForErrors(result, "edit"); Reset(); return(new SaveInfo(xml)); }
protected static string WatchOptionsToParam(WatchOptions watch) { switch (watch) { case WatchOptions.UsePreferences: return("preferences"); case WatchOptions.Watch: return("watch"); case WatchOptions.Unwatch: return("unwatch"); default: return("nochange"); } }
protected static string WatchOptionsToParam(WatchOptions watch) { // Here we provide options for both 1.16 and older versions switch (watch) { case WatchOptions.UsePreferences: return("preferences"); case WatchOptions.Watch: return("watch&watch"); case WatchOptions.Unwatch: return("unwatch&unwatch"); default: return("nochange"); } }
public SaveInfo Save(string pageText, string summary, bool minor, WatchOptions watch) { if (string.IsNullOrEmpty(pageText) && !Page.Exists) throw new ArgumentException("Can't save empty pages", "pageText"); //if (string.IsNullOrEmpty(summary)) throw new ArgumentException("Edit summary required", "summary"); if (Action != "edit") throw new ApiException(this, "This page is not opened properly for editing"); if (string.IsNullOrEmpty(Page.EditToken)) throw new ApiException(this, "Edit token is needed to edit pages"); pageText = Tools.ConvertFromLocalLineEndings(pageText); string result = HttpPost( new[,] { { "action", "edit" }, { "title", Page.Title }, { minor ? "minor" : null, null }, { WatchOptionsToParam(watch), null }, { User.IsBot ? "bot" : null, null } }, new[,] {// order matters here - https://bugzilla.wikimedia.org/show_bug.cgi?id=14210#c4 { "md5", MD5(pageText) }, { "summary", summary }, { "basetimestamp", Page.Timestamp }, { "text", pageText }, { "starttimestamp", Page.TokenTimestamp }, { "token", Page.EditToken } }, ActionOptions.All); var xml = CheckForErrors(result, "edit"); Reset(); return new SaveInfo(xml); }
protected static string WatchOptionsToParam(WatchOptions watch) { // Here we provide options for both 1.16 and older versions switch (watch) { case WatchOptions.UsePreferences: return "watchlist=preferences"; case WatchOptions.Watch: return "watchlist=watch&watch"; case WatchOptions.Unwatch: return "watchlist=unwatch&unwatch"; default: return "watchlist=nochange"; } }
public void Save(string pageText, string summary, bool minor, WatchOptions watch) { InvokeFunction("Save", pageText, summary, minor, watch); }
protected static string WatchOptionsToParam(WatchOptions watch) { switch (watch) { case WatchOptions.UsePreferences: return "preferences"; case WatchOptions.Watch: return "watch"; case WatchOptions.Unwatch: return "unwatch"; default: return "nochange"; } }
public void Save(string pageText, string summary, bool minor, WatchOptions watch, string contentModel = "wikitext") { InvokeFunction("Save", pageText, summary, minor, watch, contentModel); }
public void Save(string pageText, string summary, bool minor, WatchOptions watch) { InvokeFunction("Save", pageText, summary, minor, watch); }
public SaveInfo Save(string pageText, string summary, bool minor, WatchOptions watch) { if (string.IsNullOrEmpty(pageText) && !Page.Exists) { throw new ArgumentException("Can't save empty pages", "pageText"); } // if (string.IsNullOrEmpty(summary)) // { // throw new ArgumentException("Edit summary required", "summary"); // } if (Action != "edit") { throw new ApiException(this, "This page is not opened properly for editing"); } if (string.IsNullOrEmpty(Page.EditToken)) { throw new ApiException(this, "Edit token is needed to edit pages"); } pageText = Tools.ConvertFromLocalLineEndings(pageText); var get = new Dictionary<string, string> { {"action", "edit"}, {"title", Page.Title}, {"watchlist", WatchOptionsToParam(watch)}, }; get.AddIfTrue(minor, "minor", null); get.AddIfTrue(User.IsBot, "bot", null); string result = HttpPost( get, new Dictionary<string, string> { // order matters here - https://phabricator.wikimedia.org/T16210#183159 {"md5", MD5(pageText)}, {"summary", summary}, {"basetimestamp", Page.Timestamp}, {"text", pageText}, {"starttimestamp", Page.TokenTimestamp}, {"token", Page.EditToken} }, ActionOptions.All); var xml = CheckForErrors(result, "edit"); Reset(); return new SaveInfo(xml); }
static FileSystemWatcher CreateFileSystemWatcher(WatchOptions watchOptions) => new(watchOptions.Directory, watchOptions.Pattern)
public Listener(ILogger <Listener> logger, WatchOptions watchOptions) { _logger = logger; _watchOptions = watchOptions; }