Exemplo n.º 1
0
        internal static XmlNode GenerateQueryCAML(QueryFilter query)
        {
            XmlDocument xmlDocument = new SafeXmlDocument();
            XmlNode     xmlNode     = xmlDocument.CreateElement("Query");

            if (query != null)
            {
                xmlNode.AppendChild(xmlDocument.CreateElement("Where"));
                xmlNode.ChildNodes[0].AppendChild(SharepointHelpers.GenerateQueryCAMLHelper(query, xmlDocument, 0));
            }
            return(xmlNode);
        }
Exemplo n.º 2
0
        private static XmlNode GenerateQueryCAMLHelper(QueryFilter query, XmlDocument xmlDoc, int depth)
        {
            if (depth >= SharepointHelpers.MaxFilterHierarchyDepth)
            {
                throw new ArgumentException("filter");
            }
            XmlNode xmlNode = null;

            if (query is AndFilter)
            {
                AndFilter andFilter = (AndFilter)query;
                using (ReadOnlyCollection <QueryFilter> .Enumerator enumerator = andFilter.Filters.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        QueryFilter query2 = enumerator.Current;
                        if (xmlNode == null)
                        {
                            xmlNode = SharepointHelpers.GenerateQueryCAMLHelper(query2, xmlDoc, depth + 1);
                        }
                        else
                        {
                            XmlNode newChild = xmlNode;
                            xmlNode = xmlDoc.CreateElement("And");
                            xmlNode.AppendChild(newChild);
                            xmlNode.AppendChild(SharepointHelpers.GenerateQueryCAMLHelper(query2, xmlDoc, depth + 1));
                        }
                    }
                    return(xmlNode);
                }
            }
            if (query is OrFilter)
            {
                OrFilter orFilter = (OrFilter)query;
                using (ReadOnlyCollection <QueryFilter> .Enumerator enumerator2 = orFilter.Filters.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        QueryFilter query3 = enumerator2.Current;
                        if (xmlNode == null)
                        {
                            xmlNode = SharepointHelpers.GenerateQueryCAMLHelper(query3, xmlDoc, depth + 1);
                        }
                        else
                        {
                            XmlNode newChild2 = xmlNode;
                            xmlNode = xmlDoc.CreateElement("Or");
                            xmlNode.AppendChild(newChild2);
                            xmlNode.AppendChild(SharepointHelpers.GenerateQueryCAMLHelper(query3, xmlDoc, depth + 1));
                        }
                    }
                    return(xmlNode);
                }
            }
            if (!(query is ComparisonFilter))
            {
                throw new NotSupportedException(Strings.ExFilterNotSupported(query.GetType()));
            }
            ComparisonFilter comparisonFilter = (ComparisonFilter)query;

            switch (comparisonFilter.ComparisonOperator)
            {
            case ComparisonOperator.Equal:
                xmlNode = xmlDoc.CreateElement("Eq");
                break;

            case ComparisonOperator.NotEqual:
                xmlNode = xmlDoc.CreateElement("Neq");
                break;

            case ComparisonOperator.LessThan:
                xmlNode = xmlDoc.CreateElement("Lt");
                break;

            case ComparisonOperator.LessThanOrEqual:
                xmlNode = xmlDoc.CreateElement("Leq");
                break;

            case ComparisonOperator.GreaterThan:
                xmlNode = xmlDoc.CreateElement("Gt");
                break;

            case ComparisonOperator.GreaterThanOrEqual:
                xmlNode = xmlDoc.CreateElement("Geq");
                break;

            default:
                throw new InvalidOperationException("Invalid comparison operator");
            }
            SharepointPropertyDefinition sharepointPropertyDefinition = (SharepointPropertyDefinition)comparisonFilter.Property;

            xmlNode.InnerXml = string.Format("<FieldRef Name=\"{0}\" /><Value Type=\"{1}\">{2}</Value>", sharepointPropertyDefinition.SharepointName, sharepointPropertyDefinition.FieldTypeAsString, sharepointPropertyDefinition.ToSharepoint(comparisonFilter.PropertyValue, null));
            return(xmlNode);
        }