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(); }
/// <summary> /// Retrieve resource property values /// </summary> /// <param name="requestedProperties"></param> /// <param name="validProperties"></param> /// <param name="invalidProperties"></param> public virtual void GetPropertyValues(DavPropertyCollection requestedProperties, DavPropertyCollection validProperties, DavPropertyCollection invalidProperties) { if (validProperties == null) { throw new ArgumentNullException("validProperties", InternalFunctions.GetResourceString("ArgumentNullException", "ValidProperties")); } else if (invalidProperties == null) { throw new ArgumentNullException("invalidProperties", InternalFunctions.GetResourceString("ArgumentNullException", "InvalidProperties")); } //Clear out all the properties validProperties.Clear(); invalidProperties.Clear(); //Requesting ALL available properties DavPropertyCollection _requestedProperties; if (requestedProperties == null) { _requestedProperties = this.ResourceProperties.Clone(); } else { _requestedProperties = requestedProperties.Clone(); } //Check to see if there is a valid property foreach (DavProperty _property in _requestedProperties) { string _propertyName = _property.Name ?? ""; if (_propertyName.ToLower(CultureInfo.InvariantCulture).StartsWith("get")) { _propertyName = _propertyName.Substring(3); } if (this.__classProperties.ContainsKey(_propertyName)) { PropertyInfo _resourceProperty = this.__classProperties[_propertyName] as PropertyInfo; if (_resourceProperty != null) { if (_resourceProperty.PropertyType == typeof(XPathNavigator)) { XPathNavigator _propertyValue = (XPathNavigator)_resourceProperty.GetValue(this, null); if (_propertyValue != null) { validProperties.Add(new DavProperty(_propertyValue)); } } else if (_resourceProperty.PropertyType == typeof(ResourceType)) { ResourceType _resource = (ResourceType)_resourceProperty.GetValue(this, null); switch (_resource) { case ResourceType.Collection: DavProperty _folderResourceType = new DavProperty("resourcetype", "DAV:"); _folderResourceType.NestedProperties.Add(new DavProperty("collection", "DAV:")); validProperties.Add(_folderResourceType); break; //case ResourceType.Resource: // //DavProperty _fileResourceType = new DavProperty("resourcetype", "DAV:"); // //validProperties.Add(_fileResourceType); // break; } } else if (_resourceProperty.PropertyType == typeof(bool)) { bool _propertyValue = (bool)_resourceProperty.GetValue(this, null); if (_propertyValue) { validProperties.Add(_property); } else { invalidProperties.Add(_property); } } else if (_resourceProperty.PropertyType == typeof(DateTime)) { DateTime _propertyValue = (DateTime)_resourceProperty.GetValue(this, null); if (_propertyValue != DateTime.MinValue) { switch (_resourceProperty.Name.ToLower(CultureInfo.InvariantCulture)) { case "lastmodified": { //DavPropertyAttribute _propertyAttribute = new DavPropertyAttribute(); //_propertyAttribute.AttributeName = "dt"; //_propertyAttribute.AttributeNamespace = "b"; //_propertyAttribute.AttributeValue = "dateTime.rfc1123"; //_property.Attributes.Add(_propertyAttribute); //_property.Value = _propertyValue.ToString("r", CultureInfo.InvariantCulture); //_property.Value = _propertyValue.ToString(CultureInfo.InvariantCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.InvariantCulture); _property.Value = _propertyValue.ToString("ddd, dd MMM yyy HH':'mm':'ss 'GMT'"); } break; case "creationdate": { //DavPropertyAttribute _propertyAttribute = new DavPropertyAttribute(); //_propertyAttribute.AttributeName = "dt"; //_propertyAttribute.AttributeNamespace = "b"; //_propertyAttribute.AttributeValue = "dateTime.tz"; //_property.Attributes.Add(_propertyAttribute); //_property.Value = this.__creationDate.ToString("s", CultureInfo.InvariantCulture); _property.Value = _propertyValue.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"); } break; } validProperties.Add(_property); } else { invalidProperties.Add(_property); } } else { string _resourceValue = _resourceProperty.GetValue(this, null).ToString(); if (_resourceValue != null && _resourceValue.Length > 0) { _property.Value = _resourceValue; validProperties.Add(_property); } else { invalidProperties.Add(_property); } } } } else if (this.CustomProperties[_propertyName] != null) { validProperties.Add(_property); } else { invalidProperties.Add(_property); } } }
/// <summary> /// Retrieve resource property values /// </summary> /// <param name="requestedProperties"></param> /// <param name="validProperties"></param> /// <param name="invalidProperties"></param> public virtual void GetPropertyValues(DavPropertyCollection requestedProperties, DavPropertyCollection validProperties, DavPropertyCollection invalidProperties) { if (validProperties == null) { throw new ArgumentNullException("validProperties", InternalFunctions.GetResourceString("ArgumentNullException", "ValidProperties")); } else if (invalidProperties == null) { throw new ArgumentNullException("invalidProperties", InternalFunctions.GetResourceString("ArgumentNullException", "InvalidProperties")); } //Clear out all the properties validProperties.Clear(); invalidProperties.Clear(); //Requesting ALL available properties DavPropertyCollection _requestedProperties; if (requestedProperties == null) { _requestedProperties = this.ResourceProperties.Clone(); } else { _requestedProperties = requestedProperties.Clone(); } //Check to see if there is a valid property foreach (DavProperty _property in _requestedProperties) { string _propertyName = _property.Name ?? ""; if (_propertyName.ToLower(CultureInfo.InvariantCulture).StartsWith("get")) { _propertyName = _propertyName.Substring(3); } if (this.__classProperties.ContainsKey(_propertyName)) { PropertyInfo _resourceProperty = this.__classProperties[_propertyName] as PropertyInfo; if (_resourceProperty != null) { if (_resourceProperty.PropertyType == typeof(XPathNavigator)) { XPathNavigator _propertyValue = (XPathNavigator)_resourceProperty.GetValue(this, null); if (_propertyValue != null) { validProperties.Add(new DavProperty(_propertyValue)); } } else if (_resourceProperty.PropertyType == typeof(ResourceType)) { ResourceType _resource = (ResourceType)_resourceProperty.GetValue(this, null); switch (_resource) { case ResourceType.Collection: DavProperty _folderResourceType = new DavProperty("resourcetype", "DAV:"); _folderResourceType.NestedProperties.Add(new DavProperty("collection", "DAV:")); validProperties.Add(_folderResourceType); break; //case ResourceType.Resource: // //DavProperty _fileResourceType = new DavProperty("resourcetype", "DAV:"); // //validProperties.Add(_fileResourceType); // break; } } else if (_resourceProperty.PropertyType == typeof(bool)) { bool _propertyValue = (bool)_resourceProperty.GetValue(this, null); if (_propertyValue) { validProperties.Add(_property); } else { invalidProperties.Add(_property); } } else if (_resourceProperty.PropertyType == typeof(DateTime)) { DateTime _propertyValue = (DateTime)_resourceProperty.GetValue(this, null); if (_propertyValue != DateTime.MinValue) { switch (_resourceProperty.Name.ToLower(CultureInfo.InvariantCulture)) { case "lastmodified": case "creationdate": // Older versions of Windows require date to be sent in this now-obsolete // date format. Dates should also always be sent in rfc1123 format as per the // spec. // http://www.greenbytes.de/tech/webdav/webfolder-client-list.html#issue-date-format // http://lists.xml.org/archives/xml-dev/200101/msg00930.html DavPropertyAttribute propertyAttributeUuid = new DavPropertyAttribute { AttributeNamespace = "xmlns", AttributeName = "b", AttributeValue = "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" }; DavPropertyAttribute propertyAttributeRfc = new DavPropertyAttribute { AttributeNamespace = "b", AttributeName = "dt", AttributeValue = "dateTime.rfc1123" }; _property.Attributes.Add(propertyAttributeUuid); _property.Attributes.Add(propertyAttributeRfc); _property.Value = _propertyValue.ToString(CultureInfo.InvariantCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.InvariantCulture); break; } validProperties.Add(_property); } else { invalidProperties.Add(_property); } } else { string _resourceValue = _resourceProperty.GetValue(this, null).ToString(); if (_resourceValue != null && _resourceValue.Length > 0) { _property.Value = _resourceValue; validProperties.Add(_property); } else { invalidProperties.Add(_property); } } } } else if (this.CustomProperties[_propertyName] != null) { validProperties.Add(_property); } else { invalidProperties.Add(_property); } } }