WebDavProcessor.cs :  » Network-Servers » WebDAV.NET-Server » Sphorium » WebDAV » Server » Framework » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Servers » WebDAV.NET Server 
WebDAV.NET Server » Sphorium » WebDAV » Server » Framework » WebDavProcessor.cs
using System;
using System.Web;
using System.Xml;
using System.Text;
using System.Reflection;
using System.Globalization;
using System.Collections.Generic;

using Sphorium.WebDAV.Server.Framework.Interfaces;
using Sphorium.WebDAV.Server.Framework.BaseClasses;

namespace Sphorium.WebDAV.Server.Framework{
  /// <summary>
  /// Summary description for WebDavProcessor.
  /// </summary>
  internal class WebDavProcessor
  {
    private static string __debugFilePath = null;
    private readonly Assembly __davSourceAssembly;

    /// <summary>
    /// Keeps track of all the inherited DavOptionsBase members
    /// </summary>
    private readonly SortedList<string, string> __davMethodList = new SortedList<string, string>(StringComparer.InvariantCultureIgnoreCase);

    /// <summary>
    /// Request / Response Debug File Path
    /// </summary>
    public static string DebugFilePath
    {
      get
      {
        return __debugFilePath;
      }
      set
      {
        __debugFilePath = value;
      }
    }

    /// <summary>
    /// WebDav Framework entry point for Dav request processing
    /// </summary>
    public WebDavProcessor() : this(Assembly.GetCallingAssembly()) { }

    /// <summary>
    /// WebDav Framework entry point for Dav request processing
    /// </summary>
    /// <param name="davSourceAssembly">Assembly containing custom DAV Method implementation </param>
    public WebDavProcessor(Assembly davSourceAssembly)
    {
      this.__davSourceAssembly = davSourceAssembly;

      //Use reflection to identify the map the Map the current 
      foreach (Type _objectType in this.DavSourceAssembly.GetTypes())
      {
        string _davMethod = null;

        if (_objectType.BaseType == typeof(DavOptionsBase))
          _davMethod = "OPTIONS";
        else if (_objectType.BaseType == typeof(DavMKColBase))
          _davMethod = "MKCOL";
        else if (_objectType.BaseType == typeof(DavPropFindBase))
          _davMethod = "PROPFIND";
        else if (_objectType.BaseType == typeof(DavHeadBase))
          _davMethod = "HEAD";
        else if (_objectType.BaseType == typeof(DavDeleteBase))
          _davMethod = "DELETE";
        else if (_objectType.BaseType == typeof(DavMoveBase))
          _davMethod = "MOVE";
        else if (_objectType.BaseType == typeof(DavCopyBase))
          _davMethod = "COPY";
        else if (_objectType.BaseType == typeof(DavPutBase))
          _davMethod = "PUT";
        else if (_objectType.BaseType == typeof(DavGetBase))
          _davMethod = "GET";
        else if (_objectType.BaseType == typeof(DavLockBase))
          _davMethod = "LOCK";
        else if (_objectType.BaseType == typeof(DavUnlockBase))
          _davMethod = "UNLOCK";
        else if (_objectType.BaseType == typeof(DavPropPatchBase))
          _davMethod = "PROPPATCH";
        else if (_objectType.BaseType == typeof(DavVersionControlBase))
          _davMethod = "VERSION-CONTROL";
        else if (_objectType.BaseType == typeof(DavReportBase))
          _davMethod = "REPORT";

        if (_davMethod != null)
        {
          if (this.__davMethodList.ContainsKey(_davMethod))
            throw new WebDavException("Duplicate objects for " + _davMethod + " found. There should only up to 1 object implementing each of the base DavMethod classes.");

          this.__davMethodList[_davMethod] = _objectType.ToString();
        }
      }
    }

    /// <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();
      }
    }

    #region Private Properties
      /// <summary>
      /// Dav Source Assembly
      /// </summary>
      private Assembly DavSourceAssembly
      {
        get
        {
          return this.__davSourceAssembly;
        }
      }
    #endregion
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.