DavPropFindBase.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 » DavPropFindBase.cs
using System;
using System.IO;
using System.Xml.XPath;
using System.Globalization;

using Sphorium.WebDAV.Server.Framework.Resources;
using Sphorium.WebDAV.Server.Framework.Collections;

namespace Sphorium.WebDAV.Server.Framework.BaseClasses{
  /// <summary>
  /// Dav Resource PROPFIND Framework Base Class
  /// </summary>
  /// <remarks>
  ///    RFC2518 Compliant
  ///    
  ///    <code>
  ///    The ProcessDavRequest event must follow the following rules addressed in RFC2518
  ///      http://www.webdav.org/specs/rfc2518.html#METHOD_PROPFIND
  ///    </code>
  ///    
  ///    <code>
  ///      Returns ServerResponseCode.MultiStatus when successful
  ///    </code>
  ///    <seealso cref="DavMethodBase.AbortRequest(System.Enum)"/>
  /// </remarks>  
  public abstract class DavPropFindBase : DavResourceFindBase
  {
    /// <summary>
    /// Dav Resource PROPFIND Framework Base Class
    /// </summary>
    protected DavPropFindBase()
    {
      //Make sure the dav processing
      this.InternalProcessDavRequest += new DavInternalProcessHandler(DavPropFindBase_InternalProcessDavRequest);
      this.ValidateDavRequest += new DavRequestValidator(DavPropFindBase_ValidateDavRequest);

      this.RequestPropertyType = PropertyRequestType.None;
    }

    /// <summary>
    /// Property request types
    /// </summary>
    protected enum PropertyRequestType
    {
      /// <summary>
      /// No properties requested
      /// </summary>
      None,

      /// <summary>
      /// Specific properties requested
      /// <seealso cref="DavResourceFindBase.RequestProperties"/>
      /// </summary>
      NamedProperties,

      /// <summary>
      /// A summary of all the available properties
      /// </summary>
      PropertyNames,

      /// <summary>
      /// All properties requested
      /// </summary>
      AllProperties
    }

    /// <summary>
    /// Requested Property type
    /// <seealso cref="PropertyRequestType"/>
    /// </summary>
    protected PropertyRequestType RequestPropertyType { get; private set; }

    private int DavPropFindBase_ValidateDavRequest(object sender, EventArgs e)
    {
      int _returnCode = (int)ServerResponseCode.Ok;

      //Clear out all the collection resources
      base.FileResources.Clear();
      base.CollectionResources.Clear();

      //NOTE: An empty PROPFIND request body MUST be treated as a request for the names 
      //  and values of all properties.
      if (base.RequestXml == null)
        this.RequestPropertyType = PropertyRequestType.AllProperties;

      else
      {
        XPathNodeIterator _propFindNodeIterator = base.RequestXml.SelectDescendants("propfind", "DAV:", false);
        if (_propFindNodeIterator.MoveNext())
        {
          if (_propFindNodeIterator.Current.MoveToFirstChild())
          {
            switch (_propFindNodeIterator.Current.LocalName.ToLower(CultureInfo.InvariantCulture))
            {
              case "propnames":
                this.RequestPropertyType = PropertyRequestType.PropertyNames;
                break;
              case "allprop":
                this.RequestPropertyType = PropertyRequestType.AllProperties;
                break;
              default:
                this.RequestPropertyType = PropertyRequestType.NamedProperties;
                break;
            }
          }
          else
            _returnCode = (int)ServerResponseCode.BadRequest;
        }
        else
          _returnCode = (int)ServerResponseCode.BadRequest;
      }

      //Write to the debug log
      InternalFunctions.WriteDebugLog("DavPropFindBase: PropertyRequestType - " + this.RequestPropertyType);
      return _returnCode;
    }


    private int DavPropFindBase_InternalProcessDavRequest(object sender, EventArgs e)
    {
      int _returnCode = (int)ServerResponseCode.BadRequest;

      switch (this.RequestPropertyType)
      {
        case PropertyRequestType.AllProperties:
          ////Fix for XP Web Folder mini-redirector
          //if (this.CollectionResources.Count == 0 && base.HttpApplication.Request.UserAgent == "Microsoft Data Access Internet Publishing Provider DAV")
          //{
          //    DavFolder _rootFolder = new DavFolder("", "/");
          //    this.CollectionResources.Add(_rootFolder);
          //}

          if (this.ResourceCount == 0)
            _returnCode = (int)ServerResponseCode.NotFound;
          else
            _returnCode = base.LoadNodes(null);
          break;

        case PropertyRequestType.NamedProperties:
          ////Fix for XP Web Folder mini-redirector
          //if (this.CollectionResources.Count == 0 && base.HttpApplication.Request.UserAgent == "Microsoft Data Access Internet Publishing Provider DAV")
          //{
          //    DavFolder _rootFolder = new DavFolder("", "/");
          //    this.CollectionResources.Add(_rootFolder);
          //}

          if (this.ResourceCount == 0)
            _returnCode = (int)ServerResponseCode.NotFound;
          else
            _returnCode = base.LoadNodes(base.RequestProperties);
          break;

        case PropertyRequestType.PropertyNames:
          _returnCode = base.LoadNodePropertyNames();
          break;
      }

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