本文整理汇总了C#中WatcherChangeTypes.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# WatcherChangeTypes.ToString方法的具体用法?C# WatcherChangeTypes.ToString怎么用?C# WatcherChangeTypes.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WatcherChangeTypes
的用法示例。
在下文中一共展示了WatcherChangeTypes.ToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: waitForChangedHandler
WaitForChangedResult waitForChangedHandler(string directoryPath, string filter,
WatcherChangeTypes watcherChangeTypes, int timeOut) {
if (watcherChangeTypes != WatcherChangeTypes.Created)
throw new NotImplementedException(watcherChangeTypes.ToString());
var filesList = new ArrayList(Directory.GetFiles(directoryPath, filter));
var waitForChangedResult = new WaitForChangedResult();
while (true) {
var newFilesList = new ArrayList(Directory.GetFiles(directoryPath, filter));
foreach (string file in newFilesList) {
if (!filesList.Contains(file)) {
waitForChangedResult.ChangeType = WatcherChangeTypes.Created;
waitForChangedResult.Name = file;
return waitForChangedResult;
}
}
}
}
示例2: MoveAndCheck_WithNotifyFilter
/// <summary>
/// Sets up watchers for the type given before performing a File.Move operation and checking for
/// events. If moveRaisesEvent is true, we make sure that the given event type is observed. If false,
/// we ensure that it is not observed.
///
/// This test will use the NotifyFilter attribute of the FileSystemWatcher before the move and subsequent
/// checks are made.
/// </summary>
private static void MoveAndCheck_WithNotifyFilter(WatcherChangeTypes eventType, bool moveRaisesEvent)
{
using (var file = Utility.CreateTestFile(Guid.NewGuid().ToString()))
using (var watcher = new FileSystemWatcher("."))
{
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.Filter = Path.GetFileName(file.Path);
AutoResetEvent eventOccurred = Utility.WatchForEvents(watcher, eventType);
string newName = file.Path + "_" + eventType.ToString();
Utility.EnsureDelete(newName);
watcher.EnableRaisingEvents = true;
file.Move(newName);
if (moveRaisesEvent)
Utility.ExpectEvent(eventOccurred, eventType.ToString());
else
Utility.ExpectNoEvent(eventOccurred, eventType.ToString());
}
}
示例3: MoveAndCheck_NestedDirectory
/// <summary>
/// Sets up watchers for the type given before performing a File.Move operation and checking for
/// events. If moveRaisesEvent is true, we make sure that the given event type is observed. If false,
/// we ensure that it is not observed.
///
/// This test will move the source file of a file within a nested directory
/// </summary>
private static void MoveAndCheck_NestedDirectory(WatcherChangeTypes eventType, bool moveRaisesEvent)
{
Utility.TestNestedDirectoriesHelper(eventType, (AutoResetEvent eventOccurred, TemporaryTestDirectory ttd) =>
{
using (var nestedFile = new TemporaryTestFile(Path.Combine(ttd.Path, "nestedFile" + eventType.ToString())))
{
nestedFile.Move(nestedFile.Path + "_2");
if (moveRaisesEvent)
Utility.ExpectEvent(eventOccurred, eventType.ToString());
else
Utility.ExpectNoEvent(eventOccurred, eventType.ToString());
}
});
}
示例4: MoveAndCheck_DifferentDirectory
/// <summary>
/// Sets up watchers for the type given before performing a File.Move operation and checking for
/// events. If moveRaisesEvent is true, we make sure that the given event type is observed. If false,
/// we ensure that it is not observed.
///
/// This test checks for when the file being moved has a destination directory that is outside of
/// the path of the FileSystemWatcher.
/// </summary>
private static void MoveAndCheck_DifferentDirectory(WatcherChangeTypes eventType, bool moveRaisesEvent)
{
using (var dir = Utility.CreateTestDirectory(Guid.NewGuid().ToString()))
using (var dir_unwatched = new TemporaryTestDirectory(Path.GetRandomFileName()))
using (var watcher = new FileSystemWatcher())
{
// put everything in our own directory to avoid collisions
watcher.Path = Path.GetFullPath(dir.Path);
watcher.Filter = "*.*";
// create a file
using (var testFile = new TemporaryTestFile(Path.Combine(dir.Path, "file")))
{
watcher.EnableRaisingEvents = true;
AutoResetEvent eventOccurred = Utility.WatchForEvents(watcher, eventType);
// Move the testFile to a different name in the same directory
testFile.Move(Path.Combine(dir_unwatched.Path, testFile.Name + "_" + eventType.ToString()));
// Test which events are thrown
if (moveRaisesEvent)
Utility.ExpectEvent(eventOccurred, eventType.ToString());
else
Utility.ExpectNoEvent(eventOccurred, eventType.ToString());
}
}
}
示例5: MoveAndCheck_WithNotifyFilter
/// <summary>
/// Sets up watchers for the type given before performing a File.Move operation and checking for
/// events. If moveRaisesEvent is true, we make sure that the given event type is observed. If false,
/// we ensure that it is not observed.
///
/// This test will use the NotifyFilter attribute of the FileSystemWatcher before the move and subsequent
/// checks are made.
/// </summary>
private void MoveAndCheck_WithNotifyFilter(WatcherChangeTypes eventType, bool moveRaisesEvent)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var file = new TempFile(Path.Combine(testDirectory.Path, GetTestFileName())))
using (var watcher = new FileSystemWatcher(testDirectory.Path))
{
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.Filter = Path.GetFileName(file.Path);
AutoResetEvent eventOccurred = WatchForEvents(watcher, eventType);
string newName = Path.Combine(testDirectory.Path, GetTestFileName());
watcher.EnableRaisingEvents = true;
File.Move(file.Path, newName);
if (moveRaisesEvent)
ExpectEvent(eventOccurred, eventType.ToString());
else
ExpectNoEvent(eventOccurred, eventType.ToString());
}
}
示例6: MoveAndCheck_NestedDirectory
/// <summary>
/// Sets up watchers for the type given before performing a File.Move operation and checking for
/// events. If moveRaisesEvent is true, we make sure that the given event type is observed. If false,
/// we ensure that it is not observed.
///
/// This test will move the source file of a file within a nested directory
/// </summary>
private void MoveAndCheck_NestedDirectory(WatcherChangeTypes eventType, bool moveRaisesEvent)
{
TestNestedDirectoriesHelper(GetTestFilePath(), eventType, (AutoResetEvent eventOccurred, TempDirectory ttd) =>
{
using (var nestedFile = new TempFile(Path.Combine(ttd.Path, "nestedFile" + eventType.ToString())))
{
File.Move(nestedFile.Path, nestedFile.Path + "_2");
if (moveRaisesEvent)
ExpectEvent(eventOccurred, eventType.ToString());
else
ExpectNoEvent(eventOccurred, eventType.ToString());
}
});
}
示例7: MoveAndCheck_SameDirectory
/// <summary>
/// Sets up watchers for the type given before performing a File.Move operation and checking for
/// events. If moveRaisesEvent is true, we make sure that the given event type is observed. If false,
/// we ensure that it is not observed.
///
/// This test will move the source file to a destination file in the same directory i.e. rename it
/// </summary>
private void MoveAndCheck_SameDirectory(WatcherChangeTypes eventType, bool moveRaisesEvent)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
using (var watcher = new FileSystemWatcher(testDirectory.Path))
{
// put everything in our own directory to avoid collisions
watcher.Path = Path.GetFullPath(dir.Path);
watcher.Filter = "*.*";
// create a file
using (var testFile = new TempFile(Path.Combine(dir.Path, "file")))
{
watcher.EnableRaisingEvents = true;
AutoResetEvent eventOccurred = WatchForEvents(watcher, eventType);
// Move the testFile to a different name in the same directory
File.Move(testFile.Path, testFile.Path + "_" + eventType.ToString());
// Test that the event is observed or not observed
if (moveRaisesEvent)
ExpectEvent(eventOccurred, eventType.ToString());
else
ExpectNoEvent(eventOccurred, eventType.ToString());
}
}
}
示例8: FileMove_SameDirectory
private void FileMove_SameDirectory(WatcherChangeTypes eventType)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, "dir")))
using (var testFile = new TempFile(Path.Combine(dir.Path, "file")))
using (var watcher = new FileSystemWatcher(dir.Path, "*"))
{
string sourcePath = testFile.Path;
string targetPath = testFile.Path + "_" + eventType.ToString();
// Move the testFile to a different name in the same directory
Action action = () => File.Move(sourcePath, targetPath);
Action cleanup = () => File.Move(targetPath, sourcePath);
if ((eventType & WatcherChangeTypes.Deleted) > 0)
ExpectEvent(watcher, eventType, action, cleanup, new string[] { sourcePath, targetPath });
else
ExpectEvent(watcher, eventType, action, cleanup, targetPath);
}
}
示例9: FileMove_NestedDirectory
private void FileMove_NestedDirectory(WatcherChangeTypes eventType, bool includeSubdirectories)
{
using (var dir = new TempDirectory(GetTestFilePath()))
using (var firstDir = new TempDirectory(Path.Combine(dir.Path, "dir1")))
using (var nestedDir = new TempDirectory(Path.Combine(firstDir.Path, "nested")))
using (var nestedFile = new TempFile(Path.Combine(nestedDir.Path, "nestedFile" + eventType.ToString())))
using (var watcher = new FileSystemWatcher(dir.Path, "*"))
{
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.IncludeSubdirectories = includeSubdirectories;
string sourcePath = nestedFile.Path;
string targetPath = nestedFile.Path + "_2";
// Move the testFile to a different name within the same nested directory
Action action = () => File.Move(sourcePath, targetPath);
Action cleanup = () => File.Move(targetPath, sourcePath);
if ((eventType & WatcherChangeTypes.Deleted) > 0)
ExpectEvent(watcher, eventType, action, cleanup, new string[] { targetPath, sourcePath });
else
ExpectEvent(watcher, eventType, action, cleanup, targetPath);
}
}
示例10: FileMove_DifferentWatchedDirectory
private void FileMove_DifferentWatchedDirectory(WatcherChangeTypes eventType)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, "dir")))
using (var dir_adjacent = new TempDirectory(Path.Combine(testDirectory.Path, "dir_adj")))
using (var testFile = new TempFile(Path.Combine(dir.Path, "file")))
using (var watcher = new FileSystemWatcher(testDirectory.Path, "*"))
{
string sourcePath = testFile.Path;
string targetPath = Path.Combine(dir_adjacent.Path, Path.GetFileName(testFile.Path) + "_" + eventType.ToString());
// Move the testFile to a different directory under the Watcher
Action action = () => File.Move(sourcePath, targetPath);
Action cleanup = () => File.Move(targetPath, sourcePath);
ExpectEvent(watcher, eventType, action, cleanup, new string[] { dir.Path, dir_adjacent.Path });
}
}