Esempio n. 1
0
        public async Task <bool> PosconditionOk(Dictionary <string, string> propertiesAndHeaders, HttpResponse response)
        {
            #region Extracting Properties

            string url;
            propertiesAndHeaders.TryGetValue("url", out url);

            #endregion

            if (!Fs.ExistCalendarCollection(url) || await _collectionRepository.Exist(url))
            {
                response.StatusCode = (int)HttpStatusCode.Forbidden;
                response.Body.Write(@"<?xml version='1.0' encoding='UTF-8'?>
<error xmlns:D='DAV:' xmlns:C='urn:ietf:params:xml:ns:caldav'>
  <C:initialize-calendar-collection/>  
</error>");
                return(await Task.FromResult(false));
            }

            return(await Task.FromResult(true));
        }
        public async Task <bool> PreconditionsOK(Dictionary <string, string> propertiesAndHeaders, HttpResponse response)
        {
            #region Extracting Properties

            var body = propertiesAndHeaders["body"];
            var url  = propertiesAndHeaders["url"];

            #endregion

            if (fs.ExistCalendarCollection(url) || await _collectionRepository.Exist(url))
            {
                response.StatusCode = (int)HttpStatusCode.Forbidden;
                response.Body.Write(@"<?xml version='1.0' encoding='UTF-8'?>
<error xmlns='DAV:'>
  <resource-must-be-null/>  
</error>");

                return(false);
            }

            if (!string.IsNullOrEmpty(body))
            {
                var bodyTree = XmlTreeStructure.Parse(body);
                if (bodyTree == null)
                {
                    response.StatusCode = (int)HttpStatusCode.Forbidden;
                    response.Body.Write("Wrong Body");
                    return(false);
                }
                if (bodyTree.NodeName != "mkcalendar")
                {
                    response.StatusCode = (int)HttpStatusCode.Forbidden;
                    response.Body.Write("Wrong Body");

                    return(false);
                }
            }

            return(true);
        }
        public async Task <bool> PreconditionsOK(Dictionary <string, string> propertiesAndHeaders, HttpResponse response)
        {
            string calendarResourceId;

            propertiesAndHeaders.TryGetValue("calendarResourceID", out calendarResourceId);

            string url;

            propertiesAndHeaders.TryGetValue("url", out url);

            if (calendarResourceId == null && !await _collectionRepository.Exist(url))
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return(false);
            }
            if (calendarResourceId != null && !await _resourceRespository.Exist(url))
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public async Task <bool> DeleteCalendarObjectResource(Dictionary <string, string> propertiesAndHeaders,
                                                              HttpResponse response)
        {
            #region Extracting Properties

            string url;
            propertiesAndHeaders.TryGetValue("url", out url);

            string ifmatch;
            var    ifMatchEtags = new List <string>();
            propertiesAndHeaders.TryGetValue("If-Match", out ifmatch);
            if (ifmatch != null)
            {
                ifMatchEtags = ifmatch.Split(',').ToList();
            }

            #endregion

            //if the collection doesnt exist in the user folder
            // the can't do anything

            var collectionUrl = url?.Remove(url.LastIndexOf("/", StringComparison.Ordinal) + 1);
            if (!StorageManagement.ExistCalendarCollection(collectionUrl) &&
                !await _collectionRespository.Exist(collectionUrl))
            {
                return(true);
            }

            var resource =
                _resourceRespository.Get(url);

            if (ifMatchEtags.Count > 0)
            {
                if (resource != null)
                {
                    var resourceEtag =
                        XmlTreeStructure.Parse(resource.Properties.FirstOrDefault(x => x.Name == "getetag")?.Value)
                        .Value;
                    if (resourceEtag != null && ifMatchEtags.Contains(resourceEtag))
                    {
                        response.StatusCode = (int)HttpStatusCode.NoContent;
                        await _resourceRespository.Remove(resource);


                        //updating the ctag
                        var stack = new Stack <string>();
                        await
                        _collectionRespository.CreateOrModifyProperty(collectionUrl, "getctag",
                                                                      _namespacesSimple["S"],
                                                                      $@"<S:getctag {_namespaces["S"]} >{Guid.NewGuid()}</S:getctag>", stack, true);


                        return(StorageManagement.DeleteCalendarObjectResource(url));
                    }
                }
            }


            if (resource != null)
            {
                response.StatusCode = (int)HttpStatusCode.NoContent;
                await _resourceRespository.Remove(resource);

                //updating the ctag
                var stack = new Stack <string>();
                await _collectionRespository.CreateOrModifyProperty(collectionUrl, "getctag", _namespacesSimple["S"],
                                                                    $@"<S:getctag {_namespaces["S"]} >{Guid.NewGuid()}</S:getctag>", stack, true);


                return(StorageManagement.DeleteCalendarObjectResource(url));
            }

            return(StorageManagement.DeleteCalendarObjectResource(url));
        }