SetLastWriteTime() public static method

public static SetLastWriteTime ( string path, System lastWriteTime ) : void
path string
lastWriteTime System
return void
コード例 #1
0
        public async Task Load()
        {
            using (var testDirectory = new TestDirectory())
            {
                var directory = new Directory(testDirectory.FullPath, null, new TestItemFactory());

                const string emptyDirectoryName       = "EmptyDirectory";
                var          emptyDirectoryLastUpdate = new DateTime(2019, 2, 2, 15, 30, 20);
                var          emptyDirectoryPath       = testDirectory.CreateDirectory(emptyDirectoryName, emptyDirectoryLastUpdate);

                const string notEmptyDirectoryName       = "NotEmptyDirectory";
                var          notEmptyDirectoryLastUpdate = new DateTime(2019, 4, 4, 16, 35, 25);
                var          notEmptyDirectoryPath       = testDirectory.CreateDirectory(notEmptyDirectoryName);

                const string file1Name       = "File1";
                var          file1LastUpdate = new DateTime(2018, 3, 3, 12, 0, 30);
                const string file2Name       = "File2";
                var          file2LastUpdate = new DateTime(2019, 2, 3, 11, 5, 10);
                TestDirectory.CreateFiles(notEmptyDirectoryPath, new Dictionary <string, DateTime>
                {
                    { file1Name, file1LastUpdate },
                    { file2Name, file2LastUpdate }
                });

                // Только после добавления файлов в директорию, так как дата перетёрлась бы.
                IODirectory.SetLastWriteTime(notEmptyDirectoryPath, notEmptyDirectoryLastUpdate);

                const string rootFileName       = "RootFile";
                var          rootFileLastUpdate = new DateTime(2019, 2, 5, 8, 5, 0);
                testDirectory.CreateFiles(new Dictionary <string, DateTime> {
                    { rootFileName, rootFileLastUpdate }
                });

                await directory.Load();

                Assert.True(directory.IsLoaded);
                Assert.Equal(2, directory.Items.Length); // Один файл и одна не пустая директория.

                // Сначала идёт директория, а потом файл.
                Assert.IsType <Directory>(directory.Items[0]);
                Assert.IsType <TestFile>(directory.Items[1]);

                Assert.Equal(notEmptyDirectoryName, directory.Items[0].Name);
                Assert.Equal(notEmptyDirectoryPath, directory.Items[0].FullPath);
                Assert.Equal(notEmptyDirectoryLastUpdate, directory.Items[0].LastUpdate);
                Assert.True(((IDirectory)directory.Items[0]).IsLoaded);
                Assert.Equal(2, ((IDirectory)directory.Items[0]).Items.Length);
                var file1 = ((IDirectory)directory.Items[0]).Items[0];
                Assert.Equal(file1Name, file1.Name);
                Assert.Equal(file1LastUpdate, file1.LastUpdate);
                var file2 = ((IDirectory)directory.Items[0]).Items[1];
                Assert.Equal(file2Name, file2.Name);
                Assert.Equal(file2LastUpdate, file2.LastUpdate);

                Assert.Equal(rootFileName, directory.Items[1].Name);
                Assert.Equal(rootFileLastUpdate, directory.Items[1].LastUpdate);
            }
        }
コード例 #2
0
    /// <summary>
    ///     Sets the directory's last write time.
    /// </summary>
    /// <param name="path">The path of the directory.</param>
    /// <param name="lastWriteTime">A <see cref="DateTime" /> with the directory attribute to set.</param>
    /// <exception cref="ArgumentNullException">
    ///     <paramref name="path" /> is <see langword="null" /> (<see langword="Nothing" />
    ///     in Visual Basic).
    /// </exception>
    public void SetLastWriteTime(
        string path,
        DateTime lastWriteTime)
    {
        _ = Requires.NotNullOrWhiteSpace(
            path,
            nameof(path));

        FSDir.SetLastWriteTime(
            path,
            lastWriteTime);
    }
コード例 #3
0
    /// <summary>
    ///     Asynchronously sets the directory's last write time.
    /// </summary>
    /// <param name="path">The path of the directory.</param>
    /// <param name="lastWriteTime">A <see cref="DateTime" /> with the directory attribute to set.</param>
    /// <param name="cancellationToken">The cancellation token.</param>
    /// <returns>A task.</returns>
    public Task SetLastWriteTimeAsync(
        string path,
        DateTime lastWriteTime,
        CancellationToken cancellationToken = default)
    {
        _ = Requires.NotNullOrWhiteSpace(
            path,
            nameof(path));

        return(Work.OnThreadPoolAsync(
                   state => FSDir.SetLastWriteTime(
                       state.Path,
                       state.LastWriteTime),
                   (Path: path, LastWriteTime: lastWriteTime),
                   cancellationToken));
    }
コード例 #4
0
 public static void SetLastWriteTime(string path, System.DateTime lastWriteTime) =>
 MSIOD.SetLastWriteTime(path, lastWriteTime);
コード例 #5
0
 public override void SetLastWriteTime(string path, DateTime lastWriteTime)
 {
     Directory.SetLastWriteTime(path, lastWriteTime);
 }