Namespace: ITHit.WebDAV.Server
The DavEngineAsync type exposes the following members.
Name | Description | |
---|---|---|
DavEngineAsync |
Initializes a new instance of this class.
|
Name | Description | |
---|---|---|
AutoPutUnderVersionControl |
Determines if placing file under version control is automatic.
| |
CalculateContentLength |
Indicates if response content length is calculated. Default is true.
(Inherited from EngineAsyncTHierarchyItemAsync.) | |
ContentEncoding |
Gets or sets the HTTP character set of the output stream. Default is UTF-8.
(Inherited from EngineAsyncTHierarchyItemAsync.) | |
CorsAllowedFor |
Enables or disables CORS.
(Inherited from EngineAsyncTHierarchyItemAsync.) | |
License |
Gets or sets the license text.
(Inherited from EngineAsyncTHierarchyItemAsync.) | |
Logger | ILogger instance which engine will use for logging.
(Inherited from EngineAsyncTHierarchyItemAsync.) | |
OutputXmlFormatting |
Specifies whether XML written to the output will be formatted. Default is false.
(Inherited from EngineAsyncTHierarchyItemAsync.) | |
UseFullUris |
Specifies whether engine shall use full or relative urls. Default is true.
(Inherited from EngineAsyncTHierarchyItemAsync.) |
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
RegisterMethodHandler |
Registers custom method handler.
(Overrides EngineAsyncTHierarchyItemAsyncRegisterMethodHandler(String, IMethodHandlerTHierarchyItemAsync).) | |
RegisterOptionsHandler |
Registers custom options handler.
| |
RegisterPropertyHandler |
Registers custom property handler.
| |
RegisterReportHandler |
Registers custom report handler.
| |
RunAsync |
Processes WebDAV request and generates WebDAV response.
(Overrides EngineAsyncTHierarchyItemAsyncRunAsync(ContextAsyncTHierarchyItemAsync).) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
The engine parses XML send by WebDAV client, processes requests making calls to your implementations of WebDAV interfaces (IHierarchyItem, IFolder, IFile, etc and generates XML response.
In each HTTP request, you will create a separate instance of your class derived from ContextAsyncTHierarchyItem class and pass it to the RunAsync(ContextAsyncIHierarchyItem) method. Via the context, the engine receives all necessary information about the hosting environment.
You must set License property before you can use the engine.
All updates invoked within one request execution shall be inside a single transaction. Transaction can be committed or rollbacked in BeforeResponseAsync method, which is called right before starting sending a response to the client. After this method is called, no methods of interfaces which update state will be called by the engine. However, methods which read state can be called.
The code below is part of 'WebDAVServer.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.
public class DavHandler : HttpTaskAsyncHandler { private readonly string license = File.ReadAllText(HttpContext.Current.Request.PhysicalApplicationPath + "License.lic"); private static readonly string googleServiceAccountID = ConfigurationManager.AppSettings["GoogleServiceAccountID"]; private static readonly string googleServicePrivateKey = ConfigurationManager.AppSettings["GoogleServicePrivateKey"]; private static readonly string googleNotificationsRelativeUrl = ConfigurationManager.AppSettings["GoogleNotificationsRelativeUrl"]; private readonly string gSuiteLicense = File.Exists(HttpContext.Current.Request.PhysicalApplicationPath + "GSuiteLicense.lic") ? File.ReadAllText(HttpContext.Current.Request.PhysicalApplicationPath + "GSuiteLicense.lic") : string.Empty; private static readonly bool debugLoggingEnabled = "true".Equals( ConfigurationManager.AppSettings["DebugLoggingEnabled"], StringComparison.InvariantCultureIgnoreCase); public override bool IsReusable { get { return true; } } public override async Task ProcessRequestAsync(HttpContext context) { DavEngineAsync webDavEngine = getOrInitializeWebDavEngine(context); context.Response.BufferOutput = false; DavContext ntfsDavContext = new DavContext(context); GSuiteEngineAsync gSuiteEngine = getOrInitializeGSuiteEngine(context); await webDavEngine.RunAsync(ntfsDavContext); if (gSuiteEngine != null) { await gSuiteEngine.RunAsync(ContextConverter.ConvertToGSuiteContext(ntfsDavContext)); } } private DavEngineAsync initializeWebDavEngine(HttpContext context) { ILogger logger = WebDAVServer.FileSystemStorage.AspNet.Logger.Instance; DavEngineAsync webDavEngine = new DavEngineAsync { Logger = logger // Use idented responses if debug logging is enabled. , OutputXmlFormatting = true }; webDavEngine.License = license; string contentRootPath = HttpContext.Current.Request.MapPath("/"); // Set custom handler to process GET and HEAD requests to folders and display // info about how to connect to server. We are using the same custom handler // class (but different instances) here to process both GET and HEAD because // these requests are very similar. Some WebDAV clients may fail to connect if HEAD // request is not processed. MyCustomGetHandler handlerGet = new MyCustomGetHandler(contentRootPath); MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath); handlerGet.OriginalHandler = webDavEngine.RegisterMethodHandler("GET", handlerGet); handlerHead.OriginalHandler = webDavEngine.RegisterMethodHandler("HEAD", handlerHead); return webDavEngine; } private DavEngineAsync getOrInitializeWebDavEngine(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] = initializeWebDavEngine(context); } return (DavEngineAsync)context.Application[ENGINE_KEY]; } private GSuiteEngineAsync getOrInitializeGSuiteEngine(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 = "$GSuiteEngine$"; if (string.IsNullOrEmpty(googleServiceAccountID) || string.IsNullOrEmpty(googleServicePrivateKey)) { return null; } if (context.Application[ENGINE_KEY] == null) { var gSuiteEngine = new GSuiteEngineAsync(googleServiceAccountID, googleServicePrivateKey, googleNotificationsRelativeUrl) { License = gSuiteLicense, Logger = WebDAVServer.FileSystemStorage.AspNet.Logger.Instance }; context.Application[ENGINE_KEY] = gSuiteEngine; } return (GSuiteEngineAsync)context.Application[ENGINE_KEY]; } }
The code below is part of 'CalDAVServer.SqlStorage.AspNet' C# & VB samples provided with the SDK.
public class DavHandler : HttpTaskAsyncHandler { 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 override bool IsReusable { get { return true; } } public override async Task ProcessRequestAsync(HttpContext context) { DavEngineAsync webDavEngine = getOrInitializeWebDavEngine(context); context.Response.BufferOutput = false; using (var sqlDavContext = new DavContext(context)) { await webDavEngine.RunAsync(sqlDavContext); } } private DavEngineAsync initializeWebDavEngine(HttpContext context) { ILogger logger = CalDAVServer.SqlStorage.AspNet.Logger.Instance; logger.LogFlags = LogFlagsEnum.LogGetResponseBody | LogFlagsEnum.LogPutRequestBody; DavEngineAsync webDavEngine = new DavEngineAsync { Logger = logger // Use idented responses if debug logging is enabled. , OutputXmlFormatting = true // Do not emit CORS headers, typically not required in case of CalDAV/CardDAV server. , CorsAllowedFor = null // Use full URIs only in case of a regular WebDAV server. Microsoft Mini-redirector does not support URIs without domain. , UseFullUris = false }; webDavEngine.License = license; string contentRootPath = HttpContext.Current.Request.MapPath("/"); // Set custom handler to process GET and HEAD requests to folders and display // info about how to connect to server. We are using the same custom handler // class (but different instances) here to process both GET and HEAD because // these requests are very similar. Some WebDAV clients may fail to connect if HEAD // request is not processed. MyCustomGetHandler handlerGet = new MyCustomGetHandler(contentRootPath); MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath); handlerGet.OriginalHandler = webDavEngine.RegisterMethodHandler("GET", handlerGet); handlerHead.OriginalHandler = webDavEngine.RegisterMethodHandler("HEAD", handlerHead); // Set your iCalendar & vCard library license before calling any members. // iCalendar & vCard library accepts: // - WebDAV Server Engine license with iCalendar & vCard modules. Verify your license file to see if these modules are specified. // - or iCalendar and vCard Library license. ITHit.Collab.LicenseValidator.SetLicense(license); return webDavEngine; } private DavEngineAsync getOrInitializeWebDavEngine(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] = initializeWebDavEngine(context); } return (DavEngineAsync)context.Application[ENGINE_KEY]; } }
The code below is part of 'CardDAVServer.SqlStorage.AspNet' C# & VB samples provided with the SDK.
public class DavHandler : HttpTaskAsyncHandler { 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 override bool IsReusable { get { return true; } } public override async Task ProcessRequestAsync(HttpContext context) { DavEngineAsync webDavEngine = getOrInitializeWebDavEngine(context); context.Response.BufferOutput = false; using (var sqlDavContext = new DavContext(context)) { await webDavEngine.RunAsync(sqlDavContext); } } private DavEngineAsync initializeWebDavEngine(HttpContext context) { ILogger logger = CardDAVServer.SqlStorage.AspNet.Logger.Instance; logger.LogFlags = LogFlagsEnum.LogGetResponseBody | LogFlagsEnum.LogPutRequestBody; DavEngineAsync webDavEngine = new DavEngineAsync { Logger = logger // Use idented responses if debug logging is enabled. , OutputXmlFormatting = true // Do not emit CORS headers, typically not required in case of CalDAV/CardDAV server. , CorsAllowedFor = null // Use full URIs only in case of a regular WebDAV server. Microsoft Mini-redirector does not support URIs without domain. , UseFullUris = false }; webDavEngine.License = license; string contentRootPath = HttpContext.Current.Request.MapPath("/"); // Set custom handler to process GET and HEAD requests to folders and display // info about how to connect to server. We are using the same custom handler // class (but different instances) here to process both GET and HEAD because // these requests are very similar. Some WebDAV clients may fail to connect if HEAD // request is not processed. MyCustomGetHandler handlerGet = new MyCustomGetHandler(contentRootPath); MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath); handlerGet.OriginalHandler = webDavEngine.RegisterMethodHandler("GET", handlerGet); handlerHead.OriginalHandler = webDavEngine.RegisterMethodHandler("HEAD", handlerHead); // Set your iCalendar & vCard library license before calling any members. // iCalendar & vCard library accepts: // - WebDAV Server Engine license with iCalendar & vCard modules. Verify your license file to see if these modules are specified. // - or iCalendar and vCard Library license. ITHit.Collab.LicenseValidator.SetLicense(license); return webDavEngine; } private DavEngineAsync getOrInitializeWebDavEngine(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] = initializeWebDavEngine(context); } return (DavEngineAsync)context.Application[ENGINE_KEY]; } }