public LocalStoreCollectionProps(Func <string, bool> isEnabledPropFunc) { var props = new DavProperty <T>[] { //// was added to to make WebDrive work, but no success //new DavHref<LocalStoreCollection> //{ // Getter = (context, collection) => collection._directoryInfo.Name //}, //new DavLoctoken<LocalStoreCollection> //{ // Getter = (context, collection) => "" //}, // collection property required for WebDrive new DavCollection <T> { Getter = (cntext, collection) => string.Empty }, new DavGetEtag <T> { Getter = (cntext, item) => item.CalculateEtag() }, //new DavBsiisreadonly<LocalStoreCollection> //{ // Getter = (context, item) => false //}, //new DavSrtfileattributes<LocalStoreCollection> //{ // Getter = (context, collection) => collection.DirectoryInfo.Attributes, // Setter = (context, collection, value) => // { // collection.DirectoryInfo.Attributes = value; // return DavStatusCode.Ok; // } //}, ////==================================================================================================== new DavIsreadonly <T> { Getter = (cntext, item) => !item.IsWritable }, new DavQuotaAvailableBytes <T> { Getter = (cntext, collection) => collection.FullPath == "/" ? CloudManager.Instance(cntext.Session.Principal.Identity).GetDiskUsage().Free.DefaultValue : long.MaxValue, IsExpensive = true //folder listing performance }, new DavQuotaUsedBytes <T> { Getter = (cntext, collection) => collection.DirectoryInfo.Size //IsExpensive = true //folder listing performance }, // RFC-2518 properties new DavCreationDate <T> { Getter = (cntext, collection) => collection._directoryInfo.CreationTimeUtc, Setter = (cntext, collection, value) => { collection._directoryInfo.CreationTimeUtc = value; return(DavStatusCode.Ok); } }, new DavDisplayName <T> { Getter = (cntext, collection) => collection._directoryInfo.Name }, new DavGetLastModified <T> { Getter = (cntext, collection) => collection._directoryInfo.LastWriteTimeUtc, Setter = (cntext, collection, value) => { collection._directoryInfo.LastWriteTimeUtc = value; return(DavStatusCode.Ok); } }, new DavLastAccessed <T> { Getter = (cntext, collection) => collection._directoryInfo.LastWriteTimeUtc, Setter = (cntext, collection, value) => { collection._directoryInfo.LastWriteTimeUtc = value; return(DavStatusCode.Ok); } }, //new DavGetResourceType<LocalStoreCollection> //{ // Getter = (context, collection) => new XElement(WebDavNamespaces.DavNs + "collection") //}, new DavGetResourceType <T> { Getter = (cntext, collection) => new [] { SxDavCollection } }, // Default locking property handling via the LockingManager new DavLockDiscoveryDefault <T>(), new DavSupportedLockDefault <T>(), //Hopmann/Lippert collection properties new DavExtCollectionChildCount <T> { Getter = (cntext, collection) => { int files = collection.DirectoryInfo.NumberOfFiles; int folders = collection.DirectoryInfo.NumberOfFolders; return(folders > 0 ? folders : collection.DirectoryInfo.ServerFoldersCount + files > 0 ? files : collection.DirectoryInfo.ServerFilesCount ?? 0); } }, new DavExtCollectionIsFolder <T> { Getter = (cntext, collection) => true }, new DavExtCollectionIsHidden <T> { Getter = (cntext, collection) => false }, new DavExtCollectionIsStructuredDocument <T> { Getter = (cntext, collection) => false }, new DavExtCollectionHasSubs <T> //Identifies whether this collection contains any collections which are folders (see "isfolder"). { Getter = (cntext, collection) => collection.DirectoryInfo.NumberOfFolders > 0 || collection.DirectoryInfo.ServerFoldersCount > 0 }, new DavExtCollectionNoSubs <T> //Identifies whether this collection allows child collections to be created. { Getter = (cntext, collection) => false }, new DavExtCollectionObjectCount <T> //To count the number of non-folder resources in the collection. { Getter = (cntext, collection) => collection.DirectoryInfo.NumberOfFiles > 0 ? collection.DirectoryInfo.NumberOfFiles : collection.DirectoryInfo.ServerFilesCount ?? 0 }, new DavExtCollectionReserved <T> { Getter = (cntext, collection) => !collection.IsWritable }, new DavExtCollectionVisibleCount <T> //Counts the number of visible non-folder resources in the collection. { Getter = (cntext, collection) => collection.DirectoryInfo.NumberOfFiles > 0 ? collection.DirectoryInfo.NumberOfFiles : collection.DirectoryInfo.ServerFilesCount ?? 0 }, // Win32 extensions new Win32CreationTime <T> { Getter = (cntext, collection) => collection._directoryInfo.CreationTimeUtc, Setter = (cntext, collection, value) => { collection.DirectoryInfo.CreationTimeUtc = value; return(DavStatusCode.Ok); } }, new Win32LastAccessTime <T> { Getter = (cntext, collection) => collection.DirectoryInfo.LastAccessTimeUtc, Setter = (cntext, collection, value) => { collection._directoryInfo.LastAccessTimeUtc = value; return(DavStatusCode.Ok); } }, new Win32LastModifiedTime <T> { Getter = (cntext, collection) => collection.DirectoryInfo.LastWriteTimeUtc, Setter = (cntext, collection, value) => { collection.DirectoryInfo.LastWriteTimeUtc = value; return(DavStatusCode.Ok); } }, new Win32FileAttributes <T> { Getter = (cntext, collection) => collection.DirectoryInfo.Attributes, Setter = (cntext, collection, value) => { collection.DirectoryInfo.Attributes = value; return(DavStatusCode.Ok); } }, new DavGetContentLength <T> { Getter = (cntext, item) => item.DirectoryInfo.Size }, new DavGetContentType <T> { Getter = (cntext, item) => "httpd/unix-directory" //"application/octet-stream" }, new DavSharedLink <T> { Getter = (cntext, item) => !item.DirectoryInfo.PublicLinks.Any() ? string.Empty : item.DirectoryInfo.PublicLinks.First().Uri.OriginalString, Setter = (cntext, item, value) => DavStatusCode.Ok } }; _props = props.Where(p => isEnabledPropFunc?.Invoke(p.Name.ToString()) ?? true).ToArray(); }
public LocalStoreItemProps(Func <string, bool> isEnabledPropFunc) { var props = new DavProperty <T>[] { new DavIsreadonly <T> { Getter = (context, item) => !item.IsWritable }, // RFC-2518 properties new DavCreationDate <T> { Getter = (context, item) => item.FileInfo.CreationTimeUtc, Setter = (context, item, value) => { item.FileInfo.CreationTimeUtc = value; return(DavStatusCode.Ok); } }, new DavDisplayName <T> { Getter = (context, item) => item.FileInfo.Name }, new DavGetContentLength <T> { Getter = (context, item) => item.FileInfo.Size }, new DavGetContentType <T> { Getter = (context, item) => item.DetermineContentType() }, new DavGetEtag <T> { // Calculating the Etag is an expensive operation, // because we need to scan the entire file. IsExpensive = true, Getter = (context, item) => item.CalculateEtag() }, new DavGetLastModified <T> { Getter = (context, item) => item.FileInfo.LastWriteTimeUtc, Setter = (context, item, value) => { //item._fileInfo.LastWriteTimeUtc = value; var cloud = CloudManager.Instance((HttpListenerBasicIdentity)context.Session.Principal.Identity); bool res = cloud.SetFileDateTime(item.FileInfo, value).Result; return(res ? DavStatusCode.Ok : DavStatusCode.InternalServerError); } }, new DavLastAccessed <T> { Getter = (context, collection) => collection.FileInfo.LastWriteTimeUtc, Setter = (context, collection, value) => { collection.FileInfo.LastWriteTimeUtc = value; return(DavStatusCode.Ok); } }, new DavGetResourceType <T> { Getter = (context, item) => null }, // Default locking property handling via the LockingManager new DavLockDiscoveryDefault <T>(), new DavSupportedLockDefault <T>(), // Hopmann/Lippert collection properties // (although not a collection, the IsHidden property might be valuable) new DavExtCollectionIsHidden <T> { Getter = (context, item) => false //(item._fileInfo.Attributes & FileAttributes.Hidden) != 0 }, // Win32 extensions new Win32CreationTime <T> { Getter = (context, item) => item.FileInfo.CreationTimeUtc, Setter = (context, item, value) => { //item._fileInfo.CreationTimeUtc = value; var cloud = CloudManager.Instance((HttpListenerBasicIdentity)context.Session.Principal.Identity); bool res = cloud.SetFileDateTime(item.FileInfo, value).Result; return(res ? DavStatusCode.Ok : DavStatusCode.InternalServerError); } }, new Win32LastAccessTime <T> { Getter = (context, item) => item.FileInfo.LastAccessTimeUtc, Setter = (context, item, value) => { item.FileInfo.LastAccessTimeUtc = value; return(DavStatusCode.Ok); } }, new Win32LastModifiedTime <T> { Getter = (context, item) => item.FileInfo.LastWriteTimeUtc, Setter = (context, item, value) => { item.FileInfo.LastWriteTimeUtc = value; return(DavStatusCode.Ok); } }, new Win32FileAttributes <T> { Getter = (context, item) => FileAttributes.Normal, //item._fileInfo.Attributes, Setter = (context, item, value) => DavStatusCode.Ok }, new DavSharedLink <T> { Getter = (context, item) => !item.FileInfo.PublicLinks.Any() ? string.Empty : item.FileInfo.PublicLinks.First().Uri.OriginalString, Setter = (context, item, value) => DavStatusCode.Ok } }; _props = props.Where(p => isEnabledPropFunc?.Invoke(p.Name.LocalName) ?? true).ToArray(); }