当前位置: 首页>>代码示例>>C#>>正文


C# Cache.Patch方法代码示例

本文整理汇总了C#中Cache.Patch方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Patch方法的具体用法?C# Cache.Patch怎么用?C# Cache.Patch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cache的用法示例。


在下文中一共展示了Cache.Patch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSettings

        public static WatcherSettings GetSettings()
        {
            var maxWaitTime = 3000;

            var file2Deleted = false;
            var file3Created = false;

            var dir2Deleted = false;
            var dir3Created = false;

            var changeDir = Path.GetTempFileName();
            changeDir = Path.Combine(
                Path.GetDirectoryName(changeDir),
                "changedir_" + Path.GetFileNameWithoutExtension(changeDir));
            Directory.CreateDirectory(changeDir);
            var subdir = Path.Combine(changeDir, "subdir");
            var subdirDelete = Path.Combine(changeDir, "subdirdelete");
            var dir2 = Path.Combine(changeDir, "subdir1");
            var dir3 = Path.Combine(changeDir, "subdir2");
            var file = Path.Combine(subdir, "myfile.txt");
            var file2 = Path.Combine(changeDir, "MovedFile.txt");
            var file3 = file2 + ".again";
            var fileContentChange = Path.Combine(changeDir, "contentToChange.txt");
            Directory.CreateDirectory(dir2);
            Directory.CreateDirectory(subdirDelete);
            File.WriteAllText(fileContentChange, "to be changed");
            File.WriteAllText(file2, "hey");

            var cache = new Cache(changeDir, () => false);
            cache.Initialize();

            Func<bool> fullSupport = () => {
                return
                    _canDetectDirectoryCreate &&
                    _canDetectDirectoryDelete &&
                    dir2Deleted && dir3Created &&
                    _canDetectFileCreate &&
                    _canDetectFileChange &&
                    _canDetectFileDelete &&
                    file2Deleted && file3Created;
            };

            var fsw = new FSW(
                changeDir,
                (s) => {
                    cache.Patch(new Change(ChangeType.DirectoryCreated, s));
                    _canDetectDirectoryCreate = true;
                    if (s == dir3)
                        dir3Created = true;
                },
                (s) => {
                    cache.Patch(new Change(ChangeType.DirectoryDeleted, s));
                    _canDetectDirectoryDelete = true;
                    if (s == dir2)
                        dir2Deleted = true;
                },
                (s) => {
                    _canDetectFileCreate = true;
                    if (s == file3)
                        file3Created = true;
                },
                (s) => _canDetectFileChange = true,
                (s) => {
                    _canDetectFileDelete = true;
                    if (s == file2)
                        file2Deleted = true;
                },
                (s) => {},
                cache);
            fsw.Start();

            var fileChanges = new Thread(() => {
                var startTime = DateTime.Now;
                Directory.CreateDirectory(subdir);
                File.WriteAllText(file, "hey");
                using (var writer = File.AppendText(fileContentChange)) {
                    writer.Write("moar content");
                }
                File.Move(file2, file3);
                File.Delete(file);
                Directory.Move(dir2, dir3);
                Directory.Delete(subdirDelete);
                while (!fullSupport() && timeSince(startTime) < maxWaitTime)
                    Thread.Sleep(10);
            });
            fileChanges.Start();
            fileChanges.Join();

            fsw.Stop();

            Directory.Delete(dir3);
            if (Directory.Exists(subdirDelete))
                Directory.Delete(subdirDelete);
            File.Delete(fileContentChange);
            File.Delete(file3);
            Directory.Delete(subdir);
            Directory.Delete(changeDir);

            return new WatcherSettings(
                _canDetectDirectoryCreate,
//.........这里部分代码省略.........
开发者ID:rhwy,项目名称:FSWatcher,代码行数:101,代码来源:WatcherSettings.cs


注:本文中的Cache.Patch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。