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; } }
private int DavGetBase_InternalProcessDavRequest(object sender, EventArgs e) { var etag = string.Empty; var fileInfo = FileWrapper.Current.File?.FileInfo; if (fileInfo != null && fileInfo.Exists) { var davFile = new DavFile(fileInfo); etag = $"\"{davFile.ETag}\""; base.HttpApplication.Response.Headers["ETag"] = etag; var ifNoneMatch = base.HttpApplication.Request.Headers["If-None-Match"]; if (ifNoneMatch != null) { if (ifNoneMatch == etag) { return(304); } } } else { return((int)ServerResponseCode.NotFound); } base.HttpApplication.Response.Cache.SetCacheability(ResponseCache); if (ResponseCacheExpiration != DateTime.MinValue) { this.HttpApplication.Response.Cache.SetExpires(ResponseCacheExpiration); } if (this.ResponseOutput.Length > 0) { //Write the response using (BinaryWriter _outputStream = new BinaryWriter(base.HttpApplication.Response.OutputStream)) { _outputStream.Write(this.ResponseOutput); _outputStream.Close(); } } return((int)ServerResponseCode.Ok); //DavGetResponseCode.Created; }
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; } } }
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; } } }