提交 1642b2b1 编写于 作者: JasonWcx's avatar JasonWcx

调整命名空间

上级 3f37c053
...@@ -103,11 +103,11 @@ ...@@ -103,11 +103,11 @@
<Compile Include="StatusCode.cs" /> <Compile Include="StatusCode.cs" />
<Compile Include="Encode\StringEncoder.cs" /> <Compile Include="Encode\StringEncoder.cs" />
<Compile Include="TransformHeader.cs" /> <Compile Include="TransformHeader.cs" />
<Compile Include="WebDav\Exception\ConflictException.cs" /> <Compile Include="WebDav\Exceptions\ConflictException.cs" />
<Compile Include="WebDav\Exception\WebDavException.cs" /> <Compile Include="WebDav\Exceptions\WebDavException.cs" />
<Compile Include="WebDav\Exception\ForbiddenException.cs" /> <Compile Include="WebDav\Exceptions\ForbiddenException.cs" />
<Compile Include="WebDav\Exception\NotFoundException.cs" /> <Compile Include="WebDav\Exceptions\NotFoundException.cs" />
<Compile Include="WebDav\Exception\UnauthorizedException.cs" /> <Compile Include="WebDav\Exceptions\UnauthorizedException.cs" />
<Compile Include="WebDav\LockProperty.cs" /> <Compile Include="WebDav\LockProperty.cs" />
<Compile Include="WebDav\Method\Copy.cs" /> <Compile Include="WebDav\Method\Copy.cs" />
<Compile Include="WebDav\Method\Delete.cs" /> <Compile Include="WebDav\Method\Delete.cs" />
...@@ -121,9 +121,9 @@ ...@@ -121,9 +121,9 @@
<Compile Include="WebDav\Method\Put.cs" /> <Compile Include="WebDav\Method\Put.cs" />
<Compile Include="WebDav\Method\Unlock.cs" /> <Compile Include="WebDav\Method\Unlock.cs" />
<Compile Include="WebDav\Method\MethodHandlerBase.cs" /> <Compile Include="WebDav\Method\MethodHandlerBase.cs" />
<Compile Include="WebDav\Storage\BaseClasses\WebDAVStoreBase.cs" /> <Compile Include="WebDav\Storage\Base\WebDAVStoreBase.cs" />
<Compile Include="WebDav\Storage\BaseClasses\WebDAVStoreDocumentBase.cs" /> <Compile Include="WebDav\Storage\Base\WebDAVStoreDocumentBase.cs" />
<Compile Include="WebDav\Storage\BaseClasses\WebDAVStoreItemBase.cs" /> <Compile Include="WebDav\Storage\Base\WebDAVStoreItemBase.cs" />
<Compile Include="WebDav\Storage\DiskStore\WebDAVDiskStore.cs" /> <Compile Include="WebDav\Storage\DiskStore\WebDAVDiskStore.cs" />
<Compile Include="WebDav\Storage\DiskStore\DiskStoreCollection.cs" /> <Compile Include="WebDav\Storage\DiskStore\DiskStoreCollection.cs" />
<Compile Include="WebDav\Storage\DiskStore\DiskStoreDocument.cs" /> <Compile Include="WebDav\Storage\DiskStore\DiskStoreDocument.cs" />
......
using System; using System;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
namespace Mozi.HttpEmbedded.WebDav namespace Mozi.HttpEmbedded.WebDav
{ {
......
using System.Collections.Generic; using System.Collections.Generic;
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
using Mozi.HttpEmbedded.WebDav.Method; using Mozi.HttpEmbedded.WebDav.Method;
using Mozi.HttpEmbedded.WebDav.MethodHandlers;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
using Mozi.HttpEmbedded.WebDav.Storage.DiskStore; using Mozi.HttpEmbedded.WebDav.Storage.DiskStore;
......
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Exception namespace Mozi.HttpEmbedded.WebDav.Exceptions
{ {
/// <summary> /// <summary>
/// 409 /// 409
......
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Exception namespace Mozi.HttpEmbedded.WebDav.Exceptions
{ {
/// <summary> /// <summary>
/// 403 /// 403
......
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Exception namespace Mozi.HttpEmbedded.WebDav.Exceptions
{ {
/// <summary> /// <summary>
/// 404 /// 404
......
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Exception namespace Mozi.HttpEmbedded.WebDav.Exceptions
{ {
/// <summary> /// <summary>
/// ///
......
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Exception namespace Mozi.HttpEmbedded.WebDav.Exceptions
{ {
/// <summary> /// <summary>
/// </summary> /// </summary>
[Serializable] [Serializable]
public class WebDavException : Exception public class WebDavException : System.Exception
{ {
private StatusCode _status; private StatusCode _status;
private string message; private string message;
public override string Message { get; } public override string Message { get; }
public WebDavException(StatusCode status, string message, Exception innerException) public WebDavException(StatusCode status, string message, System.Exception innerException)
{ {
_status = status; _status = status;
Message = message; Message = message;
......
using Mozi.HttpEmbedded.Common; using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.WebDav.MethodHandlers;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.Method namespace Mozi.HttpEmbedded.WebDav.Method
...@@ -23,27 +22,27 @@ namespace Mozi.HttpEmbedded.WebDav.Method ...@@ -23,27 +22,27 @@ namespace Mozi.HttpEmbedded.WebDav.Method
IWebDavStoreItem source = WebDavExtensions.GetStoreItem(context.Request.Path, store); IWebDavStoreItem source = WebDavExtensions.GetStoreItem(context.Request.Path, store);
if (source is IWebDavStoreDocument || source is IWebDavStoreCollection) if (source is IWebDavStoreDocument || source is IWebDavStoreCollection)
{ {
string destinationUri = context.Request.Headers["Destination"]; string destPath = context.Request.Headers["destItem"];
IWebDavStoreCollection destinationParentCollection = GetParentCollection(store, destinationUri); IWebDavStoreCollection destParentCollection = GetParentCollection(store, destPath);
bool copyContent = GetDepthHeader(context.Request) != 0; bool copyContent = GetDepthHeader(context.Request) != 0;
bool isNew = true; bool isNew = true;
UrlTree ut = new UrlTree(destinationUri); UrlTree ut = new UrlTree(destPath);
string destinationName = UrlEncoder.Decode(ut.Last().TrimEnd('/', '\\')); string destName = UrlEncoder.Decode(ut.Last().TrimEnd('/', '\\'));
IWebDavStoreItem destination = destinationParentCollection.GetItemByName(destinationName); IWebDavStoreItem destItem = destParentCollection.GetItemByName(destName);
if (destination != null) if (destItem != null)
{ {
if (source.ItemPath == destination.ItemPath) if (source.ItemPath == destItem.ItemPath)
return StatusCode.Forbidden; return StatusCode.Forbidden;
if (!GetOverwriteHeader(context.Request)) if (!GetOverwriteHeader(context.Request))
return StatusCode.PreconditionFailed; return StatusCode.PreconditionFailed;
if (destination is IWebDavStoreCollection) if (destItem is IWebDavStoreCollection)
destinationParentCollection.Delete(destination); destParentCollection.Delete(destItem);
isNew = false; isNew = false;
} }
destinationParentCollection.CopyItemHere(source, destinationName, copyContent); destParentCollection.CopyItemHere(source, destName, copyContent);
return isNew ? StatusCode.Created : StatusCode.NoContent; return isNew ? StatusCode.Created : StatusCode.NoContent;
} }
else else
......
using Mozi.HttpEmbedded.WebDav.MethodHandlers;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.Method namespace Mozi.HttpEmbedded.WebDav.Method
......
using Mozi.HttpEmbedded.Source; using Mozi.HttpEmbedded.Source;
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// <c>PROPFIND</c> WebDAV윈嵐렘랬 /// <c>PROPFIND</c> WebDAV윈嵐렘랬
......
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// </summary> /// </summary>
......
using System; using System;
using System.Text;
using System.Xml; using System.Xml;
using Mozi.HttpEmbedded.Common; using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// <c>LOCK</c> WebDAV扩展方法 /// <c>LOCK</c> WebDAV扩展方法
...@@ -88,8 +87,8 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -88,8 +87,8 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
collection.CreateDocument(ut.Last().TrimEnd('/', '\\')); collection.CreateDocument(ut.Last().TrimEnd('/', '\\'));
isNew = true; isNew = true;
} }
/*************************************************************************************************** /***************************************************************************************************
* Create the body for the response * Create the body for the response
...@@ -97,7 +96,7 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -97,7 +96,7 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
//实例化XML文档 //实例化XML文档
XmlDocument responseDoc = new XmlDocument(); XmlDocument responseDoc = new XmlDocument();
string responseXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:prop " +"xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock/></D:lockdiscovery></D:prop>"; string responseXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:prop " + "xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock/></D:lockdiscovery></D:prop>";
responseDoc.LoadXml(responseXml); responseDoc.LoadXml(responseXml);
//锁定节点 //锁定节点
...@@ -113,9 +112,9 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -113,9 +112,9 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
activelock.AppendChild(timeoutProperty.ToXmlElement(responseDoc)); activelock.AppendChild(timeoutProperty.ToXmlElement(responseDoc));
// depth头属性 // depth头属性
WebDavProperty depthProperty = new WebDavProperty("depth", (depth == 0 ? "0" : "Infinity")); WebDavProperty depthProperty = new WebDavProperty("depth", depth == 0 ? "0" : "Infinity");
activelock.AppendChild(depthProperty.ToXmlElement(responseDoc)); activelock.AppendChild(depthProperty.ToXmlElement(responseDoc));
// locktoken头属性 // locktoken头属性
WebDavProperty locktokenProperty = new WebDavProperty("locktoken", ""); WebDavProperty locktokenProperty = new WebDavProperty("locktoken", "");
XmlElement locktokenElement = locktokenProperty.ToXmlElement(responseDoc); XmlElement locktokenElement = locktokenProperty.ToXmlElement(responseDoc);
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.Common; using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// </summary> /// </summary>
...@@ -21,9 +21,9 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -21,9 +21,9 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
} }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {
throw new WebDavUnauthorizedException(); throw new WebDavUnauthorizedException();
} }
catch(WebDavNotFoundException) catch (WebDavNotFoundException)
{ {
throw new WebDavConflictException(); throw new WebDavConflictException();
} }
...@@ -51,32 +51,30 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -51,32 +51,30 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
{ {
throw new WebDavNotFoundException(); throw new WebDavNotFoundException();
} }
if (item == null) if (item != null)
throw new WebDavNotFoundException(); {
return item;
return item; }
throw new WebDavNotFoundException();
} }
public static int GetDepthHeader(HttpRequest request) public static int GetDepthHeader(HttpRequest request)
{ {
string depth = request.Headers["Depth"]; string depth = request.Headers["Depth"];
if (string.IsNullOrEmpty(depth) || depth.Equals("infinity")) if (!string.IsNullOrEmpty(depth) && !depth.Equals("infinity"))
{
return DepthInfinity;
}
int value;
if (!int.TryParse(depth, out value))
{ {
int value;
if (int.TryParse(depth, out value))
{
if (value == 0 || value == 1)
{
return value;
}
return DepthInfinity;
}
return DepthInfinity; return DepthInfinity;
} }
if (value == 0 || value == 1)
{
return value;
}
return DepthInfinity; return DepthInfinity;
} }
...@@ -98,15 +96,14 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -98,15 +96,14 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
} }
return timeout; return timeout;
} }
public static Uri GetDestinationHeader(HttpRequest request) public static Uri GetdestItemHeader(HttpRequest request)
{ {
string destinationUri = request.Headers["Destination"]; string destPath = request.Headers["destItem"];
if (!string.IsNullOrEmpty(destinationUri)) if (string.IsNullOrEmpty(destPath))
return new Uri(destinationUri); throw new WebDavConflictException();
return new Uri(destPath);
throw new WebDavConflictException();
} }
} }
} }
...@@ -2,7 +2,7 @@ using Mozi.HttpEmbedded.Common; ...@@ -2,7 +2,7 @@ using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// <c>MKCOL</c> WebDAVչ /// <c>MKCOL</c> WebDAVչ
...@@ -19,17 +19,19 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -19,17 +19,19 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
/// <param name="store"><see cref="IWebDavStore" /> <see cref="DavServer" /></param> /// <param name="store"><see cref="IWebDavStore" /> <see cref="DavServer" /></param>
public StatusCode ProcessRequest(DavServer server, HttpContext context, IWebDavStore store) public StatusCode ProcessRequest(DavServer server, HttpContext context, IWebDavStore store)
{ {
if (context.Request.Body.Length > 0) if (context.Request.Body.Length == 0)
return StatusCode.UnsupportedMediaType; {
IWebDavStoreCollection collection = GetParentCollection(store, context.Request.Path.Replace("/","\\")); IWebDavStoreCollection collection = GetParentCollection(store, context.Request.Path.Replace("/", "\\"));
UrlTree ut = new UrlTree(context.Request.Path); UrlTree ut = new UrlTree(context.Request.Path);
string collectionName = UrlEncoder.Decode(ut.Last().TrimEnd('/', '\\')); string collectionName = UrlEncoder.Decode(ut.Last().TrimEnd('/', '\\'));
if (collection.GetItemByName(collectionName) != null) if (collection.GetItemByName(collectionName) != null)
return StatusCode.MethodNotAllowed; return StatusCode.MethodNotAllowed;
collection.CreateCollection(collectionName); collection.CreateCollection(collectionName);
return StatusCode.Success; return StatusCode.Success;
}
return StatusCode.UnsupportedMediaType;
} }
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ using Mozi.HttpEmbedded.Common; ...@@ -2,7 +2,7 @@ using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// <c>MOVE</c> WebDAVչ /// <c>MOVE</c> WebDAVչ
...@@ -21,24 +21,30 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -21,24 +21,30 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
{ {
var source = WebDavExtensions.GetStoreItem(context.Request.Path, store); var source = WebDavExtensions.GetStoreItem(context.Request.Path, store);
string destinationUri = context.Request.Headers["Destination"]; string destPath = context.Request.Headers["destItem"];
IWebDavStoreCollection destinationParentCollection = GetParentCollection(store, destinationUri); IWebDavStoreCollection destParentCollection = GetParentCollection(store, destPath);
bool isNew = true; bool isNew = true;
UrlTree ut = new UrlTree(destinationUri); UrlTree ut = new UrlTree(destPath);
string destinationName = UrlEncoder.Decode(ut.Last().TrimEnd('/', '\\')); string destName = UrlEncoder.Decode(ut.Last().TrimEnd('/', '\\'));
IWebDavStoreItem destination = destinationParentCollection.GetItemByName(destinationName); IWebDavStoreItem destItem = destParentCollection.GetItemByName(destName);
if (destination != null) if (destItem != null)
{ {
if (source.ItemPath == destination.ItemPath) if (source.ItemPath == destItem.ItemPath)
{
return StatusCode.Forbidden; return StatusCode.Forbidden;
}
if (!GetOverwriteHeader(context.Request)) if (!GetOverwriteHeader(context.Request))
{
return StatusCode.PreconditionFailed; return StatusCode.PreconditionFailed;
destinationParentCollection.Delete(destination); }
destParentCollection.Delete(destItem);
isNew = false; isNew = false;
} }
destinationParentCollection.MoveItemHere(source, destinationName); destParentCollection.MoveItemHere(source, destName);
return StatusCode.Success; return StatusCode.Success;
} }
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml; using System.Xml;
using Mozi.HttpEmbedded.WebDav.MethodHandlers;
using Mozi.HttpEmbedded.Common; using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
namespace Mozi.HttpEmbedded.WebDav.Method namespace Mozi.HttpEmbedded.WebDav.Method
{ {
...@@ -15,7 +14,7 @@ namespace Mozi.HttpEmbedded.WebDav.Method ...@@ -15,7 +14,7 @@ namespace Mozi.HttpEmbedded.WebDav.Method
internal class Propfind : MethodHandlerBase, IMethodHandler internal class Propfind : MethodHandlerBase, IMethodHandler
{ {
private string _requestUri; private string _requestUri;
private List<WebDavProperty> _requestedProperties; private List<WebDavProperty> _reqProps;
private List<IWebDavStoreItem> _webDavStoreItems; private List<IWebDavStoreItem> _webDavStoreItems;
/// <summary> /// <summary>
...@@ -46,7 +45,7 @@ namespace Mozi.HttpEmbedded.WebDav.Method ...@@ -46,7 +45,7 @@ namespace Mozi.HttpEmbedded.WebDav.Method
XmlDocument requestDoc = GetXmlDocument(context.Request); XmlDocument requestDoc = GetXmlDocument(context.Request);
//提取请求信息 //提取请求信息
_requestedProperties = new List<WebDavProperty>(); _reqProps = new List<WebDavProperty>();
if (requestDoc.DocumentElement != null) if (requestDoc.DocumentElement != null)
{ {
if (requestDoc.DocumentElement.LocalName != "propfind") if (requestDoc.DocumentElement.LocalName != "propfind")
...@@ -61,25 +60,25 @@ namespace Mozi.HttpEmbedded.WebDav.Method ...@@ -61,25 +60,25 @@ namespace Mozi.HttpEmbedded.WebDav.Method
switch (n.LocalName) switch (n.LocalName)
{ {
case "allprop": case "allprop":
_requestedProperties = GetAllProperties(); _reqProps = GetAllProperties();
break; break;
case "propname": case "propname":
isPropname = true; isPropname = true;
_requestedProperties = GetAllProperties(); _reqProps = GetAllProperties();
break; break;
case "prop": case "prop":
foreach (XmlNode child in n.ChildNodes) foreach (XmlNode child in n.ChildNodes)
_requestedProperties.Add(new WebDavProperty(child.LocalName, "", child.NamespaceURI)); _reqProps.Add(new WebDavProperty(child.LocalName, "", child.NamespaceURI));
break; break;
default: default:
_requestedProperties.Add(new WebDavProperty(n.LocalName, "", n.NamespaceURI)); _reqProps.Add(new WebDavProperty(n.LocalName, "", n.NamespaceURI));
break; break;
} }
} }
} }
} }
else else
_requestedProperties = GetAllProperties(); _reqProps = GetAllProperties();
XmlDocument responseDoc = ResponseDocument(context, isPropname, StatusCode.Success); XmlDocument responseDoc = ResponseDocument(context, isPropname, StatusCode.Success);
...@@ -242,7 +241,7 @@ namespace Mozi.HttpEmbedded.WebDav.Method ...@@ -242,7 +241,7 @@ namespace Mozi.HttpEmbedded.WebDav.Method
WebDavProperty propProperty = new WebDavProperty("prop", ""); WebDavProperty propProperty = new WebDavProperty("prop", "");
XmlElement propElement = propProperty.ToXmlElement(responseDoc); XmlElement propElement = propProperty.ToXmlElement(responseDoc);
foreach (WebDavProperty davProperty in _requestedProperties) foreach (WebDavProperty davProperty in _reqProps)
{ {
propElement.AppendChild(PropChildElement(davProperty, responseDoc, webDavStoreItem, propname)); propElement.AppendChild(PropChildElement(davProperty, responseDoc, webDavStoreItem, propname));
} }
......
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Xml; using System.Xml;
using Mozi.HttpEmbedded.Common; using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// <c>PROPPATCH</c> WebDAV扩展方法 /// <c>PROPPATCH</c> WebDAV扩展方法
...@@ -25,7 +24,7 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -25,7 +24,7 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
/// <param name="store"><see cref="IWebDavStore" /><see cref="DavServer" /></param> /// <param name="store"><see cref="IWebDavStore" /><see cref="DavServer" /></param>
public StatusCode ProcessRequest(DavServer server, HttpContext context, IWebDavStore store) public StatusCode ProcessRequest(DavServer server, HttpContext context, IWebDavStore store)
{ {
string requestUri = context.Request.Path; string requestUri = context.Request.Path;
XmlNamespaceManager manager = null; XmlNamespaceManager manager = null;
...@@ -63,10 +62,6 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -63,10 +62,6 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
Log.Warn(ex.Message); Log.Warn(ex.Message);
} }
/***************************************************************************************************
* Take action
***************************************************************************************************/
//父目录资源清单 //父目录资源清单
IWebDavStoreCollection collection = GetParentCollection(store, context.Request.Path); IWebDavStoreCollection collection = GetParentCollection(store, context.Request.Path);
...@@ -115,20 +110,20 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -115,20 +110,20 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
WebDavProperty propstatProperty = new WebDavProperty("propstat", ""); WebDavProperty propstatProperty = new WebDavProperty("propstat", "");
XmlElement propstatElement = propstatProperty.ToXmlElement(responseDoc); XmlElement propstatElement = propstatProperty.ToXmlElement(responseDoc);
WebDavProperty statusProperty = new WebDavProperty("status", "HTTP/1.1 " + context.Response.Status.Code + " " +context.Response.Status.Text); WebDavProperty statusProperty = new WebDavProperty("status", "HTTP/1.1 " + context.Response.Status.Code + " " + context.Response.Status.Text);
propstatElement.AppendChild(statusProperty.ToXmlElement(responseDoc)); propstatElement.AppendChild(statusProperty.ToXmlElement(responseDoc));
foreach (WebDavProperty property in from XmlNode child in propNode.ChildNodes foreach (WebDavProperty property in from XmlNode child in propNode.ChildNodes
where child.Name.ToLower() where child.Name.ToLower()
.Contains("creationtime") || child.Name.ToLower() .Contains("creationtime") || child.Name.ToLower()
.Contains("fileattributes") || child.Name.ToLower() .Contains("fileattributes") || child.Name.ToLower()
.Contains("lastaccesstime") || child.Name.ToLower() .Contains("lastaccesstime") || child.Name.ToLower()
.Contains("lastmodifiedtime") .Contains("lastmodifiedtime")
let node = propNode.SelectSingleNode(child.Name, manager) let node = propNode.SelectSingleNode(child.Name, manager)
select node != null select node != null
? new WebDavProperty(child.LocalName, "", node.NamespaceURI) ? new WebDavProperty(child.LocalName, "", node.NamespaceURI)
: new WebDavProperty(child.LocalName, "", "")) : new WebDavProperty(child.LocalName, "", ""))
propstatElement.AppendChild(property.ToXmlElement(responseDoc)); propstatElement.AppendChild(property.ToXmlElement(responseDoc));
responseNode.AppendChild(propstatElement); responseNode.AppendChild(propstatElement);
...@@ -137,7 +132,7 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers ...@@ -137,7 +132,7 @@ namespace Mozi.HttpEmbedded.WebDav.MethodHandlers
byte[] responseBytes = StringEncoder.Encode(resp); byte[] responseBytes = StringEncoder.Encode(resp);
context.Response.Headers.Add(HeaderProperty.ContentType.PropertyTag, "text/xml"); context.Response.Headers.Add(HeaderProperty.ContentType.PropertyTag, "text/xml");
context.Response.Write(responseBytes); context.Response.Write(responseBytes);
return StatusCode.MultiStatus; return StatusCode.MultiStatus;
......
using System.IO; using System.IO;
using Mozi.HttpEmbedded.Common; using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Encode; using Mozi.HttpEmbedded.Encode;
using Mozi.HttpEmbedded.WebDav.MethodHandlers;
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.Method namespace Mozi.HttpEmbedded.WebDav.Method
......
using Mozi.HttpEmbedded.WebDav.Storage; using Mozi.HttpEmbedded.WebDav.Storage;
namespace Mozi.HttpEmbedded.WebDav.MethodHandlers namespace Mozi.HttpEmbedded.WebDav.Method
{ {
/// <summary> /// <summary>
/// <c>PUT</c> WebDAV扩展方法 /// <c>PUT</c> WebDAV扩展方法
......
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Storage.BaseClasses namespace Mozi.HttpEmbedded.WebDav.Storage.Base
{ {
/// <summary> /// <summary>
/// This class is a base class for <see cref="IWebDavStore" /> implementations. /// This class is a base class for <see cref="IWebDavStore" /> implementations.
......
using Mozi.HttpEmbedded.Source; using Mozi.HttpEmbedded.Source;
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Storage.BaseClasses namespace Mozi.HttpEmbedded.WebDav.Storage.Base
{ {
/// <summary> /// <summary>
/// This is the base class for <see cref="IWebDavStoreItem" /> implementations. /// This is the base class for <see cref="IWebDavStoreItem" /> implementations.
......
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
using System; using System;
namespace Mozi.HttpEmbedded.WebDav.Storage.BaseClasses namespace Mozi.HttpEmbedded.WebDav.Storage.Base
{ {
/// <summary> /// <summary>
/// This is the base class for <see cref="IWebDavStoreItem" /> implementations. /// This is the base class for <see cref="IWebDavStoreItem" /> implementations.
......
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
...@@ -325,22 +325,22 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -325,22 +325,22 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
/// Copies an existing store item into this collection, overwriting any existing items. /// Copies an existing store item into this collection, overwriting any existing items.
/// </summary> /// </summary>
/// <param name="source">The store item to copy from.</param> /// <param name="source">The store item to copy from.</param>
/// <param name="destinationName">The name of the copy to create of <paramref name="source" />.</param> /// <param name="destName">The name of the copy to create of <paramref name="source" />.</param>
/// <param name="includeContent">The boolean for copying the containing files/folders or not.</param> /// <param name="includeContent">The boolean for copying the containing files/folders or not.</param>
/// <returns> /// <returns>
/// The created <see cref="IWebDavStoreItem" /> instance. /// The created <see cref="IWebDavStoreItem" /> instance.
/// </returns> /// </returns>
/// <exception cref="WebDavUnauthorizedException">If the user is unauthorized or has no access</exception> /// <exception cref="WebDavUnauthorizedException">If the user is unauthorized or has no access</exception>
public IWebDavStoreItem CopyItemHere(IWebDavStoreItem source, string destinationName, bool includeContent) public IWebDavStoreItem CopyItemHere(IWebDavStoreItem source, string destName, bool includeContent)
{ {
string destinationItemPath = Path.Combine(ItemPath, destinationName); string destItemItemPath = Path.Combine(ItemPath, destName);
if (source.IsCollection) if (source.IsCollection)
{ {
try try
{ {
WindowsImpersonationContext wic = Identity.Impersonate(); WindowsImpersonationContext wic = Identity.Impersonate();
DirectoryCopy(source.ItemPath, destinationItemPath, true); DirectoryCopy(source.ItemPath, destItemItemPath, true);
wic.Undo(); wic.Undo();
} }
catch catch
...@@ -348,8 +348,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -348,8 +348,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
throw new WebDavUnauthorizedException(); throw new WebDavUnauthorizedException();
} }
DiskStoreCollection collection = new DiskStoreCollection(this, destinationItemPath); DiskStoreCollection collection = new DiskStoreCollection(this, destItemItemPath);
_items.Add(destinationName, new WeakReference(collection)); _items.Add(destName, new WeakReference(collection));
return collection; return collection;
} }
...@@ -357,7 +357,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -357,7 +357,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
try try
{ {
WindowsImpersonationContext wic = Identity.Impersonate(); WindowsImpersonationContext wic = Identity.Impersonate();
System.IO.File.Copy(source.ItemPath, destinationItemPath, true); System.IO.File.Copy(source.ItemPath, destItemItemPath, true);
wic.Undo(); wic.Undo();
} }
catch catch
...@@ -365,8 +365,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -365,8 +365,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
throw new WebDavUnauthorizedException(); throw new WebDavUnauthorizedException();
} }
DiskStoreDocument document = new DiskStoreDocument(this, destinationItemPath); DiskStoreDocument document = new DiskStoreDocument(this, destItemItemPath);
_items.Add(destinationName, new WeakReference(document)); _items.Add(destName, new WeakReference(document));
return document; return document;
} }
...@@ -392,7 +392,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -392,7 +392,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
+ sourceDirName); + sourceDirName);
} }
// If the destination directory doesn't exist, create it. // If the destItem directory doesn't exist, create it.
if (!Directory.Exists(destDirName)) if (!Directory.Exists(destDirName))
{ {
Directory.CreateDirectory(destDirName); Directory.CreateDirectory(destDirName);
...@@ -413,7 +413,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -413,7 +413,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
/// Moves an existing store item into this collection, overwriting any existing items. /// Moves an existing store item into this collection, overwriting any existing items.
/// </summary> /// </summary>
/// <param name="source">The store item to move.</param> /// <param name="source">The store item to move.</param>
/// <param name="destinationName">The /// <param name="destName">The
/// <see cref="IWebDavStoreItem" /> that refers to the item that was moved, /// <see cref="IWebDavStoreItem" /> that refers to the item that was moved,
/// in its new location.</param> /// in its new location.</param>
/// <returns> /// <returns>
...@@ -425,7 +425,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -425,7 +425,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
/// Note that the method should fail without creating or overwriting content in the /// Note that the method should fail without creating or overwriting content in the
/// target collection if the move cannot go through. /// target collection if the move cannot go through.
/// </remarks> /// </remarks>
public IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destinationName) public IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destName)
{ {
string sourceItemPath = ""; string sourceItemPath = "";
...@@ -438,7 +438,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -438,7 +438,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
} }
string destinationItemPath = Path.Combine(ItemPath, destinationName); string destItemItemPath = Path.Combine(ItemPath, destName);
if (source.IsCollection) if (source.IsCollection)
...@@ -447,7 +447,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -447,7 +447,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
{ {
WindowsImpersonationContext wic = Identity.Impersonate(); WindowsImpersonationContext wic = Identity.Impersonate();
Directory.Move(sourceItemPath, destinationItemPath); Directory.Move(sourceItemPath, destItemItemPath);
wic.Undo(); wic.Undo();
} }
catch catch
...@@ -456,8 +456,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -456,8 +456,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
} }
var collection = new DiskStoreCollection(this, destinationItemPath); var collection = new DiskStoreCollection(this, destItemItemPath);
_items.Add(destinationName, new WeakReference(collection)); _items.Add(destName, new WeakReference(collection));
return collection; return collection;
} }
...@@ -465,7 +465,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -465,7 +465,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
{ {
WindowsImpersonationContext wic = Identity.Impersonate(); WindowsImpersonationContext wic = Identity.Impersonate();
System.IO.File.Move(sourceItemPath, destinationItemPath); System.IO.File.Move(sourceItemPath, destItemItemPath);
wic.Undo(); wic.Undo();
} }
catch catch
...@@ -474,8 +474,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -474,8 +474,8 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
} }
DiskStoreDocument document = new DiskStoreDocument(this, destinationItemPath); DiskStoreDocument document = new DiskStoreDocument(this, destItemItemPath);
_items.Add(destinationName, new WeakReference(document)); _items.Add(destName, new WeakReference(document));
return document; return document;
} }
......
...@@ -3,7 +3,7 @@ using System.Diagnostics; ...@@ -3,7 +3,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Security.Principal; using System.Security.Principal;
using Mozi.HttpEmbedded.Source; using Mozi.HttpEmbedded.Source;
using Mozi.HttpEmbedded.WebDav.Exception; using Mozi.HttpEmbedded.WebDav.Exceptions;
using Mozi.HttpEmbedded.WebDav.Utilities; using Mozi.HttpEmbedded.WebDav.Utilities;
namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
...@@ -59,7 +59,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore ...@@ -59,7 +59,7 @@ namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
{ {
get get
{ {
return Md5Util.Md5HashStringForUtf8String(ItemPath + ModificationDate + Hidden + Size); return Md5Util.Md5Hash4Utf8String(ItemPath + ModificationDate + Hidden + Size);
} }
} }
......
...@@ -2,7 +2,7 @@ using System; ...@@ -2,7 +2,7 @@ using System;
using System.IO; using System.IO;
using System.Security.Principal; using System.Security.Principal;
using System.Threading; using System.Threading;
using Mozi.HttpEmbedded.WebDav.Storage.BaseClasses; using Mozi.HttpEmbedded.WebDav.Storage.Base;
namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore namespace Mozi.HttpEmbedded.WebDav.Storage.DiskStore
{ {
......
...@@ -58,18 +58,18 @@ namespace Mozi.HttpEmbedded.WebDav.Storage ...@@ -58,18 +58,18 @@ namespace Mozi.HttpEmbedded.WebDav.Storage
/// Copies an existing store item into this collection, overwriting any existing items. /// Copies an existing store item into this collection, overwriting any existing items.
/// </summary> /// </summary>
/// <param name="source">The store item to copy from.</param> /// <param name="source">The store item to copy from.</param>
/// <param name="destinationName">The name of the copy to create of <paramref name="source" />.</param> /// <param name="destName">The name of the copy to create of <paramref name="source" />.</param>
/// <param name="includeContent">The boolean for copying the containing files/folders or not.</param> /// <param name="includeContent">The boolean for copying the containing files/folders or not.</param>
/// <returns> /// <returns>
/// The created <see cref="IWebDavStoreItem" /> instance. /// The created <see cref="IWebDavStoreItem" /> instance.
/// </returns> /// </returns>
IWebDavStoreItem CopyItemHere(IWebDavStoreItem source, string destinationName, bool includeContent); IWebDavStoreItem CopyItemHere(IWebDavStoreItem source, string destName, bool includeContent);
/// <summary> /// <summary>
/// Moves an existing store item into this collection, overwriting any existing items. /// Moves an existing store item into this collection, overwriting any existing items.
/// </summary> /// </summary>
/// <param name="source">The store item to move.</param> /// <param name="source">The store item to move.</param>
/// <param name="destinationName">The /// <param name="destName">The
/// <see cref="IWebDavStoreItem" /> that refers to the item that was moved, /// <see cref="IWebDavStoreItem" /> that refers to the item that was moved,
/// in its new location.</param> /// in its new location.</param>
/// <returns> /// <returns>
...@@ -79,6 +79,6 @@ namespace Mozi.HttpEmbedded.WebDav.Storage ...@@ -79,6 +79,6 @@ namespace Mozi.HttpEmbedded.WebDav.Storage
/// Note that the method should fail without creating or overwriting content in the /// Note that the method should fail without creating or overwriting content in the
/// target collection if the move cannot go through. /// target collection if the move cannot go through.
/// </remarks> /// </remarks>
IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destinationName); IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destName);
} }
} }
\ No newline at end of file
...@@ -5,15 +5,9 @@ using Mozi.HttpEmbedded.Encode; ...@@ -5,15 +5,9 @@ using Mozi.HttpEmbedded.Encode;
namespace Mozi.HttpEmbedded.WebDav.Utilities namespace Mozi.HttpEmbedded.WebDav.Utilities
{ {
/// <summary>
/// For generating an MD5 hash
/// </summary>
/// <remarks>
/// Source: <see href="https://gist.github.com/kristopherjohnson/3021045" />
/// </remarks>
internal static class Md5Util internal static class Md5Util
{ {
public static string Md5HashStringForUtf8String(string s) public static string Md5Hash4Utf8String(string s)
{ {
byte[] bytes =StringEncoder.Encode(s); byte[] bytes =StringEncoder.Encode(s);
...@@ -22,14 +16,6 @@ namespace Mozi.HttpEmbedded.WebDav.Utilities ...@@ -22,14 +16,6 @@ namespace Mozi.HttpEmbedded.WebDav.Utilities
return HexStringFromBytes(hashBytes); return HexStringFromBytes(hashBytes);
} }
/// <summary>
/// Convert an array of bytes to a string of hex digits
/// </summary>
/// <param name="bytes">Array of bytes</param>
/// <returns>
/// String of hex digits
/// </returns>
public static string HexStringFromBytes(byte[] bytes) public static string HexStringFromBytes(byte[] bytes)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册