Exemplo n.º 1
0
        private async Task <bool> BuiltResponseForSet(string url, string calendarResourceId,
                                                      bool errorOccurred, IXMLTreeStructure setTree, IXMLTreeStructure response)
        {
            //For each property it is tried to remove, if not possible change the error occured to true and
            //continue setting dependency error to the rest.
            var prop       = setTree.GetChild("prop");
            var errorStack = new Stack <string>();

            foreach (var property in prop.Children)
            {
                var propstat = new XmlTreeStructure("propstat", "DAV:");
                var stat     = new XmlTreeStructure("status", "DAV:");
                var resProp  = new XmlTreeStructure("prop", "DAV:");

                resProp.AddChild(new XmlTreeStructure(property.NodeName, property.MainNamespace));
                propstat.AddChild(stat);
                propstat.AddChild(resProp);

                response.AddChild(propstat);

                if (errorOccurred)
                {
                    stat.Value = "HTTP/1.1 424 Failed Dependency";
                }

                else
                {
                    //Try to modify the specified property if it exist, if not try to create it
                    //gets an error message from the stack in case of problems.
                    errorOccurred =
                        !(calendarResourceId != null
                            ? await
                          _resourceRespository.CreateOrModifyProperty(url, property.NodeName,
                                                                      property.MainNamespace,
                                                                      GetValueFromRealProperty(property), errorStack, false)
                            : await
                          _collectionRespository.CreateOrModifyProperty(url, property.NodeName,
                                                                        property.MainNamespace,
                                                                        GetValueFromRealProperty(property), errorStack, false));
                    //collection.CreateOrModifyProperty(property.NodeName, property.MainNamespace,
                    //    GetValueFromRealProperty(property), errorStack));
                    if (errorOccurred && errorStack.Count > 0)
                    {
                        stat.Value = errorStack.Pop();
                    }
                    else
                    {
                        stat.Value = "HTTP/1.1 200 OK";
                        //db.SaveChanges();
                    }
                }
            }
            return(errorOccurred);
        }
Exemplo n.º 2
0
        private async Task <bool> BuiltResponseForRemove(string url, string calendarResourceId,
                                                         bool errorOccurred, IXMLTreeStructure removeTree, IXMLTreeStructure response)
        {
            //For each property it is tried to remove, if not possible change the error occured to true and
            //continue setting dependency error to the rest.
            var prop       = removeTree.GetChild("prop");
            var errorStack = new Stack <string>();

            foreach (var property in prop.Children)
            {
                //The structure for the response does not change.
                //It is constructed with a propstat and the value is never showed in the prop element.
                var propstat = new XmlTreeStructure("propstat", "DAV:");
                var stat     = new XmlTreeStructure("status", "DAV:");
                var resProp  = new XmlTreeStructure("prop", "DAV:");

                propstat.AddChild(stat);
                propstat.AddChild(resProp);
                resProp.AddChild(new XmlTreeStructure(property.NodeName, property.MainNamespace));
                response.AddChild(propstat);

                //If an error occurred previously the stat if 424 Failed Dependency.
                if (errorOccurred)
                {
                    stat.Value = "HTTP/1.1 424 Failed Dependency";
                }


                else
                {
                    //Try to remove the specified property, gets an error message from the stack in case of problems.
                    errorOccurred =
                        !(calendarResourceId != null
                            ? await
                          _resourceRespository.RemoveProperty(url,
                                                              new KeyValuePair <string, string>(property.NodeName, property.MainNamespace),
                                                              errorStack)
                            : await _collectionRespository.RemoveProperty(url,
                                                                          new KeyValuePair <string, string>(property.NodeName, property.MainNamespace), errorStack));
                    //collection.RemoveProperty(property.NodeName, property.MainNamespace, errorStack));
                    if (errorOccurred && errorStack.Count > 0)
                    {
                        stat.Value = errorStack.Pop();
                    }
                    else
                    {
                        stat.Value = "HTTP/1.1 200 OK";
                        // db.SaveChanges();
                    }
                }
            }
            return(errorOccurred);
        }