Exemplo n.º 1
0
 public SPCamlQueryBuilder_SPWeb(ObjectInstance prototype, SPCamlQueryBuilderInstance builder, int startIndex)
     : base(prototype)
 {
     this.Builder    = builder;
     this.StartIndex = startIndex;
     this.PopulateFunctions();
 }
Exemplo n.º 2
0
 public SPCamlQueryBuilder_Membership(ObjectInstance prototype, SPCamlQueryBuilderInstance builder, int startIndex)
     : base(prototype)
 {
     this.Builder    = builder;
     this.StartIndex = startIndex;
     this.SPWeb      = new SPCamlQueryBuilder_SPWeb(this.Engine.Object.InstancePrototype, builder, startIndex);
     this.PopulateFields();
     this.PopulateFunctions();
 }
Exemplo n.º 3
0
 public SPCamlQueryBuilder_OrderedQuery OrderBy(string sortFieldName, bool overrideOrderBy, bool useIndexForOrderBy)
 {
     SPCamlQueryBuilderInstance.StartOrderBy(this.Builder, overrideOrderBy, useIndexForOrderBy);
     this.Builder.Tree.Add(new CamlHump
     {
         Element = CamlHumpElementType.FieldRef,
         Name    = sortFieldName,
     });
     return(new SPCamlQueryBuilder_OrderedQuery(this.Engine.Object.InstancePrototype, this.Builder));
 }
Exemplo n.º 4
0
        public static void UnaryOperator(SPCamlQueryBuilderInstance camlBuilder, int startIndex, string operation)
        {
            camlBuilder.Tree.Insert(startIndex, new CamlHump
            {
                Element = CamlHumpElementType.Start,
                Name    = operation,
            });

            camlBuilder.Tree.Add(new CamlHump
            {
                Element = CamlHumpElementType.End,
            });
        }
Exemplo n.º 5
0
        public static void Membership(SPCamlQueryBuilderInstance camlBuilder, int startIndex, string type)
        {
            camlBuilder.Tree.Insert(startIndex, new CamlHump
            {
                Element    = CamlHumpElementType.Start,
                Name       = "Membership",
                Attributes = new Dictionary <string, string> {
                    { "Type", type }
                },
            });

            camlBuilder.Tree.Add(new CamlHump
            {
                Element = CamlHumpElementType.End,
            });
        }
Exemplo n.º 6
0
        public static void StartGroupBy(SPCamlQueryBuilderInstance camlBuilder, string groupFieldName, bool collapse)
        {
            if (camlBuilder.UnclosedTags > 0)
            {
                camlBuilder.Tree.Add(new CamlHump
                {
                    Element = CamlHumpElementType.End,
                    Count   = camlBuilder.UnclosedTags
                });
            }

            camlBuilder.UnclosedTags = 0;

            if (collapse)
            {
                camlBuilder.Tree.Add(new CamlHump
                {
                    Element    = CamlHumpElementType.Start,
                    Name       = "GroupBy",
                    Attributes = new Dictionary <String, String> {
                        { "Collapse", "TRUE" }
                    }
                });
            }
            else
            {
                camlBuilder.Tree.Add(new CamlHump
                {
                    Element = CamlHumpElementType.Start,
                    Name    = "GroupBy"
                });
            }

            camlBuilder.Tree.Add(new CamlHump
            {
                Element = CamlHumpElementType.FieldRef,
                Name    = groupFieldName
            });

            camlBuilder.Tree.Add(new CamlHump
            {
                Element = CamlHumpElementType.End
            });
        }
Exemplo n.º 7
0
        public SPCamlQueryBuilder_FieldRef(ObjectInstance prototype, SPCamlQueryBuilderInstance builder, string name, string valueType, bool lookupId)
            : base(prototype)
        {
            this.Builder    = builder;
            this.StartIndex = builder.Tree.Count;
            this.ValueType  = valueType;

            this.Membership = new SPCamlQueryBuilder_Membership(this.Engine.Object.InstancePrototype, this.Builder, this.StartIndex);

            this.Builder.Tree.Add(new CamlHump
            {
                Element  = CamlHumpElementType.FieldRef,
                Name     = name,
                LookupId = lookupId,
            });

            this.PopulateFields();
            this.PopulateFunctions();
        }
Exemplo n.º 8
0
        public static void StartOrderBy(SPCamlQueryBuilderInstance camlBuilder, bool overrideOrderBy, bool useIndexForOrderBy)
        {
            if (camlBuilder.UnclosedTags > 0)
            {
                camlBuilder.Tree.Add(new CamlHump
                {
                    Element = CamlHumpElementType.End,
                    Count   = camlBuilder.UnclosedTags
                });
            }

            camlBuilder.UnclosedTags = 1;

            Dictionary <string, string> attributes = new Dictionary <string, string>();

            if (overrideOrderBy)
            {
                attributes.Add("Override", "TRUE");
            }

            if (useIndexForOrderBy)
            {
                attributes.Add("UseIndexForOrderBy", "TRUE");
            }

            if (attributes.Count > 0)
            {
                camlBuilder.Tree.Add(new CamlHump
                {
                    Element    = CamlHumpElementType.Start,
                    Name       = "OrderBy",
                    Attributes = attributes,
                });
            }
            else
            {
                camlBuilder.Tree.Add(new CamlHump
                {
                    Element = CamlHumpElementType.Start,
                    Name    = "OrderBy",
                });
            }
        }
Exemplo n.º 9
0
 public SPCamlQueryBuilder_Token GreaterThan(object value)
 {
     SPCamlQueryBuilderInstance.BinaryOperator(this.Builder, this.StartIndex, "Gt", this.ValueType, value.ToString());
     return(new SPCamlQueryBuilder_Token(this.Engine.Object.InstancePrototype, this.Builder, this.StartIndex));
 }
Exemplo n.º 10
0
 public SPCamlQueryBuilder_Token IsNotNull()
 {
     SPCamlQueryBuilderInstance.UnaryOperator(this.Builder, this.StartIndex, "IsNotNull");
     return(new SPCamlQueryBuilder_Token(this.Engine.Object.InstancePrototype, this.Builder, this.StartIndex));
 }
Exemplo n.º 11
0
 public override string ToString()
 {
     return(SPCamlQueryBuilderInstance.Finalize(this.Builder));
 }
Exemplo n.º 12
0
 public SPCamlQueryBuilder_GroupedQuery(ObjectInstance prototype, SPCamlQueryBuilderInstance builder)
     : base(prototype)
 {
     this.Builder = builder;
     this.PopulateFunctions();
 }
Exemplo n.º 13
0
 public SPCamlQueryBuilder_Token Groups()
 {
     SPCamlQueryBuilderInstance.Membership(this.Builder, this.StartIndex, "SPWeb.Groups");
     return(new SPCamlQueryBuilder_Token(this.Engine.Object.InstancePrototype, this.Builder, this.StartIndex));
 }
Exemplo n.º 14
0
 public SPCamlQueryBuilder_GroupedQuery GroupBy(string groupFieldName, bool collapse)
 {
     SPCamlQueryBuilderInstance.StartGroupBy(this.Builder, groupFieldName, collapse);
     return(new SPCamlQueryBuilder_GroupedQuery(this.Engine.Object.InstancePrototype, this.Builder));
 }
Exemplo n.º 15
0
        public static string Finalize(SPCamlQueryBuilderInstance camlBuilder)
        {
            var sb     = new StringBuilder();
            var writer = XmlWriter.Create(sb, new XmlWriterSettings {
                Indent             = true,
                OmitXmlDeclaration = true,
                ConformanceLevel   = ConformanceLevel.Fragment
            });

            foreach (var node in camlBuilder.Tree)
            {
                switch (node.Element)
                {
                case CamlHumpElementType.FieldRef:
                    writer.WriteStartElement("FieldRef");
                    writer.WriteAttributeString("Name", node.Name);
                    if (node.LookupId)
                    {
                        writer.WriteAttributeString("LookupId", "True");
                    }

                    if (node.IsDescending)
                    {
                        writer.WriteAttributeString("Ascending", "False");
                    }
                    writer.WriteEndElement();
                    break;

                case CamlHumpElementType.Start:
                    writer.WriteStartElement(node.Name);
                    if (node.Attributes != null && node.Attributes.Count > 0)
                    {
                        foreach (var attribute in node.Attributes)
                        {
                            writer.WriteAttributeString(attribute.Key, attribute.Value);
                        }
                    }
                    break;

                case CamlHumpElementType.Value:
                    writer.WriteStartElement("Value");
                    writer.WriteAttributeString("Type", node.ValueType);
                    if (node.Value.StartsWith("{") && node.Value.EndsWith("}"))
                    {
                        writer.WriteRaw("<" + node.Value.Trim('{', '}') + "/>");
                    }
                    else
                    {
                        writer.WriteString(node.Value);
                    }
                    writer.WriteEndElement();
                    break;

                case CamlHumpElementType.End:
                    if (node.Count.HasValue)
                    {
                        for (int i = 0; i < node.Count; i++)
                        {
                            writer.WriteEndElement();
                        }
                    }
                    else
                    {
                        writer.WriteEndElement();
                    }
                    break;
                }
            }

            for (int i = 0; i < camlBuilder.UnclosedTags; i++)
            {
                writer.WriteEndElement();
            }

            writer.Close();
            return(sb.ToString());
        }