Beispiel #1
0
        /// <summary>
        /// Internal function for obtaining a URIPath's relative path (Removes the NonPathPart)
        /// </summary>
        /// <param name="httpApplication"></param>
        /// <param name="URIPath"></param>
        /// <returns></returns>
        internal static string GetRelativePath(HttpApplication httpApplication, string URIPath)
        {
            if (httpApplication == null)
            {
                throw new ArgumentNullException("HttpApplication", InternalFunctions.GetResourceString("ArgumentNullException", "HttpApplication"));
            }

            string _nonPathPart = GetNonPathPart(httpApplication);

            string _retValue;

            if (URIPath.ToLower().StartsWith(_nonPathPart.ToLower()))
            {
                _retValue = URIPath.Remove(0, _nonPathPart.Length);
            }
            else
            {
                _retValue = URIPath;
            }

            //Remove the application path
            string _appPath = httpApplication.Request.ApplicationPath;

            if (_retValue.ToLower().StartsWith(_appPath.ToLower()))
            {
                _retValue = _retValue.Remove(0, _appPath.Length);
            }

            return(HttpUtility.UrlDecode(_retValue.Trim('/')));
        }
Beispiel #2
0
        /// <summary>
        /// Retrieve the HTTP response status
        /// </summary>
        /// <param name="statusCode"></param>
        /// <returns></returns>
        internal static string GetEnumHttpResponse(Enum statusCode)
        {
            string _httpResponse = "";

            switch (InternalFunctions.GetEnumValue(statusCode))
            {
            case 200:
                _httpResponse = "HTTP/1.1 200 OK";
                break;

            case 404:
                _httpResponse = "HTTP/1.1 404 Not Found";
                break;

            case 423:
                _httpResponse = "HTTP/1.1 423 Locked";
                break;

            case 424:
                _httpResponse = "HTTP/1.1 424 Failed Dependency";
                break;

            case 507:
                _httpResponse = "HTTP/1.1 507 Insufficient Storage";
                break;

            default:
                throw new WebDavException(InternalFunctions.GetResourceString("InvalidStatusCode"));
            }

            return(_httpResponse);
        }
Beispiel #3
0
 /// <summary>
 /// Iternal function to write debug file
 /// </summary>
 /// <param name="message"></param>
 internal static void WriteDebugLog(string message)
 {
     Trace.WriteLine(message);
     if (!string.IsNullOrEmpty(WebDavProcessor.DebugFilePath))
     {
         InternalFunctions.AppendFile(WebDavProcessor.DebugFilePath, message);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Internal function to validate the enumerator is of type Int32
        /// </summary>
        /// <param name="enumToValidate"></param>
        /// <exception cref="WebDavException">Throw exception if the enumToValidate value is not a valid Int32</exception>
        internal static bool ValidateEnumType(Enum enumToValidate)
        {
            if (enumToValidate.GetTypeCode() != TypeCode.Int32)
            {
                throw new WebDavException(InternalFunctions.GetResourceString("InvalidEnumIntType"));
            }

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Internal function for retrieving the NonPathPart since it is not available via the framework (internal property)
        /// </summary>
        /// <param name="httpApplication"></param>
        /// <returns></returns>
        internal static string GetNonPathPart(HttpApplication httpApplication)
        {
            if (httpApplication == null)
            {
                throw new ArgumentNullException("HttpApplication", InternalFunctions.GetResourceString("ArgumentNullException", "HttpApplication"));
            }

            string _completePath = httpApplication.Request.Url.AbsoluteUri;
            string _relativePath = httpApplication.Request.Url.AbsolutePath;

            return(_completePath.Substring(0, _completePath.Length - _relativePath.Length));
        }
Beispiel #6
0
        /// <summary>
        /// WebDav Framework method for Dav request processing
        /// </summary>
        /// <param name="httpApplication"></param>
        /// <remarks>
        ///		Process all requests... will return 501 if the requested method is not implemented
        /// </remarks>
        public void ProcessRequest(HttpApplication httpApplication)
        {
            if (httpApplication == null)
            {
                throw new ArgumentNullException("httpApplication", InternalFunctions.GetResourceString("ArgumentNullException", "HttpApplication"));
            }

            //Set the status code to Method Not Allowed by default
            int _statusCode = 405;

            string _httpMethod = httpApplication.Request.HttpMethod;

            InternalFunctions.WriteDebugLog("Processing HttpMethod " + _httpMethod);
            //try
            {
                if (this.__davMethodList.ContainsKey(_httpMethod))
                {
                    httpApplication.Response.Clear();
                    httpApplication.Response.ClearContent();

                    DavMethodBase _davMethodBase = this.DavSourceAssembly.CreateInstance(this.__davMethodList[_httpMethod]) as DavMethodBase;
                    if (_davMethodBase != null)
                    {
                        _davMethodBase.HttpApplication = httpApplication;
                        _statusCode = ((IDavRequest)_davMethodBase).ProcessRequest();
                    }
                }
            }
            //catch (Exception ex)
            //{
            //    InternalFunctions.WriteDebugLog("Error processing HttpMethod " + _httpMethod +
            //        Environment.NewLine + "Message: " + ex.Message);
            //}

            InternalFunctions.WriteDebugLog("Completed processing HttpMethod " + _httpMethod + " status code returned: " + _statusCode);

            if (this.__davMethodList.ContainsKey(_httpMethod))
            {
                httpApplication.Response.StatusCode = _statusCode;


                ////TODO: remove this
                //System.Threading.Thread.Sleep(10000);

                //Perhaps implement...
                //httpApplication.Request.InputStream.Close();
                httpApplication.Response.End();
            }
        }
Beispiel #7
0
        /// <summary>
        /// WebDav Framework method for Dav request processing
        /// </summary>
        /// <param name="httpApplication"></param>
        /// <remarks>
        ///		Process all requests... will return 501 if the requested method is not implemented
        /// </remarks>
        public void ProcessRequest(HttpApplication httpApplication)
        {
            if (httpApplication == null)
            {
                throw new ArgumentNullException("httpApplication", InternalFunctions.GetResourceString("ArgumentNullException", "HttpApplication"));
            }

            var verb = GeneralHelper.GetVerb(httpApplication.Request.HttpMethod);

            var e = XdavEvents.Current.XdavOnProcessingHandler(new XdavOnProcessingEventArg()
            {
                Context  = httpApplication,
                HttpVerp = verb,
                File     = FileWrapper.Current.File
            });

            if (!e.AllowContinue)
            {
                return;
            }


            //Set the status code to Method Not Allowed by default
            int _statusCode = 405;

            string _httpMethod = httpApplication.Request.HttpMethod;

            InternalFunctions.WriteDebugLog("Processing HttpMethod " + _httpMethod);
            try
            {
                if (this.__davMethodList.ContainsKey(_httpMethod))
                {
                    httpApplication.Response.Clear();
                    httpApplication.Response.ClearContent();

                    DavMethodBase _davMethodBase = this.DavSourceAssembly.CreateInstance(this.__davMethodList[_httpMethod]) as DavMethodBase;
                    if (_davMethodBase != null)
                    {
                        _davMethodBase.HttpApplication = httpApplication;
                        _statusCode = ((IDavRequest)_davMethodBase).ProcessRequest();
                    }
                }
            }
            catch (Exception ex)
            {
                XdavEvents.Current.XdavOnExceptionHandler(new XdavOnExceptionEventArg()
                {
                    Exception = ex,
                    Context   = httpApplication,
                    HttpVerp  = verb,
                    File      = FileWrapper.Current.File
                });
            }

            InternalFunctions.WriteDebugLog("Completed processing HttpMethod " + _httpMethod + " status code returned: " + _statusCode);

            if (this.__davMethodList.ContainsKey(_httpMethod))
            {
                httpApplication.Response.StatusCode = _statusCode;


                ////TODO: remove this
                //System.Threading.Thread.Sleep(10000);

                //Perhaps implement...
                //httpApplication.Request.InputStream.Close();
                httpApplication.Response.End();
            }

            XdavEvents.Current.XdavOnProcessedHandler(new XdavOnProcessedEventArg()
            {
                Context    = httpApplication,
                HttpVerp   = verb,
                StatusCode = _statusCode,
                File       = FileWrapper.Current.File
            });
        }