示例#1
0
        public override DateTime Handle(FileGetTimeArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            var       resolver = new EntryResolver(Container);
            BaseEntry entry    = resolver.SafeResolveEntry(arguments.Path);

            if (entry == null)
            {
                return(arguments.IsInUtc ? PathFacts.ZeroFileTimeUtc : PathFacts.ZeroFileTime);
            }

            switch (arguments.Kind)
            {
            case FileTimeKind.CreationTime:
            {
                return(arguments.IsInUtc ? entry.CreationTimeUtc : entry.CreationTime);
            }

            case FileTimeKind.LastWriteTime:
            {
                return(arguments.IsInUtc ? entry.LastWriteTimeUtc : entry.LastWriteTime);
            }

            case FileTimeKind.LastAccessTime:
            {
                return(arguments.IsInUtc ? entry.LastAccessTimeUtc : entry.LastAccessTime);
            }

            default:
            {
                throw ErrorFactory.Internal.EnumValueUnsupported(arguments.Kind);
            }
            }
        }
示例#2
0
        public override EntryMetadata Handle(EntryGetMetadataArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            var resolver = new EntryResolver(Container)
            {
                ErrorDirectoryFoundAsFile     = ErrorFactory.System.FileNotFound,
                ErrorLastDirectoryFoundAsFile = ErrorFactory.System.FileNotFound,
                ErrorDirectoryNotFound        = ErrorFactory.System.FileNotFound
            };

            BaseEntry entry;

            try
            {
                entry = resolver.ResolveEntry(arguments.Path);
            }
            catch (FileNotFoundException)
            {
                return(EntryMetadata.Default);
            }
            catch (Exception ex)
            {
                return(EntryMetadata.CreateForError(ex));
            }

            long fileSize = entry is FileEntry fileEntry ? fileEntry.Size : -1;

            return(EntryMetadata.CreateForSuccess(entry.Attributes, entry.CreationTimeUtc, entry.LastAccessTimeUtc,
                                                  entry.LastWriteTimeUtc, fileSize));
        }
        public override DateTime Handle(FileGetTimeArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            var       resolver = new EntryResolver(Root);
            BaseEntry entry    = resolver.SafeResolveEntry(arguments.Path);

            if (entry == null)
            {
                return(arguments.IsInUtc ? PathFacts.ZeroFileTimeUtc : PathFacts.ZeroFileTime);
            }

            switch (arguments.Kind)
            {
            case FileTimeKind.CreationTime:
                return(arguments.IsInUtc ? entry.CreationTimeUtc : entry.CreationTime);

            case FileTimeKind.LastWriteTime:
                return(arguments.IsInUtc ? entry.LastWriteTimeUtc : entry.LastWriteTime);

            case FileTimeKind.LastAccessTime:
                return(arguments.IsInUtc ? entry.LastAccessTimeUtc : entry.LastAccessTime);

            default:
                throw new NotSupportedException($"Unsupported kind of file time '{arguments.Kind}'.");
            }
        }
示例#4
0
        public override FileAttributes Handle(FileGetAttributesArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            var       resolver = new EntryResolver(Root);
            BaseEntry entry    = resolver.ResolveEntry(arguments.Path);

            return(entry.Attributes);
        }
示例#5
0
        public override object Handle(EntrySetTimeArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));
            AssertTimeValueIsInRange(arguments);
            AssertIsNotVolumeRoot(arguments.Path);

            var       resolver = new EntryResolver(Root);
            BaseEntry entry    = resolver.ResolveEntry(arguments.Path);

            AssertIsNotDirectory(entry, arguments.Path);
            AssertFileIsNotReadOnly(entry, arguments.Path);
            AssertHasExclusiveAccessToFile(entry, arguments.Path);

            switch (arguments.Kind)
            {
            case FileTimeKind.CreationTime:
                if (arguments.IsInUtc)
                {
                    entry.CreationTimeUtc = arguments.TimeValue;
                }
                else
                {
                    entry.CreationTime = arguments.TimeValue;
                }
                break;

            case FileTimeKind.LastWriteTime:
                if (arguments.IsInUtc)
                {
                    entry.LastWriteTimeUtc = arguments.TimeValue;
                }
                else
                {
                    entry.LastWriteTime = arguments.TimeValue;
                }
                break;

            case FileTimeKind.LastAccessTime:
                if (arguments.IsInUtc)
                {
                    entry.LastAccessTimeUtc = arguments.TimeValue;
                }
                else
                {
                    entry.LastAccessTime = arguments.TimeValue;
                }
                break;

            default:
                throw ErrorFactory.Internal.EnumValueUnsupported(arguments.Kind);
            }

            return(Missing.Value);
        }
        public override Missing Handle(FileSetAttributesArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            var       resolver = new EntryResolver(Container);
            BaseEntry entry    = resolver.ResolveEntry(arguments.Path);

            entry.SetAttributes(arguments.Attributes, arguments.AccessKinds);

            return(Missing.Value);
        }
示例#7
0
        public override object Handle(FileSetAttributesArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            var       resolver = new EntryResolver(Root);
            BaseEntry entry    = resolver.ResolveEntry(arguments.Path);

            entry.Attributes = arguments.Attributes;

            return(Missing.Value);
        }
示例#8
0
        private BaseEntry ResolveEntry([NotNull] FileCryptoArguments arguments)
        {
            EntryResolver resolver = arguments.IsEncrypt
                ? new EntryResolver(Container)
            {
                ErrorNetworkShareNotFound = _ => ErrorFactory.System.FileOrDirectoryOrVolumeIsIncorrect(),
                ErrorDirectoryNotFound    = path => IsPathOnExistingVolume(path)
                        ? ErrorFactory.System.DirectoryNotFound(path)
                        : ErrorFactory.System.FileNotFound(path)
            }
                : new EntryResolver(Container);

            return(resolver.ResolveEntry(arguments.Path));
        }
示例#9
0
        public override Missing Handle(EntrySetTimeArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));
            AssertTimeValueIsInRange(arguments);
            AssertIsNotVolumeRoot(arguments.Path);

            var       resolver = new EntryResolver(Container);
            BaseEntry entry    = resolver.ResolveEntry(arguments.Path);

            AssertIsNotExternallyEncrypted(entry, arguments.Path);
            AssertIsNotDirectory(entry, arguments.Path);
            AssertFileIsNotReadOnly(entry, arguments.Path);
            AssertHasExclusiveAccessToFile(entry, arguments.Path);

            switch (arguments.Kind)
            {
            case FileTimeKind.CreationTime:
            {
                if (arguments.IsInUtc)
                {
                    entry.CreationTimeUtc = arguments.TimeValue;
                }
                else
                {
                    entry.CreationTime = arguments.TimeValue;
                }

                Container.ChangeTracker.NotifyContentsAccessed(entry.PathFormatter, FileAccessKinds.Create);
                break;
            }

            case FileTimeKind.LastWriteTime:
            {
                if (arguments.IsInUtc)
                {
                    entry.LastWriteTimeUtc = arguments.TimeValue;
                }
                else
                {
                    entry.LastWriteTime = arguments.TimeValue;
                }

                Container.ChangeTracker.NotifyContentsAccessed(entry.PathFormatter, FileAccessKinds.Write);
                break;
            }

            case FileTimeKind.LastAccessTime:
            {
                if (arguments.IsInUtc)
                {
                    entry.LastAccessTimeUtc = arguments.TimeValue;
                }
                else
                {
                    entry.LastAccessTime = arguments.TimeValue;
                }

                Container.ChangeTracker.NotifyContentsAccessed(entry.PathFormatter, FileAccessKinds.Read);
                break;
            }

            default:
            {
                throw ErrorFactory.Internal.EnumValueUnsupported(arguments.Kind);
            }
            }

            return(Missing.Value);
        }