DavOptionsBase.cs :  » Network-Servers » WebDAV.NET-Server » Sphorium » WebDAV » Server » Framework » BaseClasses » 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 » BaseClasses » DavOptionsBase.cs
using System;
using System.Text;

namespace Sphorium.WebDAV.Server.Framework.BaseClasses{
  /// <summary>
  /// Dav Server OPTIONS Framework Base Class
  /// </summary>
  /// <remarks>
  ///    RFC2518 Compliant / RFC3253 Compliant
  ///    
  ///    <code>
  ///    The ProcessDavRequest event must follow the following rules addressed in RFC2518
  ///      http://www.webdav.org/specs/rfc2518.html#dav.compliance.classes
  ///      http://www.webdav.org/specs/rfc3253.html#rfc.section.3.9  
  ///      
  ///    Class 1:
  ///      Class 1 compliant resources MUST return, at minimum, the value "1" in the Dav header 
  ///      on all responses to the OPTIONS method.
  ///    Class 2: 
  ///      Class 2 compliant resources MUST meet all class 1 requirements and support the LOCK 
  ///      method, the supportedlock property, the lockdiscovery property, the Time-Out response 
  ///      header and the Lock-Token request header. A class "2" compliant resource SHOULD also 
  ///      support the Time-Out request header and the owner XML element.
  ///      
  ///      Class 2 compliant resources MUST return, at minimum, the values "1" and "2" in the 
  ///      Dav header on all responses to the OPTIONS method.
  ///    </code>
  ///    
  ///    <code>
  ///      Returns ServerResponseCode.OK when successful
  ///    </code>
  /// </remarks>  

  public abstract class DavOptionsBase : DavMethodBase
  {
    /// <summary>
    /// Dav Server OPTIONS Framework Base Class
    /// </summary>
    protected DavOptionsBase()
    {
      this.InternalProcessDavRequest += new DavInternalProcessHandler(DavOptionsBase_InternalProcessDavRequest);
      this.SupportedHttpMethods = HttpMethods.None;
    }

    /// <summary>
    /// WebDav HttpMethods
    /// </summary>
    [FlagsAttribute]
    protected enum HttpMethods : int
    {
      /// <summary>
      /// No supported methods
      /// </summary>
      None = 0,

      /// <summary>
      /// Supports OPTIONS Method
      /// </summary>
      Options = 1,

      /// <summary>
      /// Supports GET Method
      /// </summary>
      Get = 2,

      /// <summary>
      /// Supports HEAD Method
      /// </summary>
      Head = 4,

      /// <summary>
      /// Supports DELETE Method
      /// </summary>
      Delete = 8,

      /// <summary>
      /// Supports PUT Method
      /// </summary>
      Put = 16,

      /// <summary>
      /// Supports COPY Method
      /// </summary>
      Copy = 32,

      /// <summary>
      /// Supports MOVE Method
      /// </summary>
      Move = 64,

      /// <summary>
      /// Supports MKCOL Method
      /// </summary>
      MKCol = 128,

      /// <summary>
      /// Supports PROPFIND Method
      /// </summary>
      PropFind = 256,

      /// <summary>
      /// Supports PROPPATCH Method
      /// </summary>
      PropPatch = 512,

      /// <summary>
      /// Supports LOCK Method
      /// </summary>
      Lock = 1024,

      /// <summary>
      /// Supports UNLOCK Method
      /// </summary>
      Unlock = 2048,

      /// <summary>
      /// Supports VERSION-CONTROL Method
      /// </summary>
      VersionControl = 4096,

      /// <summary>
      /// Supports REPORT Method
      /// </summary>
      Report = 8192,

      /// <summary>
      /// Supports All Methods
      /// </summary>
      All = HttpMethods.Copy | HttpMethods.Delete | HttpMethods.Get | HttpMethods.Head | HttpMethods.Lock |
        HttpMethods.MKCol | HttpMethods.Move | HttpMethods.Options | HttpMethods.PropFind | HttpMethods.PropPatch | HttpMethods.Put |
        HttpMethods.Report | HttpMethods.Unlock | HttpMethods.VersionControl
    }

    /// <summary>
    /// WebDav Server Supported Http Methods
    /// </summary>
    protected HttpMethods SupportedHttpMethods { get; set; }

    private int DavOptionsBase_InternalProcessDavRequest(object sender, EventArgs e)
    {
      string _davClass = "1";
      if ((SupportedHttpMethods & HttpMethods.Lock) != 0 && (SupportedHttpMethods & HttpMethods.PropFind) != 0)
        _davClass += ", 2";

      StringBuilder _allowedMethods = new StringBuilder();
      foreach (string enumName in Enum.GetNames(typeof(HttpMethods)))
      {
        if (enumName != "All" && enumName != "None")
        {
          HttpMethods _httpMethod = (HttpMethods)Enum.Parse(typeof(HttpMethods), enumName, true);

          if ((SupportedHttpMethods & _httpMethod) != 0)
          {
            if (_httpMethod == HttpMethods.VersionControl)
              _allowedMethods.Append("version-control" + ", ");
            else
              _allowedMethods.Append(enumName.ToUpper() + ", ");
          }
        }
      }

      //Remove the trailing comma [, ]
      if (_allowedMethods.Length > 2)
        _allowedMethods.Remove(_allowedMethods.Length - 2, 2);

      base.HttpApplication.Response.AddHeader("DAV", _davClass);
      base.HttpApplication.Response.AddHeader("Public", _allowedMethods.ToString());
      base.HttpApplication.Response.AddHeader("Allow", _allowedMethods.ToString());
      base.HttpApplication.Response.AddHeader("Accept-Ranges", "bytes");

      return (int)ServerResponseCode.Ok;
    }
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.