本文整理汇总了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;
}
}