/// <summary> /// Aborts the current request processing /// </summary> /// <param name="responseCode">HttpResponse status code</param> protected internal void AbortRequest(int responseCode) { if (responseCode >= 200 && responseCode < 300) { throw new WebDavException(InternalFunctions.GetResourceString("InvalidResponseCode")); } this.__abortStatusCode = responseCode; }
/// <summary> /// Check to see if this object is read only /// </summary> /// <returns></returns> private bool IsReadOnly(bool throwError) { bool _isReadOnly = false; if (this.__readOnly) { _isReadOnly = true; if (throwError) { throw new WebDavException(InternalFunctions.GetResourceString("ReadOnlyException")); } } return(_isReadOnly); }
/// <summary> /// Copy an existing property collection /// </summary> /// <param name="propertyCollection"></param> public void Copy(DavPropertyCollection propertyCollection) { if (propertyCollection == null) { throw new ArgumentNullException("propertyCollection", InternalFunctions.GetResourceString("ArgumentNullException", "PropertyCollection")); } base.Clear(); foreach (DavProperty _davProperty in propertyCollection) { if (_davProperty.Name != null) { this.Add(_davProperty.Clone()); } } }
/// <summary> /// WebDav Property Attribute. /// </summary> /// <param name="xPathAttribute"></param> public DavPropertyAttribute(XPathNavigator xPathAttribute) { if (xPathAttribute == null) { throw new ArgumentNullException("xPathAttribute", InternalFunctions.GetResourceString("ArgumentNullException", "XPathAttribute")); } else if (xPathAttribute.NodeType != XPathNodeType.Element) { throw new ArgumentException(InternalFunctions.GetResourceString("XPathNavigatorElementArgumentException", "xPathAttribute"), "XPathAttribute"); } this.__xPathAttribute = xPathAttribute; this.AttributeName = xPathAttribute.LocalName; this.AttributeValue = xPathAttribute.Value; this.AttributeNamespace = xPathAttribute.NamespaceURI; }
/// <summary> /// Aborts the current request processing /// </summary> protected void AbortRequest(System.Enum responseCode) { if (responseCode == null) { throw new ArgumentNullException("HttpApplication", InternalFunctions.GetResourceString("ArgumentNullException", "ResponseCode")); } Type _enumType = responseCode.GetType(); if (responseCode.GetTypeCode() == TypeCode.Int32) { AbortRequest((int)System.Enum.Parse(_enumType, responseCode.ToString(), true)); } else { throw new WebDavException(InternalFunctions.GetResourceString("InvalidEnumIntType")); } }
/// <summary> /// Dav Resource Framework Base Class /// </summary> /// <param name="displayName">Resource display name</param> /// <param name="resourcePath">Resource path</param> protected DavResourceBase(string displayName, string resourcePath) { this.DisplayName = displayName; this.ResourcePath = resourcePath; this.LastModified = DateTime.MinValue; this.CreationDate = DateTime.MinValue; this.ContentLanguage = "en-us"; this.ActiveLocks = new DavLockPropertyCollection(); this.ResourceVersions = new DavResourceVersionCollection(); //if (displayName == null || displayName.Length == 0) // throw new ArgumentNullException("displayName", InternalFunctions.GetResourceString("ArgumentNullStringException", "DisplayName")); if (resourcePath == null || resourcePath.Length == 0) { throw new ArgumentNullException("resourcePath", InternalFunctions.GetResourceString("ArgumentNullStringException", "ResourcePath")); } //Populate the class properties hashtable foreach (PropertyInfo _property in this.GetType().GetProperties()) { bool _includeProperty = true; //Check to see if we should include this property ResourcePropertyAttribute _propertyAttribute = Attribute.GetCustomAttribute(_property, typeof(ResourcePropertyAttribute)) as ResourcePropertyAttribute; if (_propertyAttribute != null) { _includeProperty = _propertyAttribute.EnableAutoDiscovery; } if (_includeProperty) { if (!this.__classProperties.ContainsKey(_property.Name)) { this.__classProperties.Add(_property.Name, _property); } } } this.CustomProperties = new DavPropertyCollection(); }
/// <summary> /// WebDav Property. /// </summary> /// <param name="property"></param> public DavProperty(XPathNavigator property) { if (property == null) { throw new ArgumentNullException("property", InternalFunctions.GetResourceString("ArgumentNullException", "Property")); } else if (property.NodeType != XPathNodeType.Element) { throw new ArgumentException(InternalFunctions.GetResourceString("XPathNavigatorElementArgumentException", "Property"), "property"); } base.Name = property.LocalName; base.Namespace = property.NamespaceURI; if (property.HasAttributes) { //TODO: Support element attributes //string _here = ""; //Add the attributes first // foreach (XmlAttribute _xmlAttribute in property.Attributes) // Attributes.Add(new DavPropertyAttribute(_xmlAttribute)); } if (property.MoveToFirstChild()) { if (property.NodeType == XPathNodeType.Element) { NestedProperties.Add(new DavProperty(property.Clone())); while (property.MoveToNext()) { if (property.NodeType == XPathNodeType.Element) { NestedProperties.Add(new DavProperty(property.Clone())); } } } else if (property.NodeType == XPathNodeType.Text) { base.Value = property.Value; property.MoveToParent(); } } }
/// <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); } } }