Click or drag to resize

DavEngine Class

IT Hit WebDAV Classes Reference
The DavEngine class provides the core implementation for WebDAV engine.
Inheritance Hierarchy
SystemObject
  ITHit.WebDAV.ServerDavEngine

Namespace: ITHit.WebDAV.Server
Assembly: ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 4.5.3121.0
Syntax
public sealed class DavEngine

The DavEngine type exposes the following members.

Constructors
  NameDescription
Public methodDavEngine
Initializes a new instance of the DavEngine class.
Top
Properties
  NameDescription
Public propertyAutoPutUnderVersionControl
Determines if placing file under version control is automatic.
Public propertyCalculateContentLength
Indicates if response content length calculation will occur.
Public propertyContentEncoding
Gets or sets the HTTP character set of the output stream.
Public propertyCorsAllowedFor
Enables or disables CORS.
Public propertyCode exampleLicense
Gets or sets the license text.
Public propertyLogger
ILogger instance which engine will use for logging.
Public propertyOutputXmlFormatting
Specifies whether XML written to the output will be formatted.
Public propertyUseFullUris
Specifies whether engine shall use full or relative urls.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleRegisterMethodHandler
Registers custom method handler.
Public methodRegisterOptionsHandler
Registers custom options handler.
Public methodRegisterPropertyHandler
Registers custom property handler.
Public methodRegisterReportHandler
Registers custom report handler.
Public methodCode exampleRun
Processes WebDAV request and generates WebDAV response.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

Engine parses XML send by WebDAV client, processes requests making calls to your implementations of WebDAV interfaces (IHierarchyItem, IFolder, IFile and other) and finally generates XML response.

In each HTTP request you will create separate instance of your class derived from DavContextBase class and pass it to the Run(DavContextBase) method. Via the context, engine receives all necessary information about hosting environment.

You must set License property before you can use the engine.

All updates invoked within one request execution shall be inside one transactions. Transaction can be committed or rollbacked in BeforeResponse method, which is called right before starting sending response to client. After this method is called, no methods of interfaces which update state will be called. However methods which read state can be called.

Examples

The code below is part of 'WebDAVServer.NtfsStorage' sample provided with the SDK.

public class DavHandler : IHttpHandler
{
    private readonly string license = File.ReadAllText(HttpContext.Current.Request.PhysicalApplicationPath + "License.lic");

    private static readonly bool debugLoggingEnabled =
        "true".Equals(
            ConfigurationManager.AppSettings["DebugLoggingEnabled"],
            StringComparison.InvariantCultureIgnoreCase);

    public bool IsReusable
    {
        get { return true; }
    }


    public void ProcessRequest(HttpContext context)
    {
        DavEngine engine = getOrInitializeEngine(context);

        context.Response.BufferOutput = false;
        DavContext ntfsDavContext = new DavContext(context);
        engine.Run(ntfsDavContext);
    }

    private DavEngine initializeEngine(HttpContext context)
    {

        ILogger logger = Logger.Instance;
        var engine = new DavEngine
        {
            Logger = logger

            // Use idented responses if debug logging is enabled.
            , OutputXmlFormatting = debugLoggingEnabled ? Formatting.Indented : Formatting.None
        };

        engine.License = license;

        return engine;
    }

    private DavEngine getOrInitializeEngine(HttpContext context)
    {
        //we don't use any double check lock pattern here because nothing wrong
        //is going to happen if we created occasionally several engines.
        const string ENGINE_KEY = "$DavEngine$";
        if (context.Application[ENGINE_KEY] == null)
        {
            context.Application[ENGINE_KEY] = initializeEngine(context);
        }

        return (DavEngine)context.Application[ENGINE_KEY];
    }
}
Examples

HttpListener-based server:

class Program
{
    static void Main(string[] args)
    {
        HttpListener listener = new HttpListener();
        listener.Prefixes.Add("http://localhost:8080/");
        listener.Start();
        DavEngine engine = new DavEngine();
        engine.License = "..."; 
        while (true)
        {
            HttpListenerContext context = listener.GetContext();
            engine.Run(new MyContext(context, listener.Prefixes));
            try
            {
                context.Response.Close();
            }
            catch
            {
                // client closed connection before the content was sent
            }
        }
    }
}
Thread Safety
Method Run(DavContextBase) is threadsafe. All other members are not threadsafe. You can create a single instance of DavEngine, initialize it onces and use to serve all requests from different threads.
See Also