コード例 #1
0
ファイル: DavPropPatch.cs プロジェクト: atallo/webdavserver
        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);
            }
        }
コード例 #2
0
ファイル: DavCopy.cs プロジェクト: atallo/webdavserver
 private void CopyFile(FileInfo _sourceFile, string destination)
 {
     if (_sourceFile != null)
     {
         try
         {
             if (!base.OverwriteExistingResource && File.Exists(destination))
             {
                 var _fileResource = new DavFile(_sourceFile.Name, _sourceFile.Name);
                 base.AddProcessErrorResource(_fileResource, DavCopyResponseCode.PreconditionFailed);
             }
             else
                 _sourceFile.CopyTo(destination, base.OverwriteExistingResource);
         }
         catch (Exception)
         {
             var _fileResource = new DavFile(_sourceFile.Name, _sourceFile.Name);
             base.AddProcessErrorResource(_fileResource, DavCopyResponseCode.Forbidden);
         }
     }
 }
コード例 #3
0
ファイル: DavPropFind.cs プロジェクト: Fedorm/core-master
		private void DavPropFind_ProcessDavRequest(object sender, EventArgs e)
		{
            if (HttpContext.Current == null)
                base.AbortRequest(ServerResponseCode.BadRequest);
            else
            {

                String _path = VirtualDirectory.PathInfo(SolutionName);
                String _basePath = HttpContext.Current.Request.Url.AbsoluteUri;

                if (!Path.HasExtension(_basePath) && !_basePath.EndsWith("/"))
                    _basePath += "/";

                FileItem item = Directory.GetItem(_path);

                
                if ((!string.IsNullOrEmpty(_path)) && (!_path.Equals("/")) && (item == null))  // no such item
                {
                    base.AbortRequest(ServerResponseCode.NotFound);
                    return;
                }


                if (item!=null) 
                {
                    if ((item is VirtualFile) || (Directory._fileSystem.FileExists(item.RelativePath))) // file
                    {

                        if (item is VirtualFile)
                        {
                            DavFile _davFile = new DavFile(item.Name, _basePath);
                            _davFile.CreationDate = DateTime.Now.ToUniversalTime();
                            _davFile.LastModified = DateTime.Now.ToUniversalTime();

                            _davFile.SupportsExclusiveLock = true;
                            _davFile.SupportsSharedLock = true;
                            _davFile.ContentLength = 0;

                            base.FileResources.Add(_davFile);
                            return;
                        }

                        FileSystem.ItemInfo _fileInfo = Directory._fileSystem.GetFileInfo(item.RelativePath);

                        if (_fileInfo != null)
                        {

                            DavFile _davFile = new DavFile(_fileInfo.Name, _basePath);
                            _davFile.CreationDate = _fileInfo.CreationTime;
                            _davFile.LastModified = _fileInfo.LastWriteTime;

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

                            base.FileResources.Add(_davFile);
                            return;
                        }
                    }
                }
                //dir
                DavFolder _rootResource;
                FileSystem.ItemInfo _dirInfo;
                if (item == null)
                {
                    _rootResource = new DavFolder("DavWWWRoot", _basePath);
                    _dirInfo = Directory._fileSystem.GetDirectoryInfo("");
                }
                else
                {
                    _dirInfo = Directory._fileSystem.GetDirectoryInfo(item.RelativePath);
                    _rootResource = new DavFolder(_dirInfo.Name, _basePath);
                }
                _rootResource.CreationDate = _dirInfo.CreationTime;
                _rootResource.LastModified = _dirInfo.LastWriteTime;
                _rootResource.ContentLength = (int)_dirInfo.Length;

                base.CollectionResources.Add(_rootResource);


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

                    default:

                        if (item == null) //root dir
                        {

                            foreach (FileItem subItem in Directory.items)
                            {
                                if (subItem is VirtualFile)
                                {
                                    DavFile _davFile = new DavFile(subItem.Name, _basePath + subItem.Name);
                                    _davFile.CreationDate = DateTime.Now.ToUniversalTime();
                                    _davFile.LastModified = DateTime.Now.ToUniversalTime();

                                    _davFile.SupportsExclusiveLock = true;
                                    _davFile.SupportsSharedLock = true;
                                    _davFile.ContentLength = 0;

                                    base.FileResources.Add(_davFile);
                                }
                                else
                                {
                                    DavFolder _davFolder = new DavFolder(subItem.Name, _basePath + subItem.Name);
                                    FileSystem.ItemInfo _subDir = Directory._fileSystem.GetDirectoryInfo(subItem.RelativePath);

                                    _davFolder.CreationDate = _subDir.CreationTime;
                                    _davFolder.LastModified = _subDir.LastWriteTime;
                                    _davFolder.ContentLength =  (int)_subDir.Length;
                                    base.CollectionResources.Add(_davFolder);
                                }
                            }
                        }
                        else // non root dir
                        {
                            foreach (FileSystem.ItemInfo _subDir in Directory._fileSystem.EnumerateDirectories(item.RelativePath))
                            {
                                //TODO: Only populate the requested properties
                                DavFolder _davFolder = new DavFolder(_subDir.Name, _basePath + _subDir.Name);
                                _davFolder.CreationDate = _subDir.CreationTime;
                                _davFolder.LastModified = _subDir.LastWriteTime;
                                _davFolder.ContentLength = (int)_subDir.Length;

                                base.CollectionResources.Add(_davFolder);
                            }

                            foreach (FileSystem.ItemInfo _fileInfo in Directory._fileSystem.EnumerateFiles(item.RelativePath))
                            {
                                //TODO: Only populate the requested properties
                                DavFile _davFile = new DavFile(_fileInfo.Name, _basePath +  _fileInfo.Name);
                                _davFile.CreationDate = _fileInfo.CreationTime;
                                _davFile.LastModified = _fileInfo.LastWriteTime;

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



                                base.FileResources.Add(_davFile);
                            }
                        }
                        break;
                    }
                }
		}
コード例 #4
0
ファイル: DavPropFind.cs プロジェクト: atallo/webdavserver
        private void DavPropFind_ProcessDavRequest(object sender, EventArgs e)
        {
            //Set the CollectionResources and DavFile
            DirectoryInfo _dirInfo = RequestWrapper.GetDirectory(base.RelativeRequestPath);

            if (_dirInfo == null)
            {
                FileInfo _fileInfo = RequestWrapper.GetFile(base.RelativeRequestPath);

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

                    var _davFile = new DavFile(_fileInfo.Name, RequestWrapper.WebBasePath);
                    _davFile.CreationDate = _fileInfo.CreationTime;
                    _davFile.LastModified = _fileInfo.LastWriteTime.ToUniversalTime();

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

                    //Check to see if there are any custom properties on the resource
                    DavPropertyCollection _customProperties = RequestWrapper.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", RequestWrapper.WebBasePath);
                else
                    _rootResource = new DavFolder(_dirInfo.Name, RequestWrapper.WebBasePath);

                _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 Sphorium.WebDAV.Server.Framework.DepthType.ResourceOnly:
                        break;

                    default:
                        foreach (DirectoryInfo _subDir in _dirInfo.GetDirectories())
                        {
                            //TODO: Only populate the requested properties
                            var _davFolder = new DavFolder(_subDir.Name, RequestWrapper.WebBasePath + _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 = RequestWrapper.ParseVersionFileName(_fileInfo);

                                //TODO: Only populate the requested properties
                                var _davFile = new DavFile(_fileName, Path.Combine(RequestWrapper.WebBasePath, _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 = RequestWrapper.GetLockInfo(_fileInfo.FullName);
                                if (_lockInfo != null)
                                    _davFile.ActiveLocks.Add(_lockInfo);

                                //Check to see if there are any custom properties on the resource
                                DavPropertyCollection _customProperties = RequestWrapper.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
                                var _davFile = new DavFile(_fileInfo.Name, Path.Combine(RequestWrapper.WebBasePath, _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 = RequestWrapper.GetLockInfo(_fileInfo.FullName);
                                if (_lockInfo != null)
                                    _davFile.ActiveLocks.Add(_lockInfo);

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

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

                                base.FileResources.Add(_davFile);
                            }
                        }
                        break;
                }
            }
        }