/// <summary> /// Starts the WebDAV server. /// </summary> /// <returns>The <see cref="WebDavServer"/></returns> internal static WebDavServer StartWebDavServer() { var server = new WebDavServer(new WebDavDiskStore(WebDavConfig.WebDavLocalPath)); server.Start(WebDavConfig.WebDavUri.ToString()); return server; }
/// <summary> /// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param> /// <param name="server"> /// The /// <see cref="WebDavServer" /> that hosts the WebDAV server and holds the collection /// of known prefixes. /// </param> /// <returns> /// The most specific <see cref="Uri" /> for the given <paramref name="uri" />. /// </returns> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception> /// <exception cref="WebDavInternalServerException"> /// <paramref name="uri" /> specifies a <see cref="Uri" /> that is not /// known to the <paramref name="server" />. /// </exception> public static Uri GetPrefixUri(this Uri uri, WebDavServer server) { string url = uri.ToString(); string exactPrefix = server.Listener.Prefixes .FirstOrDefault(item => url.StartsWith(item, StringComparison.OrdinalIgnoreCase)); if (!IsNullOrEmpty(exactPrefix)) { return new Uri(exactPrefix); } string wildcardUrl = new UriBuilder(uri) { Host = "WebDAVSharpSpecialHostTag" } .ToString().Replace("WebDAVSharpSpecialHostTag", "*"); string wildcardPrefix = server.Listener.Prefixes .FirstOrDefault(item => wildcardUrl.StartsWith(item, StringComparison.OrdinalIgnoreCase)); if (!IsNullOrEmpty(wildcardPrefix)) { return new Uri(wildcardPrefix.Replace("://*", $"://{uri.Host}")); } throw new WebDavInternalServerException("Unable to find correct server root"); }
/// <summary> /// Retrieves a store item through the specified /// <see cref="Uri" /> from the /// specified /// <see cref="WebDavServer" /> and /// <see cref="IWebDavStore" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to retrieve the store item for.</param> /// <param name="server">The <see cref="WebDavServer" /> that hosts the <paramref name="store" />.</param> /// <param name="store">The <see cref="IWebDavStore" /> from which to retrieve the store item.</param> /// <returns> /// The retrieved store item. /// </returns> /// <exception cref="System.ArgumentNullException"><para> /// <paramref name="uri" /> is <c>null</c>.</para> /// <para> /// <paramref name="server" /> is <c>null</c>.</para> /// <para> /// <paramref name="store" /> is <c>null</c>.</para></exception> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If the item was not found.</exception> /// <exception cref="WebDavConflictException"><paramref name="uri" /> refers to a document in a collection, where the collection does not exist.</exception> /// <exception cref="WebDavNotFoundException"><paramref name="uri" /> refers to a document that does not exist.</exception> public static IWebDavStoreItem GetItem( this Uri uri, WebDavServer server, IWebDavStore store) { if (uri == null) { throw new ArgumentNullException("uri"); } if (server == null) { throw new ArgumentNullException("server"); } if (store == null) { throw new ArgumentNullException("store"); } Uri prefixUri = uri.GetPrefixUri(server); IWebDavStoreCollection collection = store.Root; IWebDavStoreItem item = null; if (prefixUri.Segments.Length == uri.Segments.Length) { return(collection); } string[] segments = SplitUri(uri, prefixUri); for (int index = 0; index < segments.Length; index++) { string segmentName = Uri.UnescapeDataString(segments[index]); IWebDavStoreItem nextItem = collection.GetItemByName(segmentName); if (nextItem == null) { throw new WebDavNotFoundException(String.Format("Cannot find item {0} from collection {1}", segmentName, collection.ItemPath)); //throw new WebDavConflictException(); } if (index == segments.Length - 1) { item = nextItem; } else { collection = nextItem as IWebDavStoreCollection; if (collection == null) { throw new WebDavNotFoundException(String.Format("NextItem [{0}] is not a collection", nextItem.ItemPath)); } } } if (item == null) { throw new WebDavNotFoundException(String.Format("Unable to find {0}", uri)); } return(item); }
/// <summary> /// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param> /// <param name="server">The /// <see cref="WebDavServer" /> that hosts the WebDAV server and holds the collection /// of known prefixes.</param> /// <returns> /// The most specific <see cref="Uri" /> for the given <paramref name="uri" />. /// </returns> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception> /// <exception cref="WebDavInternalServerException"><paramref name="uri" /> specifies a <see cref="Uri" /> that is not known to the <paramref name="server" />.</exception> public static Uri GetPrefixUri(this Uri uri, WebDavServer server) { string url = uri.ToString(); foreach ( string prefix in server.Listener.Prefixes.Where( prefix => url.StartsWith(uri.ToString(), StringComparison.OrdinalIgnoreCase))) return new Uri(prefix); throw new WebDavInternalServerException("Unable to find correct server root"); }
/// <summary> /// Retrieves a store item through the specified /// <see cref="Uri" /> from the /// specified /// <see cref="WebDavServer" /> and /// <see cref="IWebDavStore" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to retrieve the store item for.</param> /// <param name="server">The <see cref="WebDavServer" /> that hosts the <paramref name="store" />.</param> /// <param name="store">The <see cref="IWebDavStore" /> from which to retrieve the store item.</param> /// <returns> /// The retrieved store item. /// </returns> /// <exception cref="System.ArgumentNullException"><para> /// <paramref name="uri" /> is <c>null</c>.</para> /// <para> /// <paramref name="server" /> is <c>null</c>.</para> /// <para> /// <paramref name="store" /> is <c>null</c>.</para></exception> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If the item was not found.</exception> /// <exception cref="WebDavConflictException"><paramref name="uri" /> refers to a document in a collection, where the collection does not exist.</exception> /// <exception cref="WebDavNotFoundException"><paramref name="uri" /> refers to a document that does not exist.</exception> public static IWebDavStoreItem GetItem(this Uri uri, WebDavServer server, IWebDavStore store) { if (uri == null) { throw new ArgumentNullException("uri"); } if (server == null) { throw new ArgumentNullException("server"); } if (store == null) { throw new ArgumentNullException("store"); } Uri prefixUri = uri.GetPrefixUri(server); var collection = store.Root; IWebDavStoreItem item = null; if (prefixUri.Segments.Length == uri.Segments.Length) { return(collection); } for (var index = prefixUri.Segments.Length; index < uri.Segments.Length; index++) { var segmentName = Uri.UnescapeDataString(uri.Segments[index]); var nextItem = collection.GetItemByName(segmentName.TrimEnd('/', '\\')); if (nextItem == null) { throw new WebDavNotFoundException(); //throw new WebDavConflictException(); } if (index == uri.Segments.Length - 1) { item = nextItem; } else { collection = nextItem as IWebDavStoreCollection; if (collection == null) { throw new WebDavNotFoundException(); } } } if (item == null) { throw new WebDavNotFoundException(); } return(item); }
/// <summary> /// This method is called when the service gets a request to start. /// </summary> /// <param name="args">Any command line arguments</param> public void OnStart(string[] args) { #if DEBUG NameValueCollection properties = new NameValueCollection {["showDateTime"] = "true"}; LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(properties); #endif IWebDavStoreItemLock lockSystem = new WebDavSqlStoreItemLock(); IWebDavStore store = new WebDavSqlStore("\\Data", new Guid("00000000-0000-0000-0000-000000000000"), lockSystem); WebDavServer server = new WebDavServer(ref store, AuthType.Negotiate); server.Start(Url); }
/// <summary> /// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param> /// <param name="server">The /// <see cref="WebDavServer" /> that hosts the WebDAV server and holds the collection /// of known prefixes.</param> /// <returns> /// The most specific <see cref="Uri" /> for the given <paramref name="uri" />. /// </returns> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception> /// <exception cref="WebDavInternalServerException"><paramref name="uri" /> specifies a <see cref="Uri" /> that is not known to the <paramref name="server" />.</exception> public static Uri GetPrefixUri(this Uri uri, WebDavServer server) { var url = uri.ToString(); foreach ( var prefix in server.Listener.Prefixes.Where( prefix => url.StartsWith(uri.ToString(), StringComparison.OrdinalIgnoreCase))) { return(new Uri(prefix)); } throw new WebDavInternalServerException("Unable to find correct server root"); }
private static Uri GetPrefixWithWildCard(Uri uri, WebDavServer server) { foreach (var wc in AllIpWildChards) { string wildcardUrl = new UriBuilder(uri) { Host = "WebDAVSharpSpecialHostTag" } .ToString().Replace("WebDAVSharpSpecialHostTag", wc); string wildcardPrefix = server.Listener.Prefixes .FirstOrDefault(item => wildcardUrl.StartsWith(item, StringComparison.OrdinalIgnoreCase)); if (!String.IsNullOrEmpty(wildcardPrefix)) { return(new Uri(wildcardPrefix.Replace("://" + wc, string.Format("://{0}", uri.Host)))); } } return(null); }
/// <summary> /// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param> /// <param name="server">The /// <see cref="WebDavServer" /> that hosts the WebDAV server and holds the collection /// of known prefixes.</param> /// <returns> /// The most specific <see cref="Uri" /> for the given <paramref name="uri" />. /// </returns> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception> /// <exception cref="WebDavInternalServerException"><paramref name="uri" /> specifies a <see cref="Uri" /> that is not known to the <paramref name="server" />.</exception> public static Uri GetPrefixUri(this Uri uri, WebDavServer server) { string url = uri.ToString(); string exactPrefix = server.Listener.Prefixes .FirstOrDefault(item => url.StartsWith(item, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(exactPrefix)) { return(new Uri(exactPrefix)); } Uri wildcardPrefix = GetPrefixWithWildCard(uri, server); if (wildcardPrefix != null) { return(wildcardPrefix); } throw new WebDavInternalServerException("Unable to find correct server root"); }
/// <summary> /// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param> /// <param name="server">The /// <see cref="WebDavServer" /> that hosts the WebDAV server and holds the collection /// of known prefixes.</param> /// <returns> /// The most specific <see cref="Uri" /> for the given <paramref name="uri" />. /// </returns> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception> /// <exception cref="WebDavInternalServerException"><paramref name="uri" /> specifies a <see cref="Uri" /> that is not known to the <paramref name="server" />.</exception> public static Uri GetPrefixUri(this Uri uri, WebDavServer server) { string url = uri.ToString(); string exactPrefix = server.Listener.Prefixes .FirstOrDefault(item => url.StartsWith(item, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(exactPrefix)) { return new Uri(exactPrefix); } Uri wildcardPrefix = GetPrefixWithWildCard(uri, server); if (wildcardPrefix != null) { return wildcardPrefix; } throw new WebDavInternalServerException("Unable to find correct server root"); }
/// <summary> /// Retrieves a store item through the specified /// <see cref="Uri" /> from the /// specified /// <see cref="WebDavServer" /> and /// <see cref="IWebDavStore" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to retrieve the store item for.</param> /// <param name="server">The <see cref="WebDavServer" /> that hosts the <paramref name="store" />.</param> /// <param name="store">The <see cref="IWebDavStore" /> from which to retrieve the store item.</param> /// <returns> /// The retrieved store item. /// </returns> /// <exception cref="System.ArgumentNullException"> /// <para> /// <paramref name="uri" /> is <c>null</c>. /// </para> /// <para> /// <paramref name="server" /> is <c>null</c>. /// </para> /// <para> /// <paramref name="store" /> is <c>null</c>. /// </para> /// </exception> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If the item was not found.</exception> /// <exception cref="WebDavConflictException"> /// <paramref name="uri" /> refers to a document in a collection, where the /// collection does not exist. /// </exception> /// <exception cref="WebDavNotFoundException"><paramref name="uri" /> refers to a document that does not exist.</exception> public static IWebDavStoreItem GetItem(this Uri uri, WebDavServer server, IWebDavStore store) { if (uri == null) throw new ArgumentNullException(nameof(uri)); if (server == null) throw new ArgumentNullException(nameof(server)); if (store == null) throw new ArgumentNullException(nameof(store)); Uri prefixUri = uri.GetPrefixUri(server); IWebDavStoreCollection collection = store.Root; IWebDavStoreItem item = null; if (prefixUri.Segments.Length == uri.Segments.Length) return collection; for (int index = prefixUri.Segments.Length; index < uri.Segments.Length; index++) { string segmentName = Uri.UnescapeDataString(uri.Segments[index]); IWebDavStoreItem nextItem = collection.GetItemByName(segmentName.TrimEnd('/', '\\')); if (nextItem == null) throw new WebDavNotFoundException(); //throw new WebDavConflictException(); if (index == uri.Segments.Length - 1) item = nextItem; else { collection = nextItem as IWebDavStoreCollection; if (collection == null) throw new WebDavNotFoundException(); } } if (item == null) throw new WebDavNotFoundException(); return item; }
/// <summary> /// Retrieves a store item through the specified /// <see cref="Uri" /> from the /// specified /// <see cref="WebDavServer" /> and /// <see cref="IWebDavStore" />. /// </summary> /// <param name="uri">The <see cref="Uri" /> to retrieve the store item for.</param> /// <param name="server">The <see cref="WebDavServer" /> that hosts the <paramref name="store" />.</param> /// <param name="store">The <see cref="IWebDavStore" /> from which to retrieve the store item.</param> /// <returns> /// The retrieved store item. /// </returns> /// <exception cref="System.ArgumentNullException"><para> /// <paramref name="uri" /> is <c>null</c>.</para> /// <para> /// <paramref name="server" /> is <c>null</c>.</para> /// <para> /// <paramref name="store" /> is <c>null</c>.</para></exception> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If the item was not found.</exception> /// <exception cref="WebDavConflictException"><paramref name="uri" /> refers to a document in a collection, where the collection does not exist.</exception> /// <exception cref="WebDavNotFoundException"><paramref name="uri" /> refers to a document that does not exist.</exception> public static IWebDavStoreItem GetItem( this Uri uri, WebDavServer server, IWebDavStore store) { if (uri == null) throw new ArgumentNullException("uri"); if (server == null) throw new ArgumentNullException("server"); if (store == null) throw new ArgumentNullException("store"); Uri prefixUri = uri.GetPrefixUri(server); IWebDavStoreCollection collection = store.Root; IWebDavStoreItem item = null; if (prefixUri.Segments.Length == uri.Segments.Length) return collection; string[] segments = SplitUri(uri, prefixUri); for (int index = 0; index < segments.Length; index++) { string segmentName = Uri.UnescapeDataString(segments[index]); IWebDavStoreItem nextItem = collection.GetItemByName(segmentName); if (nextItem == null) throw new WebDavNotFoundException(String.Format("Cannot find item {0} from collection {1}", segmentName, collection.ItemPath)); //throw new WebDavConflictException(); if (index == segments.Length - 1) item = nextItem; else { collection = nextItem as IWebDavStoreCollection; if (collection == null) throw new WebDavNotFoundException(String.Format("NextItem [{0}] is not a collection", nextItem.ItemPath)); } } if (item == null) throw new WebDavNotFoundException(String.Format("Unable to find {0}", uri)); return item; }
private static Uri GetPrefixWithWildCard(Uri uri, WebDavServer server) { foreach (var wc in AllIpWildChards) { string wildcardUrl = new UriBuilder(uri) { Host = "WebDAVSharpSpecialHostTag" } .ToString().Replace("WebDAVSharpSpecialHostTag", wc); string wildcardPrefix = server.Listener.Prefixes .FirstOrDefault(item => wildcardUrl.StartsWith(item, StringComparison.OrdinalIgnoreCase)); if (!String.IsNullOrEmpty(wildcardPrefix)) { return new Uri(wildcardPrefix.Replace("://" + wc, string.Format("://{0}", uri.Host))); } } return null; }
/// <summary> /// Starts the server. /// Authentication used: Negotiate /// </summary> private static void StartServer() { IWebDavStoreItemLock lockSystem = new WebDavStoreItemLock(); IWebDavStore store = new WebDavDiskStore(Localpath, lockSystem); WebDavServer server = new WebDavServer(ref store); server.Start(Url); }
public void Initialize() { _server = WebDav.StartWebDavServer(); }