/// <summary> /// The CALDAV:calendar-query REPORT performs a search for all calendar object resources that match a /// specified filter. The response of this report will contain all the WebDAV properties and calendar object /// resource data specified in the request. In the case of the CALDAV:calendar-data XML element, one can /// explicitly specify the calendar components and properties that should be returned in the calendar object /// resource data that matches the filter. /// </summary> /// <param name="xmlDoc">The body of the request.</param> /// <param name="collectionURl"></param> /// <param name="httpContext"></param> /// <returns></returns> public async Task CalendarQuery(IXMLTreeStructure xmlDoc, string collectionURl, HttpContext httpContext) { IFileSystemManagement fs = new FileSystemManagement(); // take the first prop node to know the data that // should ne returned IXMLTreeStructure propNode; xmlDoc.GetChildAtAnyLevel("prop", out propNode); //get the filters to be applied IXMLTreeStructure componentFilter; xmlDoc.GetChildAtAnyLevel("filter", out componentFilter); var userResources = new Dictionary <string, string>(); await fs.GetAllCalendarObjectResource(collectionURl, userResources); var userCalendars = userResources.ToDictionary(userResource => userResource.Key, userResource => VCalendar.Parse(userResource.Value)); //apply the filters to the calendars var filteredCalendars = userCalendars.Where(x => x.Value.FilterResource(componentFilter)); await ReportResponseBuilder(filteredCalendars, propNode, httpContext); }
/// <summary> /// The CALDAV:calendar-multiget REPORT is used to retrieve specific calendar object resources from within a /// collection, if the Request-URI is a collection, or to retrieve a specific calendar object resource, if the /// Request-URI is a calendar object resource. This report is similar to the CALDAV:calendar-query REPORT /// (see Section 7.8), except that it takes a list of DAV:href elements, instead of a CALDAV:filter element, to /// determine which calendar object resources to return /// </summary> /// <returns></returns> private async Task CalendarMultiget(IXMLTreeStructure xmlBody, HttpContext httpContext) { // take the first prop node to know the data that // should ne returned IXMLTreeStructure propNode; xmlBody.GetChildAtAnyLevel("prop", out propNode); //take the href nodes. Contain the direction of the resources files that //are requested var hrefs = xmlBody.Children.Where(node => node.NodeName == "href").Select(href => href.Value); var result = new Dictionary <string, string>(); // process the requested resources foreach (var href in hrefs) { var fs = new FileSystemManagement(); var resourceContent = await fs.GetCalendarObjectResource(href); result.Add(href, resourceContent); } await ReportResponseBuilder(result .Select( x => new KeyValuePair <string, VCalendar>(x.Key, string.IsNullOrEmpty(x.Value) ? null : VCalendar.Parse(x.Value))), propNode, httpContext); }