/// <summary>
        /// Initializes a new instance of the <see cref="WebDavServer" /> class.
        /// </summary>
        /// <param name="store">The 
        /// <see cref="IWebDavStore" /> store object that will provide
        /// collections and documents for this 
        /// <see cref="WebDavServer" />.</param>
        /// <param name="listener">The 
        /// <see cref="IHttpListener" /> object that will handle the web server portion of
        /// the WebDAV server; or 
        /// <c>null</c> to use a fresh one.</param>
        /// <param name="methodHandlers">A collection of HTTP method handlers to use by this 
        /// <see cref="WebDavServer" />;
        /// or 
        /// <c>null</c> to use the built-in method handlers.</param>
        /// <exception cref="System.ArgumentNullException"><para>
        ///   <paramref name="listener" /> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para>
        ///   <paramref name="store" /> is <c>null</c>.</para></exception>
        /// <exception cref="System.ArgumentException"><para>
        ///   <paramref name="methodHandlers" /> is empty.</para>
        /// <para>- or -</para>
        /// <para>
        ///   <paramref name="methodHandlers" /> contains a <c>null</c>-reference.</para></exception>
        public WebDavServer(IWebDavStore store, IHttpListener listener = null, IEnumerable<IWebDavMethodHandler> methodHandlers = null)
        {
            if (store == null)
                throw new ArgumentNullException("store");
            if (listener == null)
            {
                listener = new HttpListenerAdapter();
                _ownsListener = true;
            }
            methodHandlers = methodHandlers ?? WebDavMethodHandlers.BuiltIn;

            IWebDavMethodHandler[] webDavMethodHandlers = methodHandlers as IWebDavMethodHandler[] ?? methodHandlers.ToArray();

            if (!webDavMethodHandlers.Any())
                throw new ArgumentException("The methodHandlers collection is empty", "methodHandlers");
            if (webDavMethodHandlers.Any(methodHandler => methodHandler == null))
                throw new ArgumentException("The methodHandlers collection contains a null-reference", "methodHandlers");

            _listener = listener;
            _store = store;
            var handlersWithNames =
                from methodHandler in webDavMethodHandlers
                from name in methodHandler.Names
                select new
                {
                    name,
                    methodHandler
                };
            _methodHandlers = handlersWithNames.ToDictionary(v => v.name, v => v.methodHandler);
            _log = LogManager.GetCurrentClassLogger();
            }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDAVServer"/> class.
        /// </summary>
        /// <param name="store">
        /// The <see cref="IWebDAVStore"/> store object that will provide
        /// collections and documents for this <see cref="WebDAVServer"/>.
        /// </param>
        /// <param name="logger">
        /// The <see cref="ILogger"/> object that log messages will be sent to;
        /// or <c>null</c> to not use a logger.
        /// </param>
        /// <param name="listener">
        /// The <see cref="IHttpListener"/> object that will handle the web server portion of
        /// the WebDAV server; or <c>null</c> to use a fresh one.
        /// </param>
        /// <param name="methodHandlers">
        /// A collection of HTTP method handlers to use by this <see cref="WebDAVServer"/>;
        /// or <c>null</c> to use the built-in method handlers.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="listener"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="store"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <para><paramref name="methodHandlers"/> is empty.</para>
        /// <para>- or -</para>
        /// <para><paramref name="methodHandlers"/> contains a <c>null</c>-reference.</para>
        /// </exception>
        public WebDAVServer(IWebDAVStore store, ILogger logger = null, IHttpListener listener = null, IEnumerable <IWebDAVMethodHandler> methodHandlers = null)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            if (listener == null)
            {
                listener      = new HttpListenerAdapter();
                _OwnsListener = true;
            }
            methodHandlers = methodHandlers ?? WebDAVMethodHandlers.BuiltIn;
            if (!methodHandlers.Any())
            {
                throw new ArgumentException("The methodHandlers collection is empty", "methodHandlers");
            }
            if (methodHandlers.Any(methodHandler => methodHandler == null))
            {
                throw new ArgumentException("The methodHandlers collection contains a null-reference", "methodHandlers");
            }

            _Listener = listener;
            _Store    = store;
            var handlersWithNames =
                from methodHandler in methodHandlers
                from name in methodHandler.Names
                select new { name, methodHandler };

            _MethodHandlers = handlersWithNames.ToDictionary(v => v.name, v => v.methodHandler);
            _Logger         = logger ?? new VoidLogger();
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDavServer" /> class.
        /// </summary>
        /// <param name="store">The
        /// <see cref="IWebDavStore" /> store object that will provide
        /// collections and documents for this
        /// <see cref="WebDavServer" />.</param>
        /// <param name="listener">The
        /// <see cref="IHttpListener" /> object that will handle the web server portion of
        /// the WebDAV server; or
        /// <c>null</c> to use a fresh one.</param>
        /// <param name="methodHandlers">A collection of HTTP method handlers to use by this
        /// <see cref="WebDavServer" />;
        /// or
        /// <c>null</c> to use the built-in method handlers.</param>
        /// <exception cref="System.ArgumentNullException"><para>
        ///   <paramref name="listener" /> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para>
        ///   <paramref name="store" /> is <c>null</c>.</para></exception>
        /// <exception cref="System.ArgumentException"><para>
        ///   <paramref name="methodHandlers" /> is empty.</para>
        /// <para>- or -</para>
        /// <para>
        ///   <paramref name="methodHandlers" /> contains a <c>null</c>-reference.</para></exception>
        public WebDavServer(IWebDavStore store, IHttpListener listener = null, IEnumerable <IWebDavMethodHandler> methodHandlers = null)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            if (listener == null)
            {
                listener      = new HttpListenerAdapter();
                _ownsListener = true;
            }
            methodHandlers = methodHandlers ?? WebDavMethodHandlers.BuiltIn;

            var webDavMethodHandlers = methodHandlers as IWebDavMethodHandler[] ?? methodHandlers.ToArray();

            if (!webDavMethodHandlers.Any())
            {
                throw new ArgumentException("The methodHandlers collection is empty", "methodHandlers");
            }
            if (webDavMethodHandlers.Any(methodHandler => methodHandler == null))
            {
                throw new ArgumentException("The methodHandlers collection contains a null-reference", "methodHandlers");
            }

            _listener = listener;
            _store    = store;
            var handlersWithNames =
                from methodHandler in webDavMethodHandlers
                from name in methodHandler.Names
                select new
            {
                name,
                methodHandler
            };

            _methodHandlers = handlersWithNames.ToDictionary(v => v.name, v => v.methodHandler);
            //_log = LogManager.GetCurrentClassLogger();
            _log = LogManager.GetLogger(GetType().Name);
        }