Skip to content

Commit

Permalink
Reformatted the diskstore properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramondeklein committed Apr 21, 2016
1 parent eab9fad commit 264cf95
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 131 deletions.
172 changes: 98 additions & 74 deletions NWebDav.Server/Stores/DiskStoreCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,89 +27,113 @@ public DiskStoreCollection(ILockingManager lockingManager, DirectoryInfo directo

public static PropertyManager<DiskStoreCollection> DefaultPropertyManager { get; } = new PropertyManager<DiskStoreCollection>(new DavProperty<DiskStoreCollection>[]
{
// RFC-2518 properties
new DavCreationDate<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.CreationTimeUtc,
Setter = (context, collection, value) => { collection._directoryInfo.CreationTimeUtc = value; return DavStatusCode.Ok; }
},
new DavDisplayName<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.Name
},
new DavGetLastModified<DiskStoreCollection>
// RFC-2518 properties
new DavCreationDate<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.CreationTimeUtc,
Setter = (context, collection, value) =>
{
Getter = (context, collection) => collection._directoryInfo.LastWriteTimeUtc,
Setter = (context, collection, value) => { collection._directoryInfo.LastWriteTimeUtc = value; return DavStatusCode.Ok; }
},
new DavGetResourceType<DiskStoreCollection>
collection._directoryInfo.CreationTimeUtc = value;
return DavStatusCode.Ok;
}
},
new DavDisplayName<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.Name
},
new DavGetLastModified<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.LastWriteTimeUtc,
Setter = (context, collection, value) =>
{
Getter = (context, collection) => new XElement(WebDavNamespaces.DavNs + "collection")
},
collection._directoryInfo.LastWriteTimeUtc = value;
return DavStatusCode.Ok;
}
},
new DavGetResourceType<DiskStoreCollection>
{
Getter = (context, collection) => new XElement(WebDavNamespaces.DavNs + "collection")
},

// Default locking property handling via the LockingManager
new DavLockDiscoveryDefault<DiskStoreCollection>(),
new DavSupportedLockDefault<DiskStoreCollection>(),
// Default locking property handling via the LockingManager
new DavLockDiscoveryDefault<DiskStoreCollection>(),
new DavSupportedLockDefault<DiskStoreCollection>(),

// Hopmann/Lippert collection properties
new DavExtCollectionChildCount<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateFiles().Count() + collection._directoryInfo.EnumerateDirectories().Count()
},
new DavExtCollectionIsFolder<DiskStoreCollection>
{
Getter = (context, collection) => true
},
new DavExtCollectionIsHidden<DiskStoreCollection>
{
Getter = (context, collection) => (collection._directoryInfo.Attributes & FileAttributes.Hidden) != 0
},
new DavExtCollectionIsStructuredDocument<DiskStoreCollection>
{
Getter = (context, collection) => false
},
new DavExtCollectionHasSubs<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateDirectories().Any()
},
new DavExtCollectionNoSubs<DiskStoreCollection>
{
Getter = (context, collection) => false
},
new DavExtCollectionObjectCount<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateFiles().Count()
},
new DavExtCollectionReserved<DiskStoreCollection>
{
Getter = (context, collection) => false
},
new DavExtCollectionVisibleCount<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateFiles().Count(fi => (fi.Attributes & FileAttributes.Hidden) == 0)
},

// Win32 extensions
new Win32CreationTime<DiskStoreCollection>
// Hopmann/Lippert collection properties
new DavExtCollectionChildCount<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateFiles().Count() + collection._directoryInfo.EnumerateDirectories().Count()
},
new DavExtCollectionIsFolder<DiskStoreCollection>
{
Getter = (context, collection) => true
},
new DavExtCollectionIsHidden<DiskStoreCollection>
{
Getter = (context, collection) => (collection._directoryInfo.Attributes & FileAttributes.Hidden) != 0
},
new DavExtCollectionIsStructuredDocument<DiskStoreCollection>
{
Getter = (context, collection) => false
},
new DavExtCollectionHasSubs<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateDirectories().Any()
},
new DavExtCollectionNoSubs<DiskStoreCollection>
{
Getter = (context, collection) => false
},
new DavExtCollectionObjectCount<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateFiles().Count()
},
new DavExtCollectionReserved<DiskStoreCollection>
{
Getter = (context, collection) => false
},
new DavExtCollectionVisibleCount<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.EnumerateFiles().Count(fi => (fi.Attributes & FileAttributes.Hidden) == 0)
},

// Win32 extensions
new Win32CreationTime<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.CreationTimeUtc,
Setter = (context, collection, value) =>
{
Getter = (context, collection) => collection._directoryInfo.CreationTimeUtc,
Setter = (context, collection, value) => { collection._directoryInfo.CreationTimeUtc = value; return DavStatusCode.Ok; }
},
new Win32LastAccessTime<DiskStoreCollection>
collection._directoryInfo.CreationTimeUtc = value;
return DavStatusCode.Ok;
}
},
new Win32LastAccessTime<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.LastAccessTimeUtc,
Setter = (context, collection, value) =>
{
Getter = (context, collection) => collection._directoryInfo.LastAccessTimeUtc,
Setter = (context, collection, value) => { collection._directoryInfo.LastAccessTimeUtc = value; return DavStatusCode.Ok; }
},
new Win32LastModifiedTime<DiskStoreCollection>
collection._directoryInfo.LastAccessTimeUtc = value;
return DavStatusCode.Ok;
}
},
new Win32LastModifiedTime<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.LastWriteTimeUtc,
Setter = (context, collection, value) =>
{
Getter = (context, collection) => collection._directoryInfo.LastWriteTimeUtc,
Setter = (context, collection, value) => { collection._directoryInfo.LastWriteTimeUtc = value; return DavStatusCode.Ok; }
},
new Win32FileAttributes<DiskStoreCollection>
collection._directoryInfo.LastWriteTimeUtc = value;
return DavStatusCode.Ok;
}
},
new Win32FileAttributes<DiskStoreCollection>
{
Getter = (context, collection) => collection._directoryInfo.Attributes,
Setter = (context, collection, value) =>
{
Getter = (context, collection) => collection._directoryInfo.Attributes,
Setter = (context, collection, value) => { collection._directoryInfo.Attributes = value; return DavStatusCode.Ok; }
collection._directoryInfo.Attributes = value;
return DavStatusCode.Ok;
}
}
});

public string Name => _directoryInfo.Name;
Expand Down
139 changes: 82 additions & 57 deletions NWebDav.Server/Stores/DiskStoreItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,76 +26,101 @@ public DiskStoreItem(ILockingManager lockingManager, FileInfo fileInfo)

private static PropertyManager<DiskStoreItem> DefaultPropertyManager { get; } = new PropertyManager<DiskStoreItem>(new DavProperty<DiskStoreItem>[]
{
// RFC-2518 properties
new DavCreationDate<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.CreationTimeUtc,
Setter = (context, item, value) => { item._fileInfo.CreationTimeUtc = value; return DavStatusCode.Ok; }
},
new DavDisplayName<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.Name
},
new DavGetContentLength<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.Length
},
new DavGetContentType<DiskStoreItem>
{
Getter = (context, item) => item.DetermineContentType()
},
new DavGetEtag<DiskStoreItem>
{
// Calculating the Etag is an expensive operation,
// because we need to scan the entire file.
IsExpensive = true,
Getter = (context, item) => item.CalculateEtag()
},
new DavGetLastModified<DiskStoreItem>
// RFC-2518 properties
new DavCreationDate<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.CreationTimeUtc,
Setter = (context, item, value) =>
{
Getter = (context, item) => item._fileInfo.LastWriteTimeUtc,
Setter = (context, item, value) => { item._fileInfo.LastWriteTimeUtc = value; return DavStatusCode.Ok; }
},
new DavGetResourceType<DiskStoreItem>
item._fileInfo.CreationTimeUtc = value;
return DavStatusCode.Ok;
}
},
new DavDisplayName<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.Name
},
new DavGetContentLength<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.Length
},
new DavGetContentType<DiskStoreItem>
{
Getter = (context, item) => item.DetermineContentType()
},
new DavGetEtag<DiskStoreItem>
{
// Calculating the Etag is an expensive operation,
// because we need to scan the entire file.
IsExpensive = true,
Getter = (context, item) => item.CalculateEtag()
},
new DavGetLastModified<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.LastWriteTimeUtc,
Setter = (context, item, value) =>
{
Getter = (context, item) => null
},
item._fileInfo.LastWriteTimeUtc = value;
return DavStatusCode.Ok;
}
},
new DavGetResourceType<DiskStoreItem>
{
Getter = (context, item) => null
},

// Default locking property handling via the LockingManager
new DavLockDiscoveryDefault<DiskStoreItem>(),
new DavSupportedLockDefault<DiskStoreItem>(),
// Default locking property handling via the LockingManager
new DavLockDiscoveryDefault<DiskStoreItem>(),
new DavSupportedLockDefault<DiskStoreItem>(),

// Hopmann/Lippert collection properties
// (although not a collection, the IsHidden property might be valuable)
new DavExtCollectionIsHidden<DiskStoreItem>
{
Getter = (context, item) => (item._fileInfo.Attributes & FileAttributes.Hidden) != 0
},
// Hopmann/Lippert collection properties
// (although not a collection, the IsHidden property might be valuable)
new DavExtCollectionIsHidden<DiskStoreItem>
{
Getter = (context, item) => (item._fileInfo.Attributes & FileAttributes.Hidden) != 0
},

// Win32 extensions
new Win32CreationTime<DiskStoreItem>
// Win32 extensions
new Win32CreationTime<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.CreationTimeUtc,
Setter = (context, item, value) =>
{
Getter = (context, item) => item._fileInfo.CreationTimeUtc,
Setter = (context, item, value) => { item._fileInfo.CreationTimeUtc = value; return DavStatusCode.Ok; }
},
new Win32LastAccessTime<DiskStoreItem>
item._fileInfo.CreationTimeUtc = value;
return DavStatusCode.Ok;
}
},
new Win32LastAccessTime<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.LastAccessTimeUtc,
Setter = (context, item, value) =>
{
Getter = (context, item) => item._fileInfo.LastAccessTimeUtc,
Setter = (context, item, value) => { item._fileInfo.LastAccessTimeUtc = value; return DavStatusCode.Ok; }
},
new Win32LastModifiedTime<DiskStoreItem>
item._fileInfo.LastAccessTimeUtc = value;
return DavStatusCode.Ok;
}
},
new Win32LastModifiedTime<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.LastWriteTimeUtc,
Setter = (context, item, value) =>
{
Getter = (context, item) => item._fileInfo.LastWriteTimeUtc,
Setter = (context, item, value) => { item._fileInfo.LastWriteTimeUtc = value; return DavStatusCode.Ok; }
},
new Win32FileAttributes<DiskStoreItem>
item._fileInfo.LastWriteTimeUtc = value;
return DavStatusCode.Ok;
}
},
new Win32FileAttributes<DiskStoreItem>
{
Getter = (context, item) => item._fileInfo.Attributes,
Setter = (context, item, value) =>
{
Getter = (context, item) => item._fileInfo.Attributes,
Setter = (context, item, value) => { item._fileInfo.Attributes = value; return DavStatusCode.Ok; }
item._fileInfo.Attributes = value;
return DavStatusCode.Ok;
}
}
});

public string Name => _fileInfo.Name;
public string FullPath => _fileInfo.FullName;
public Stream GetReadableStream(IHttpContext httpContext) => _fileInfo.OpenRead();
public Stream GetWritableStream(IHttpContext httpContext) => _fileInfo.OpenWrite();
public IPropertyManager PropertyManager => DefaultPropertyManager;
Expand Down

0 comments on commit 264cf95

Please sign in to comment.