當前位置: 首頁>>代碼示例>>C#>>正文


C# FileSystemWatcher.CreateObservableForRenamed方法代碼示例

本文整理匯總了C#中System.IO.FileSystemWatcher.CreateObservableForRenamed方法的典型用法代碼示例。如果您正苦於以下問題:C# FileSystemWatcher.CreateObservableForRenamed方法的具體用法?C# FileSystemWatcher.CreateObservableForRenamed怎麽用?C# FileSystemWatcher.CreateObservableForRenamed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.FileSystemWatcher的用法示例。


在下文中一共展示了FileSystemWatcher.CreateObservableForRenamed方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EvaluateEx

        public override string EvaluateEx(ParsedLine line)
        {
            if (line.IsCommand && line.Command.ToLower() == "unwatch")
            {
                if (line.Args.Length < 1)
                {
                    return "!unwatch [path]";
                }

                // Request that this path no longer be watched
                _unwatch.OnNext(line.Args[0]);

                return null;
            }

            if (!line.IsCommand || line.Command.ToLower() != "watch")
            {
                return null;
            }

            string help = "!watch [path]";

            // Verify we have enough arguments
            if (line.Args.Length < 1)
            {
                return help;
            }

            string path = line.Args[0];

            try
            {
                // Create a file system watcher for the requested folder
                var fsw = new FileSystemWatcher(path);
                fsw.EnableRaisingEvents = true;

                // Create observables for the Created, Deleted, and Renamed events from the file system watcher
                // Each one takes the events and converts them to a string description of the event
                var obsCreated = fsw.CreateObservableForCreated().Select(args => String.Format("{0} was created", args.Name));
                var obsDeleted = fsw.CreateObservableForDeleted().Select(args => String.Format("{0} was deleted", args.Name));
                var obsRenamed = fsw.CreateObservableForRenamed().Select(args => String.Format("{0} was renamed", args.Name));
                var txt = Observable.Return(String.Format("Watching for changes to {0}.", path));

                // Merge all the events into a single stream
                var changes =
                    txt.Concat(

                    obsCreated.Merge(obsDeleted).Merge(obsRenamed)
                                        .Merge(_unwatch.Where(s => s.Contains(path))) // Merge with the stream of unwatch requests which match this path
                                        .TakeWhile(args => args != path)); // end the sequence when we get a string that just matches the path (which would be from the unwatch)

                changes.Subscribe((msg) =>
                {
                    this.SendMessage(msg, line.From, BotMessageType.chat);
                });

                return null;
            }
            catch (Exception ex)
            {
                // Show the error in the chat - most likely it'll be an invalid path issue
                return ex.Message;
            }
        }
開發者ID:BrewAndCode,項目名稱:XmppBot-for-HipChat,代碼行數:64,代碼來源:WatchFolder.cs


注:本文中的System.IO.FileSystemWatcher.CreateObservableForRenamed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。