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