当前位置: 首页>>代码示例>>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;未经允许,请勿转载。