예제 #1
0
파일: Listener.cs 프로젝트: agross/watchr
 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)));
 }
예제 #2
0
        /// <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;
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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");
            }
        }
예제 #6
0
        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");
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
 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";
     }
 }
예제 #9
0
파일: AsyncApiEdit.cs 프로젝트: svick/AWB
 public void Save(string pageText, string summary, bool minor, WatchOptions watch)
 {
     InvokeFunction("Save", pageText, summary, minor, watch);
 }
예제 #10
0
 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";
     }
 }
예제 #11
0
 public void Save(string pageText, string summary, bool minor, WatchOptions watch, string contentModel = "wikitext")
 {
     InvokeFunction("Save", pageText, summary, minor, watch, contentModel);
 }
예제 #12
0
 public void Save(string pageText, string summary, bool minor, WatchOptions watch)
 {
     InvokeFunction("Save", pageText, summary, minor, watch);
 }
예제 #13
0
        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);
        }
예제 #14
0
파일: Listener.cs 프로젝트: agross/watchr
 static FileSystemWatcher CreateFileSystemWatcher(WatchOptions watchOptions)
 => new(watchOptions.Directory, watchOptions.Pattern)
예제 #15
0
파일: Listener.cs 프로젝트: agross/watchr
 public Listener(ILogger <Listener> logger, WatchOptions watchOptions)
 {
     _logger       = logger;
     _watchOptions = watchOptions;
 }