Skip to content

Commit

Permalink
Simplified file interfaces. Directories and Files are now both repres…
Browse files Browse the repository at this point in the history
…ented

as IFileInfo.
  • Loading branch information
jimmyca15 committed Jan 30, 2017
1 parent 5d0e45c commit becdfd7
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 139 deletions.
22 changes: 17 additions & 5 deletions src/Microsoft.IIS.Administration.Files.Core/DirectoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Microsoft.IIS.Administration.Files
using System;
using System.IO;

class DirectoryInfo : IDirectoryInfo
class DirectoryInfo : IFileInfo
{
private System.IO.DirectoryInfo _info;
private IDirectoryInfo _parent;
private IFileInfo _parent;

public DirectoryInfo(string path)
{
Expand All @@ -24,7 +24,7 @@ public FileAttributes Attributes {
}
}

public DateTime Creation {
public DateTime Created {
get {
return _info.CreationTime;
}
Expand All @@ -36,7 +36,7 @@ public bool Exists {
}
}

public DateTime LastAccess {
public DateTime LastAccessed {
get {
return _info.LastAccessTime;
}
Expand All @@ -54,7 +54,7 @@ public string Name {
}
}

public IDirectoryInfo Parent {
public IFileInfo Parent {
get {
return _parent;
}
Expand All @@ -65,5 +65,17 @@ public string Path {
return _info.FullName;
}
}

public long Size {
get {
return 0;
}
}

public FileType Type {
get {
return FileType.Directory;
}
}
}
}
14 changes: 10 additions & 4 deletions src/Microsoft.IIS.Administration.Files.Core/FileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.IIS.Administration.Files
class FileInfo : IFileInfo
{
private System.IO.FileInfo _info;
private IDirectoryInfo _parent;
private IFileInfo _parent;

public FileInfo(string path)
{
Expand All @@ -24,7 +24,7 @@ public FileAttributes Attributes {
}
}

public DateTime Creation {
public DateTime Created {
get {
return _info.CreationTime;
}
Expand All @@ -36,7 +36,7 @@ public bool Exists {
}
}

public DateTime LastAccess {
public DateTime LastAccessed {
get {
return _info.LastAccessTime;
}
Expand All @@ -54,7 +54,7 @@ public string Name {
}
}

public IDirectoryInfo Parent {
public IFileInfo Parent {
get {
return _parent;
}
Expand All @@ -71,5 +71,11 @@ public long Size {
return _info.Length;
}
}

public FileType Type {
get {
return FileType.File;
}
}
}
}
32 changes: 8 additions & 24 deletions src/Microsoft.IIS.Administration.Files.Core/FileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,7 @@ public IFileInfo GetFile(string path)
}, path);
}

public FileVersionInfo GetFileVersion(string path)
{
return PerformIO(p => {
var info = new FileInfo(path);
if (!IsAccessAllowed(path, FileAccess.Read) && (info.Parent == null || !IsAccessAllowed(info.Parent.Path, FileAccess.Read))) {
throw new ForbiddenArgumentException(path);
}
return FileVersionInfo.GetVersionInfo(p);
}, path);
}

public IDirectoryInfo GetDirectory(string path)
public IFileInfo GetDirectory(string path)
{
return PerformIO(p => {
Expand All @@ -87,7 +71,7 @@ public IEnumerable<IFileInfo> GetFiles(string path, string searchPattern, Search
return PerformIO(p => Directory.GetFiles(p ,searchPattern, searchOption), path).Select(f => new FileInfo(f));
}

public IEnumerable<IDirectoryInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly)
public IEnumerable<IFileInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly)
{
this.EnsureAccess(path, FileAccess.Read);

Expand Down Expand Up @@ -138,7 +122,7 @@ public IFileInfo CreateFile(string path)
}, path);
}

public IDirectoryInfo CreateDirectory(string path)
public IFileInfo CreateDirectory(string path)
{
this.EnsureAccess(path, FileAccess.ReadWrite);

Expand Down Expand Up @@ -218,20 +202,20 @@ private async Task CopyFileInternal(string sourcePath, string destPath)
destFileInfo.CreationTimeUtc = sourceFileInfo.CreationTimeUtc;
}

public void SetFileTime(string path, DateTime? lastAccess, DateTime? lastModified, DateTime? creation)
public void SetFileTime(string path, DateTime? lastAccessed, DateTime? lastModified, DateTime? created)
{
PerformIO(p => {
if (lastAccess != null) {
Directory.SetLastAccessTime(p, lastAccess.Value);
if (lastAccessed != null) {
Directory.SetLastAccessTime(p, lastAccessed.Value);
}
if (lastModified != null) {
Directory.SetLastWriteTime(p, lastModified.Value);
}
if (creation != null) {
Directory.SetCreationTime(p, creation.Value);
if (created != null) {
Directory.SetCreationTime(p, created.Value);
}
}, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Microsoft.IIS.Administration.Files
{
enum FileType
public enum FileType
{
File,
Directory
Expand Down
11 changes: 0 additions & 11 deletions src/Microsoft.IIS.Administration.Files.Core/IDirectoryInfo.cs

This file was deleted.

15 changes: 13 additions & 2 deletions src/Microsoft.IIS.Administration.Files.Core/IFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

namespace Microsoft.IIS.Administration.Files
{
public interface IFileInfo : IFileSystemInfo
using System;
using System.IO;

public interface IFileInfo
{
string Name { get; }
string Path { get; }
bool Exists { get; }
long Size { get; }
IDirectoryInfo Parent { get; }
FileType Type { get; }
IFileInfo Parent { get; }
FileAttributes Attributes { get; }
DateTime LastAccessed { get; }
DateTime LastModified { get; }
DateTime Created { get; }
}
}
11 changes: 4 additions & 7 deletions src/Microsoft.IIS.Administration.Files.Core/IFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Microsoft.IIS.Administration.Files
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

Expand All @@ -16,13 +15,11 @@ public interface IFileProvider

IFileInfo GetFile(string path);

IDirectoryInfo GetDirectory(string path);

FileVersionInfo GetFileVersion(string path);
IFileInfo GetDirectory(string path);

IEnumerable<IFileInfo> GetFiles(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly);

IEnumerable<IDirectoryInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly);
IEnumerable<IFileInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly);

Task Copy(string sourcePath, string destPath);

Expand All @@ -32,7 +29,7 @@ public interface IFileProvider

IFileInfo CreateFile(string path);

IDirectoryInfo CreateDirectory(string path);
IFileInfo CreateDirectory(string path);

bool FileExists(string path);

Expand All @@ -42,6 +39,6 @@ public interface IFileProvider

bool IsAccessAllowed(string path, FileAccess requestedAccess);

void SetFileTime(string path, DateTime? lastAccess, DateTime? lastModified, DateTime? creation);
void SetFileTime(string path, DateTime? lastAccessed, DateTime? lastModified, DateTime? created);
}
}
20 changes: 0 additions & 20 deletions src/Microsoft.IIS.Administration.Files.Core/IFileSystemInfo.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Microsoft.IIS.Administration.Files.Core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
}
},
"dependencies": {
"Microsoft.IIS.Administration.Core": "1.0.0-*"
"Microsoft.IIS.Administration.Core": "1.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public object Post([FromBody] dynamic model)
throw new NotFoundException("parent");
}

var src = fileType == FileType.File ? _fileService.GetFile(fileId.PhysicalPath) : (IFileSystemInfo)_fileService.GetDirectory(fileId.PhysicalPath);
var src = fileType == FileType.File ? _fileService.GetFile(fileId.PhysicalPath) : _fileService.GetDirectory(fileId.PhysicalPath);

string destPath = Path.Combine(parentId.PhysicalPath, name == null ? src.Name : name);

Expand Down Expand Up @@ -85,7 +85,7 @@ public object Get(string id)
return _helper.ToJsonModel(copy);
}

private MoveOperation InitiateCopy(IFileSystemInfo source, string destination)
private MoveOperation InitiateCopy(IFileInfo source, string destination)
{
MoveOperation copy = _helper.Move(source, destination, true);

Expand Down
Loading

0 comments on commit becdfd7

Please sign in to comment.