コード例 #1
0
ファイル: CalDav.cs プロジェクト: flechilla/CalDavServer
        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);
        }
コード例 #2
0
ファイル: CalDav.cs プロジェクト: flechilla/CalDavServer
        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);
        }
コード例 #3
0
 /// <summary>
 ///     Apply the time-filter to the
 /// </summary>
 /// <param name="resources"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="filter"></param>
 /// <returns></returns>
 public static Dictionary <string, VCalendar> TimeFilter(this Dictionary <string, VCalendar> resources,
                                                         DateTime start, DateTime end, IXMLTreeStructure filter)
 {
     foreach (var resource in resources)
     {
         var compNode = filter.GetChild("comp-filter");
         var compName = compNode.Attributes["name"];
         if (resource.Value.CalendarComponents.ContainsKey(compName))
         {
         }
         else
         {
             continue;
         }
     }
     return(null);
 }