C# FileInfo.Refresh的代码示例

通过代码示例来学习C# FileInfo.Refresh方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


FileInfo.Refresh是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的FileInfo.Refresh() 已经帮大家高亮显示了,大家可以重点学习FileInfo.Refresh() 方法的写法,从而快速掌握该方法的应用。

FileInfo.Refresh的代码示例1 - ExpandedFileAttributesAreUpdated()

    using System.IO;

        [TestCase]
        public void ExpandedFileAttributesAreUpdated()
        {
            FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner;

            string filename = Path.Combine("GVFS", "GVFS", "GVFS.csproj");
            string virtualFile = this.Enlistment.GetVirtualPathTo(filename);

            // Update defaults. FileInfo is not batched, so each of these will create a separate Open-Update-Close set.
            FileInfo before = new FileInfo(virtualFile);
            DateTime testValue = DateTime.Now + TimeSpan.FromDays(1);

            // Setting the CreationTime results in a write handle being open to the file and the file being expanded
            before.CreationTime = testValue;
            before.LastAccessTime = testValue;
            before.LastWriteTime = testValue;
            before.Attributes = FileAttributes.Hidden;

            // FileInfo caches information. We can refresh, but just to be absolutely sure...
            FileInfo info = virtualFile.ShouldBeAFile(fileSystem).WithInfo(testValue, testValue, testValue);

            // Ignore the archive bit as it can be re-added to the file as part of its expansion to full
            FileAttributes attributes = info.Attributes & ~FileAttributes.Archive;

            int retryCount = 0;
            int maxRetries = 10;
            while (attributes != FileAttributes.Hidden && retryCount < maxRetries)
            {
                // ProjFS attributes are remoted asynchronously when files are converted to full
                FileAttributes attributesLessProjFS = attributes & (FileAttributes)~(FileAttributeSparseFile | FileAttributeReparsePoint | FileAttributeRecallOnDataAccess);

                attributesLessProjFS.ShouldEqual(
                    FileAttributes.Hidden,
                    $"Attributes (ignoring ProjFS attributes) do not match, expected: {FileAttributes.Hidden} actual: {attributesLessProjFS}");

                ++retryCount;
                Thread.Sleep(500);

                info.Refresh();
                attributes = info.Attributes & ~FileAttributes.Archive;
            }

            attributes.ShouldEqual(FileAttributes.Hidden, $"Attributes do not match, expected: {FileAttributes.Hidden} actual: {attributes}");
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:46,代码来源:BasicFileSystemTests.cs

在ExpandedFileAttributesAreUpdated()方法中,FileInfo的代码示例类中的Refresh的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

FileInfo.Refresh的代码示例2 - VerifyResults()

    using System.IO;

        private void VerifyResults(FileGeneratorTestHelper testHelper)
        {
            testHelper.Flush();

            string tmpFile1 = Path.GetTempFileName();
            string tmpFile2 = Path.GetTempFileName();
            try
            {
                // Check that generated content is different than default content of tmp file(empty)
                var fileInfo1 = new FileInfo(tmpFile1);
                var fileInfo2 = new FileInfo(tmpFile2);

                Assert.IsTrue(testHelper.Generator.IsFileDifferent(fileInfo1));
                Assert.IsTrue(testHelper.Generator.IsFileDifferent(fileInfo2));

                // Write the file using reference stream
                Assert.IsTrue(Util.FileWriteIfDifferentInternal(fileInfo1, testHelper.Stream, true));
                fileInfo1.Refresh();

                // Using second file to write a file using generator.
                Assert.IsTrue(testHelper.Generator.FileWriteIfDifferent(fileInfo2, true));
                fileInfo2.Refresh();

                // Verify that generator content is the same.
                Assert.IsFalse(testHelper.Generator.IsFileDifferent(fileInfo1));

                // Verify that written file is identical to stream
                Assert.IsFalse(Util.IsFileDifferent(fileInfo2, testHelper.Stream));

                // Read the two files and verify that they are identical
                var contentFile1 = File.ReadAllBytes(tmpFile1);
                var contentFile2 = File.ReadAllBytes(tmpFile2);
                ReadOnlySpan span1 = new ReadOnlySpan(contentFile1);
                ReadOnlySpan span2 = new ReadOnlySpan(contentFile2);
                Assert.IsTrue(span1.SequenceEqual(span2));
            }
            finally
            {
                File.Delete(tmpFile1);
                File.Delete(tmpFile2);
            }
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:44,代码来源:TestFileGenerator.cs

在VerifyResults()方法中,FileInfo的代码示例类中的Refresh的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

FileInfo.Refresh的代码示例3 - SetExpire()

    using System.IO;

        /// 设置过期重新加载配置的时间
        void SetExpire()
        {
            if (_.ReloadTime > 0)
            {
                // 这里必须在加载后即可设置过期时间和最后写入时间,否则下一次访问的时候,IsUpdated会报告文件已更新
                var fi = new FileInfo(ConfigFile);
                if (fi.Exists)
                {
                    fi.Refresh();
                    lastWrite = fi.LastWriteTime;
                }
                else
                    lastWrite = DateTime.Now;
                expire = DateTime.Now.AddMilliseconds(_.ReloadTime);
            }
        }
    

开发者ID:NewLifeX,项目名称:X,代码行数:19,代码来源:JsonConfig.cs

在SetExpire()方法中,FileInfo的代码示例类中的Refresh的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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