Beispiel #1
0
        private void BuildResponse(AbstractFolder currentFolder, List <XElement> props, int depth, XElement elementBase)
        {
            var supportedProperties = new HashSet <XName>();

            var response = Common.xDav.Element("response");

            response.Add(Common.xDav.Element("href", currentFolder.Path));
            var propStat = Common.xDav.Element("propstat");

            response.Add(propStat);

            propStat.Add(Common.xDav.Element("status", "HTTP/1.1 200 OK"));

            var prop = Common.xDav.Element("prop");

            propStat.Add(prop);


            if (depth < 0)
            {
                return;
            }

            AbstractCalendarRepository calendarFolder = null;


            var allprop       = props.Elements(Common.xDav.GetName("allprops")).Any();
            var hrefName      = Common.xDav.GetName("href");
            var privilegeName = Common.xDav.GetName("privilege");

            XElement resourceType     = null;
            XName    resourceTypeName = null;

            XElement getctag     = null;
            XName    getctagName = null;

            XElement getContentType     = null;
            XName    getContentTypeName = null;

            XName getetagName = Common.xDav.GetName("getetag");


            // Dav:: https://tools.ietf.org/html/rfc3744#section-5.1.1
            // CalDav:: https://icalendar.org/RFC-Specifications/CalDAV-Access-RFC-4791/

            foreach (var currentProp in props)
            {
                var test = Properties.Where(a => a.Name == currentProp.Name).SingleOrDefault();

                XElement currentElement = null;
                if (test != null)
                {
                    currentElement = test.Build(allprop, props, currentFolder, prop, supportedProperties, RequestData);

                    if (currentProp.Name.LocalName.Equals("resourcetype"))
                    {
                        resourceType     = currentElement;
                        resourceTypeName = test.Name;
                    }
                    else if (currentProp.Name.LocalName.Equals("getctag"))
                    {
                        getctag     = currentElement;
                        getctagName = test.Name;
                    }
                    else if (currentProp.Name.LocalName.Equals("getcontenttype"))
                    {
                        getContentType     = currentElement;
                        getContentTypeName = test.Name;
                    }
                }
            }


            var status = BuildUnsupportedProperties(props, supportedProperties);

            if (status != null)
            {
                response.Add(status);
            }


            elementBase.Add(response);
            // solve Depth

            // if this is a calendar folder and depth request remains return calendar props
            if (currentFolder.Type == FileSystem.FolderType.CalendarFolder && depth > 0)
            {
                calendarFolder = (AbstractCalendarRepository)currentFolder;

                var calendarObjects = calendarFolder.GetObjects().Where(x => x != null).ToArray();

                var calendarItems = calendarObjects.Select(item => Common.xDav.Element("response",
                                                                                       hrefName.Element($"{calendarFolder.Path}{item.UID}.ics"),
                                                                                       Common.xDav.Element("propstat",
                                                                                                           Common.xDav.Element("status", "HTTP/1.1 200 OK"),
                                                                                                           resourceType == null ? null : resourceTypeName.Element(),
                                                                                                           (getContentType == null
                           ? null
                           : getContentTypeName.Element("text/calendar; component=v" + item.GetType().Name.ToLower())),
                                                                                                           getetagName.Element("\"" + Common.FormatDate(item.LastModified) + "\"")
                                                                                                           ))).ToArray();

                elementBase.Add(calendarItems);
            }
            depth--;
            foreach (var child in currentFolder.ChildFolders ?? new List <AbstractFolder>())
            {
                BuildResponse(child, props, depth, elementBase);
            }
        }