Пример #1
0
        private void DavHead_ProcessDavRequest(object sender, EventArgs e)
        {
            FileInfo _fileInfo = FileWrapper.Current.File.FileInfo;

            if (_fileInfo != null)
            {
                //TODO: handle versions

                DavFile _davFile = new DavFile(_fileInfo.Name, FileWrapper.Current.FullPath);
                _davFile.CreationDate = _fileInfo.CreationTime;
                _davFile.LastModified = _fileInfo.LastWriteTime.ToUniversalTime();

                //Check to see if there are any locks on the resource
                DavLockProperty _lockInfo = FileWrapper.Current.GetLockInfo(_fileInfo.FullName);
                if (_lockInfo != null)
                {
                    _davFile.ActiveLocks.Add(_lockInfo);
                }

                //Check to see if there are any custom properties on the resource
                DavPropertyCollection _customProperties = FileWrapper.Current.GetCustomPropertyInfo(_fileInfo.FullName);
                if (_customProperties != null)
                {
                    _davFile.CustomProperties.Copy(_customProperties);
                }

                _davFile.SupportsExclusiveLock = true;
                _davFile.SupportsSharedLock    = true;
                _davFile.ContentLength         = (int)_fileInfo.Length;

                //Set the resource
                base.Resource = _davFile;
            }
        }
Пример #2
0
        public DavPropertyCollection GetCustomPropertyInfo(string filePath)
        {
            DavPropertyCollection _customProperties = null;

            //Try to deserialize the property file
            string _propFilePath = GetCustomPropertyInfoFilePath(filePath);

            if (_propFilePath != null)
            {
                try
                {
                    FileInfo _propFile = new FileInfo(_propFilePath);
                    if (_propFile.Exists)
                    {
                        using (Stream _propFileStream = _propFile.Open(FileMode.Open))
                        {
                            BinaryFormatter _binaryFormatter = new BinaryFormatter();
                            _customProperties = (DavPropertyCollection)_binaryFormatter.Deserialize(_propFileStream);
                            _propFileStream.Close();
                        }
                    }
                }
                catch (Exception)
                {
                    //Incase the deserialization fails
                }
            }

            return(_customProperties);
        }
Пример #3
0
        /// <summary>
        /// Append a resource to the xml text writer
        /// </summary>
        /// <param name="davResource"></param>
        /// <param name="requestedProperties"></param>
        /// <param name="xmlWriter"></param>
        private static void AppendResourceNode(DavResourceBase davResource, DavPropertyCollection requestedProperties, XmlTextWriter xmlWriter)
        {
            DavPropertyCollection _validProperties   = new DavPropertyCollection();
            DavPropertyCollection _invalidProperties = new DavPropertyCollection();

            davResource.GetPropertyValues(requestedProperties, _validProperties, _invalidProperties);

            //Open the response element
            xmlWriter.WriteStartElement("response", "DAV:");

            //Load the valid items HTTP/1.1 200 OK
            xmlWriter.WriteElementString("href", "DAV:", davResource.ResourcePath);

            //Open the propstat element section
            xmlWriter.WriteStartElement("propstat", "DAV:");

            //Open the prop element section
            xmlWriter.WriteStartElement("prop", "DAV:");

            //Load the valid properties
            foreach (DavProperty _davProperty in _validProperties)
            {
                _davProperty.ToXML(xmlWriter);
            }

            //Close the prop element section
            xmlWriter.WriteEndElement();

            //Write the status record
            xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.Ok));

            //Close the propstat element section
            xmlWriter.WriteEndElement();
            //END Load the valid items HTTP/1.1 200 OK

            //Load the invalid items HTTP/1.1 404 Not Found
            if (_invalidProperties.Count > 0)
            {
                xmlWriter.WriteStartElement("propstat", "DAV:");
                xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.NotFound));

                //Open the prop element section
                xmlWriter.WriteStartElement("prop", "DAV:");

                //Load all the invalid properties
                foreach (DavProperty _davProperty in _invalidProperties)
                {
                    _davProperty.ToXML(xmlWriter);
                }

                //Close the prop element section
                xmlWriter.WriteEndElement();
                //Close the propstat element section
                xmlWriter.WriteEndElement();
            }
            //END Load the invalid items HTTP/1.1 404 Not Found

            //Close the response element
            xmlWriter.WriteEndElement();
        }
Пример #4
0
        /// <summary>
        /// Load the requested properties
        /// </summary>
        /// <param name="properties">Requested properties or null for all properties</param>
        /// <returns></returns>
        internal int LoadNodes(DavPropertyCollection properties)
        {
            using (Stream _responseStream = new MemoryStream())
            {
                XmlTextWriter _xmlWriter = new XmlTextWriter(_responseStream, new UTF8Encoding(false));

                _xmlWriter.Formatting  = Formatting.Indented;
                _xmlWriter.IndentChar  = '\t';
                _xmlWriter.Indentation = 1;
                _xmlWriter.WriteStartDocument();

                //Set the Multistatus
                _xmlWriter.WriteStartElement("D", "multistatus", "DAV:");

                //Append the folders
                foreach (DavFolder _davFolder in CollectionResources)
                {
                    AppendResourceNode(_davFolder, properties, _xmlWriter);
                }

                //Append the files
                foreach (DavFile _davFile in FileResources)
                {
                    AppendResourceNode(_davFile, properties, _xmlWriter);
                }

                //Append the files
                foreach (DavResourceBase _missingResource in MissingResources)
                {
                    AppendResourceNode(_missingResource, properties, _xmlWriter);
                }

                _xmlWriter.WriteEndElement();
                _xmlWriter.WriteEndDocument();
                _xmlWriter.Flush();

                base.SetResponseXml(_responseStream);
                _xmlWriter.Close();
            }
            return((int)ServerResponseCode.MultiStatus);
        }
Пример #5
0
        /// <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);
                }
            }
        }
Пример #6
0
		/// <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("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
										}
										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);
			}
		}
Пример #7
0
        /// <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);
                }
            }
        }
Пример #8
0
        private void DavPropFind_ProcessDavRequest(object sender, EventArgs e)
        {
            //Set the CollectionResources and DavFile
            DirectoryInfo _dirInfo = FileWrapper.Current.File.FileInfo.Directory;

            if (_dirInfo == null)
            {
                FileInfo _fileInfo = FileWrapper.Current.File.FileInfo;

                if (_fileInfo != null)
                {
                    //TODO: handle versions

                    DavFile _davFile = new DavFile(_fileInfo.Name, XDav.Config.ConfigManager.DavPath);
                    _davFile.CreationDate = _fileInfo.CreationTime;
                    _davFile.LastModified = _fileInfo.LastWriteTime.ToUniversalTime();


                    //Check to see if there are any locks on the resource
                    DavLockProperty _lockInfo = FileWrapper.Current.GetLockInfo(_fileInfo.FullName);
                    if (_lockInfo != null)
                    {
                        _davFile.ActiveLocks.Add(_lockInfo);
                    }

                    //Check to see if there are any custom properties on the resource
                    DavPropertyCollection _customProperties = FileWrapper.Current.GetCustomPropertyInfo(_fileInfo.FullName);
                    if (_customProperties != null)
                    {
                        _davFile.CustomProperties.Copy(_customProperties);
                    }

                    _davFile.SupportsExclusiveLock = true;
                    _davFile.SupportsSharedLock    = true;
                    _davFile.ContentLength         = (int)_fileInfo.Length;

                    base.FileResources.Add(_davFile);
                }
            }
            else
            {
                //Don't include any additional resources
                DavFolder _rootResource;
                if (base.RelativeRequestPath.Length == 0)
                {
                    _rootResource = new DavFolder("DavWWWRoot", XDav.Config.ConfigManager.DavPath);
                }
                else
                {
                    _rootResource = new DavFolder(_dirInfo.Name, XDav.Config.ConfigManager.DavPath);
                }

                _rootResource.CreationDate  = _dirInfo.CreationTime.ToUniversalTime();
                _rootResource.LastModified  = _dirInfo.LastWriteTime.ToUniversalTime();
                _rootResource.ContentLength = _dirInfo.GetDirectories().Length + _dirInfo.GetFiles().Length;

                base.CollectionResources.Add(_rootResource);


                //TODO: Only populate the requested properties
                switch (base.RequestDepth)
                {
                case DepthType.ResourceOnly:
                    break;

                default:
                    foreach (DirectoryInfo _subDir in _dirInfo.GetDirectories())
                    {
                        //TODO: Only populate the requested properties
                        DavFolder _davFolder = new DavFolder(_subDir.Name, XDav.Config.ConfigManager.DavPath + _subDir.Name);
                        _davFolder.CreationDate  = _subDir.CreationTime.ToUniversalTime();
                        _davFolder.LastModified  = _subDir.LastWriteTime.ToUniversalTime();
                        _davFolder.ContentLength = _subDir.GetDirectories().Length + _subDir.GetFiles().Length;

                        base.CollectionResources.Add(_davFolder);
                    }

                    foreach (FileInfo _fileInfo in _dirInfo.GetFiles())
                    {
                        //Hide all the lock / custom property information...
                        //	this is maintained in a separate file as an example
                        if (_fileInfo.Extension == ".version")
                        {
                            //Do nothing
                        }
                        else if (_fileInfo.Extension == ".latestVersion")
                        {
                            string _fileName = FileWrapper.Current.ParseVersionFileName(_fileInfo);

                            //TODO: Only populate the requested properties
                            DavFile _davFile = new DavFile(_fileName, Path.Combine(XDav.Config.ConfigManager.DavPath, _fileName));
                            _davFile.CreationDate = _fileInfo.CreationTime.ToUniversalTime();
                            _davFile.LastModified = _fileInfo.LastWriteTime.ToUniversalTime();

                            _davFile.SupportsExclusiveLock = true;
                            _davFile.SupportsSharedLock    = true;
                            _davFile.ContentLength         = (int)_fileInfo.Length;

                            //Check to see if there are any locks on the resource
                            DavLockProperty _lockInfo = FileWrapper.Current.GetLockInfo(_fileInfo.FullName);
                            if (_lockInfo != null)
                            {
                                _davFile.ActiveLocks.Add(_lockInfo);
                            }

                            //Check to see if there are any custom properties on the resource
                            DavPropertyCollection _customProperties = FileWrapper.Current.GetCustomPropertyInfo(_fileInfo.FullName);

                            if (_customProperties != null)
                            {
                                _davFile.CustomProperties.Copy(_customProperties);
                            }

                            base.FileResources.Add(_davFile);
                        }
                        else if (_fileInfo.Extension != ".locked" && _fileInfo.Extension != ".property")
                        {
                            //TODO: Only populate the requested properties
                            DavFile _davFile = new DavFile(_fileInfo.Name, Path.Combine(XDav.Config.ConfigManager.DavPath, _fileInfo.Name));
                            _davFile.CreationDate = _fileInfo.CreationTime;
                            _davFile.LastModified = _fileInfo.LastWriteTime.ToUniversalTime();

                            _davFile.SupportsExclusiveLock = true;
                            _davFile.SupportsSharedLock    = true;
                            _davFile.ContentLength         = (int)_fileInfo.Length;


                            //Check to see if there are any locks on the resource
                            DavLockProperty _lockInfo = FileWrapper.Current.GetLockInfo(_fileInfo.FullName);
                            if (_lockInfo != null)
                            {
                                _davFile.ActiveLocks.Add(_lockInfo);
                            }

                            //Check to see if there are any custom properties on the resource
                            DavPropertyCollection _customProperties = FileWrapper.Current.GetCustomPropertyInfo(_fileInfo.FullName);

                            if (_customProperties != null)
                            {
                                _davFile.CustomProperties.Copy(_customProperties);
                            }

                            base.FileResources.Add(_davFile);
                        }
                    }
                    break;
                }
            }
        }
Пример #9
0
		/// <summary>
		/// Append a resource to the xml text writer
		/// </summary>
		/// <param name="davResource"></param>
		/// <param name="requestedProperties"></param>
		/// <param name="xmlWriter"></param>
		private static void AppendInvalidResourceNode(DavResourceBase davResource, DavPropertyCollection requestedProperties, XmlTextWriter xmlWriter)
		{
			DavPropertyCollection _validProperties = new DavPropertyCollection();
			DavPropertyCollection _invalidProperties = new DavPropertyCollection();

			davResource.GetPropertyValues(requestedProperties, _validProperties, _invalidProperties);

			//Open the response element
			xmlWriter.WriteStartElement("response", "DAV:");

			//Load the valid items HTTP/1.1 200 OK
			xmlWriter.WriteElementString("href", "DAV:", davResource.ResourcePath);

			//Open the propstat element section
			xmlWriter.WriteStartElement("propstat", "DAV:");

			//Open the prop element section
			xmlWriter.WriteStartElement("prop", "DAV:");

			//Load the valid properties
			foreach (DavProperty _davProperty in _validProperties)
				_davProperty.ToXML(xmlWriter);

			//Close the prop element section
			xmlWriter.WriteEndElement();

			//Write the status record
			xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.Ok));

			//Close the propstat element section
			xmlWriter.WriteEndElement();
			//END Load the valid items HTTP/1.1 200 OK

			//Load the invalid items HTTP/1.1 404 Not Found
			if (_invalidProperties.Count > 0)
			{
				xmlWriter.WriteStartElement("propstat", "DAV:");

				//Open the prop element section
				xmlWriter.WriteStartElement("prop", "DAV:");

				//Load all the invalid properties
				foreach (DavProperty _davProperty in _invalidProperties)
					_davProperty.ToXML(xmlWriter);

				//Close the prop element section
				xmlWriter.WriteEndElement();

				//Write the status record
				xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.NotFound));

				//Close the propstat element section
				xmlWriter.WriteEndElement();
			}
			//END Load the invalid items HTTP/1.1 404 Not Found

			//Close the response element
			xmlWriter.WriteEndElement();
		}
Пример #10
0
		/// <summary>
		/// Load the requested properties
		/// </summary>
		/// <param name="properties">Requested properties or null for all properties</param>
		/// <returns></returns>
		internal int LoadNodes(DavPropertyCollection properties)
		{
			using (Stream _responseStream = new MemoryStream())
			{
				XmlTextWriter _xmlWriter = new XmlTextWriter(_responseStream, new UTF8Encoding(false));

				_xmlWriter.Formatting = Formatting.Indented;
				_xmlWriter.IndentChar = '\t';
				_xmlWriter.Indentation = 1;
				_xmlWriter.WriteStartDocument();

				//Set the Multistatus
				_xmlWriter.WriteStartElement("D", "multistatus", "DAV:");

				//Append the folders
				foreach (DavFolder _davFolder in CollectionResources)
					AppendResourceNode(_davFolder, properties, _xmlWriter);

				//Append the files
				foreach (DavFile _davFile in FileResources)
					AppendResourceNode(_davFile, properties, _xmlWriter);

				//Append the files
				foreach (DavResourceBase _missingResource in MissingResources)
					AppendResourceNode(_missingResource, properties, _xmlWriter);

				_xmlWriter.WriteEndElement();
				_xmlWriter.WriteEndDocument();
				_xmlWriter.Flush();

				base.SetResponseXml(_responseStream);
				_xmlWriter.Close();
			}
			return (int)ServerResponseCode.MultiStatus;
		}
Пример #11
0
        private void DavPropPatch_ProcessDavRequest(object sender, EventArgs e)
        {
            //Check to see if we can replace the properties

            //			//Fake out the delete process issue by default
            //			DavFile _junk = new DavFile();
            //			_junk.FilePath = "http://www.bubba.com/nope";
            //
            //			base.AddProcessErrorResource(_junk, DavDeleteResponseCode.Locked);
            //			base.AddProcessErrorResource(_junk, DavDeleteResponseCode.InsufficientStorage);
            //
            //			return;

            //Logic... if anything fails... must rollback!

            //Check to see if the resource exists
            FileInfo _fileInfo = RequestWrapper.GetFile(base.RelativeRequestPath);
            if (_fileInfo != null)
            {
                var _davFile = new DavFile(_fileInfo.Name, RequestWrapper.WebBasePath);
                base.PatchedResource = _davFile;

                //Check to see if there are any custom properties on the resource
                DavPropertyCollection _customProperties = RequestWrapper.GetCustomPropertyInfo(_fileInfo.FullName);
                if (_customProperties == null)
                    _customProperties = new DavPropertyCollection();

                //Update the delta's... remove the deleted properties
                foreach (DavProperty _property in base.RequestDeleteProperties)
                    _customProperties.Remove(_property.Name);

                foreach (DavProperty _property in base.RequestModifyProperties)
                {
                    DavProperty _customProperty = _customProperties[_property.Name];
                    if (_customProperty != null)
                        _customProperties.Remove(_property.Name);

                    _customProperties.Add(_property);
                }

                _davFile.CustomProperties.Copy(_customProperties);
            }
        }