Пример #1
0
        public void ExampleCamlQueryEqValue()
        {
            var queryDef = new CamlQueryRoot {
                Where = new LogicalJoinDefinition {
                    And =
                    {
                        new ExtendedLogicalJoinDefinition {
                            Eq =
                            {
                                new LogicalTestDefinition {
                                    FieldRef = FieldRefDefinition.FromNames("State"),
                                    Value    = ValueDefinition.NewTextValues("Queensland")
                                }
                            }
                        }
                    }
                }
            };

            queryDef.Where.And.First().Eq.Add(new LogicalTestDefinition {
                FieldRef = FieldRefDefinition.FromNames("Country"),
                Value    = ValueDefinition.NewTextValues("Australia")
            });

            var andClauses = queryDef.Untyped.Descendants().Where(d => d.Name.LocalName == "And").ToList();

            var query = new Query(queryDef);

            var queryString          = query.ToString();
            var chameleonQueryString = queryDef.ToCamlString();

            Assert.IsTrue(queryString.IsNotEmpty());
            Assert.IsTrue(chameleonQueryString.IsNotEmpty());
        }
Пример #2
0
        /// <summary>
        /// Used to get the query root element containing the where condition.
        /// </summary>
        /// <param name="isLookupId">Explicitly specify whether the field referenced in the logical test query condition is a look up field.</param>
        /// <returns>The query root element containing a where condition.</returns>
        protected CamlQueryRoot GetCamlQueryRootForWhere(bool isLookupId)
        {
            CamlQueryRoot camlQuery = new CamlQueryRoot();

            // Construct a LogicalTestDefinition based on PTF Configure file.
            LogicalTestDefinition       logicalTest = new LogicalTestDefinition();
            FieldRefDefinitionQueryTest fieldRef    = new FieldRefDefinitionQueryTest();

            fieldRef.Name                 = Common.GetConfigurationPropertyValue("FieldRefWhere_Name", this.Site);
            logicalTest.FieldRef          = fieldRef;
            logicalTest.FieldRef.LookupId = isLookupId.ToString().ToUpper();
            ValueDefinition value = new ValueDefinition();

            value.Type        = Common.GetConfigurationPropertyValue("FieldRefWhere_Type", this.Site);
            value.Text        = new string[] { Common.GetConfigurationPropertyValue("FieldRefWhere_Text", this.Site) };
            logicalTest.Value = value;

            // Use Equal to construct a Where condition.
            camlQuery.Where = new LogicalJoinDefinition();
            camlQuery.Where.ItemsElementName = new ItemsChoiceType1[] { ItemsChoiceType1.Eq };
            camlQuery.Where.Items            = new LogicalTestDefinition[] { logicalTest };

            // Construct an OrderBy element.
            camlQuery.OrderBy                       = new OrderByDefinition();
            camlQuery.OrderBy.FieldRef              = new FieldRefDefinitionOrderBy[1];
            camlQuery.OrderBy.FieldRef[0]           = new FieldRefDefinitionOrderBy();
            camlQuery.OrderBy.FieldRef[0].Ascending = Common.GetConfigurationPropertyValue("FieldRefOrderBy_Ascending", this.Site);
            camlQuery.OrderBy.FieldRef[0].Name      = Common.GetConfigurationPropertyValue("FieldRefOrderBy_Name", this.Site);

            return(camlQuery);
        }
Пример #3
0
        /// <summary>
        /// Used to get the query of a view.
        /// </summary>
        /// <param name="query">Specify the type of Query.</param>
        /// <param name="isLookupId">Explicitly specify whether the field referenced in the logical test query condition is a look up field.</param>
        /// <returns>A constructed query root element.</returns>
        protected CamlQueryRoot GetCamlQueryRoot(Query query, bool isLookupId)
        {
            CamlQueryRoot camlQueryRoot = null;

            switch (query)
            {
            case Query.AvailableQueryInfo:
                camlQueryRoot = this.GetCamlQueryRootForWhere(isLookupId);
                break;

            case Query.EmptyQueryInfo:
                camlQueryRoot = new CamlQueryRoot();
                break;

            case Query.IsCollapse:
                camlQueryRoot = this.GetCamlQueryRootForGroupBy(true);
                break;

            case Query.IsNotCollapse:
                camlQueryRoot = this.GetCamlQueryRootForGroupBy(false);
                break;

            default:
                Site.Debug.Fail("Not supported Query type {0}", query.ToString());
                break;
            }

            return(camlQueryRoot);
        }
        public void TestPublicTypeConversion()
        {
            var logicalJoinDefXml     = "<LogicalJoinDefinition xmlns=\"http://schemas.microsoft.com/sharepoint/\"> <Or> <Eq> <FieldRef Name=\"FirstName\" /> </Eq> </Or> </LogicalJoinDefinition>";
            var logicalJoinDefElement = XElement.Parse(logicalJoinDefXml);

            LogicalJoinDefinition where = null;
            Assert.DoesNotThrow(() => {
                where = (LogicalJoinDefinition)logicalJoinDefElement;
                Assert.IsNotNull(where);
            });

            Assert.DoesNotThrow(() => {
                var newCamlQueryRoot = new CamlQueryRoot {
                    Where = @where
                };
                Assert.IsNotNull(newCamlQueryRoot.Where);
            });
        }
Пример #5
0
        /// <summary>
        /// Used to get the query with GroupBy and OrderBy condition.
        /// </summary>
        /// <param name="isCollapse">Indicate whether the result set is collapsed.</param>
        /// <returns>A constructed query with GroupBy and OrderBy condition.</returns>
        protected CamlQueryRoot GetCamlQueryRootForGroupBy(bool isCollapse)
        {
            CamlQueryRoot     camlQuery = new CamlQueryRoot();
            GroupByDefinition groupBy   = new GroupByDefinition();

            FieldRefDefinitionGroupBy fieldRefGroupBy = new FieldRefDefinitionGroupBy();

            fieldRefGroupBy.Ascending = Common.GetConfigurationPropertyValue("FieldRefGroupBy_Ascending", this.Site);
            fieldRefGroupBy.Name      = Common.GetConfigurationPropertyValue("FieldRefGroupBy_Name", this.Site);
            FieldRefDefinitionGroupBy[] fieldRefs = { fieldRefGroupBy };

            groupBy.FieldRef   = fieldRefs;
            groupBy.Collapse   = isCollapse.ToString();
            groupBy.GroupLimit = int.Parse(Common.GetConfigurationPropertyValue("FieldRefGroupBy_RowLimit", this.Site));

            camlQuery.GroupBy = groupBy;

            return(camlQuery);
        }
Пример #6
0
        /// <summary>
        /// Used to validate the available query information related requirements.
        /// </summary>
        /// <param name="queryRoot">The returned view query instance.</param>
        private void ValidateQuery(CamlQueryRoot queryRoot)
        {
            // If the query is not null, its schema has been validated before de-serialization; so the requirement MS-WSSCAML_R20 can be captured.
            if (queryRoot != null)
            {
                Site.CaptureRequirementIfIsTrue(
                    this.PassSchemaValidation,
                    "MS-WSSCAML",
                    20,
                    @"[In Schema] [The schema definition of CamlQueryRoot Type is as follows:]
                                                        <xs:complexType name=""CamlQueryRoot"">
                                                        <xs:all>
                                                        <xs:element name=""Where"" type=""LogicalJoinDefinition"" minOccurs=""0"" maxOccurs=""1"" />
                                                        <xs:element name=""OrderBy"" type=""OrderByDefinition"" minOccurs=""0"" maxOccurs=""1"" />
                                                        <xs:element name=""GroupBy"" type=""GroupByDefinition"" minOccurs=""0"" maxOccurs=""1"" />
                                                        <xs:element name=""WithIndex"" type=""LogicalWithIndexDefinition"" minOccurs=""0"" maxOccurs=""1"" />
                                                        </xs:all>
                                                        </xs:complexType>");

                if (queryRoot.OrderBy != null)
                {
                    // If ViewFields contains any element, its schema has been validated before de-serialization; so this requirement MS-WSSCAML_R56 can be captured.
                    Site.CaptureRequirementIfIsTrue(
                        this.PassSchemaValidation,
                        "MS-WSSCAML",
                        56,
                        @"[In Schema] [The schema definition of OrderByDefinition is as follows]  <xs:complexType name=""OrderByDefinition"">
                                                          <xs:sequence>
                                                          <xs:element name=""FieldRef"" type=""FieldRefDefinitionOrderBy"" minOccurs=""0"" maxOccurs=""unbounded"" />
                                                          </xs:sequence>
                                                          <xs:attribute name=""Override"" type=""TRUE_Case_Insensitive_Else_Anything"" use=""optional"" default=""FALSE""/>
                                                          </xs:complexType>");

                    if (queryRoot.OrderBy.FieldRef != null && queryRoot.OrderBy.FieldRef.Length > 0)
                    {
                        // If ViewFields contains any element, and its schema has been validated before de-serialization; so this requirement MS-WSSCAML_R59 can be captured.
                        Site.CaptureRequirementIfIsTrue(
                            this.PassSchemaValidation,
                            "MS-WSSCAML",
                            59,
                            @"[In Schema] [The schema definition of FieldRefDefinitionOrderBy is as follows:]<xs:complexType name=""FieldRefDefinitionOrderBy"">
                                                              <xs:attribute name=""ID"" type=""UniqueIdentifierWithOrWithoutBraces"" use=""optional"" />
                                                              <xs:attribute name=""Name"" type=""xs:string"" use=""optional"" />
                                                              <xs:attribute name=""Ascending"" type=""TRUE_Case_Insensitive_Else_Anything"" use=""optional"" default=""FALSE"" />
                                                              </xs:complexType>");

                        foreach (FieldRefDefinitionOrderBy fieldRef in queryRoot.OrderBy.FieldRef)
                        {
                            if (fieldRef.Ascending != null)
                            {
                                // If Ascending exists, and its schema has been validated before DE serializing So this requirement MS-WSSCAML_R1455 can be captured.
                                Site.CaptureRequirementIfIsTrue(
                                    this.PassSchemaValidation,
                                    "MS-WSSCAML",
                                    1455,
                                    @"[In TRUE_Case_Insensitive_Else_Anything] This type is defined as follows:
                                                                              <xs:simpleType name=""TRUE_Case_Insensitive_Else_Anything"">
                                                                                <xs:restriction base=""xs:string"">
                                                                                  <xs:pattern value=""([Tt][Rr][Uu][Ee])|.*"" />
                                                                                </xs:restriction>
                                                                              </xs:simpleType>");
                            }
                        }
                    }
                }

                // If the Where element is not null, its schema type LogicalJoinDefinition has been validated before de-serialization; so this requirement MS-WSSCAML_R24 can be captured.
                if (queryRoot.Where != null)
                {
                    Site.CaptureRequirementIfIsTrue(
                        this.PassSchemaValidation,
                        "MS-WSSCAML",
                        24,
                        @"[In Schema] [The schema definition of LogicalJoinDefinition type is as follows:] <xs:complexType name=""LogicalJoinDefinition"">
                                                                                              <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
                                                                                              <xs:element name=""And"" type=""ExtendedLogicalJoinDefinition"" />
                                                                                              <xs:element name=""BeginsWith"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""Contains"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""DateRangesOverlap"" type=""LogicalTestDefinitionDateRange"" />
                                                                                              <xs:element name=""Eq"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""Geq"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""Gt"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""In"" type=""LogicalTestInValuesDefinition"" />
                                                                                              <xs:element name=""Includes"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""IsNotNull"" type=""LogicalNullDefinition"" />
                                                                                              <xs:element name=""IsNull"" type=""LogicalNullDefinition"" />
                                                                                              <xs:element name=""Leq"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""Lt"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""Membership"" type=""MembershipDefinition"" />
                                                                                              <xs:element name=""Neq"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""NotIncludes"" type=""LogicalTestDefinition"" />
                                                                                              <xs:element name=""Or"" type=""ExtendedLogicalJoinDefinition"" />
                                                                                              </xs:choice>
                                                                                              </xs:complexType>");
                    switch (queryRoot.Where.ItemsElementName[0])
                    {
                        case ItemsChoiceType1.Contains:
                        case ItemsChoiceType1.BeginsWith:
                        case ItemsChoiceType1.Eq:
                        case ItemsChoiceType1.Geq:
                        case ItemsChoiceType1.Gt:
                        case ItemsChoiceType1.Includes:
                        case ItemsChoiceType1.NotIncludes:
                        case ItemsChoiceType1.Leq:
                        case ItemsChoiceType1.Lt:
                        case ItemsChoiceType1.Neq:

                            // If the Where element exists and used one of the above comparing signs that is defined by the LogicalTestDefinition complex type and the schema of the comparing sign has been validated before de-serialization, the requirement MS-WSSCAML_R79 can be captured.
                            Site.CaptureRequirementIfIsTrue(
                                this.PassSchemaValidation,
                                "MS-WSSCAML",
                                79,
                                @"[In Schema] [The schema definition of LogicalTestDefinition is as follows:] 
                                             <xs:complexType name=""LogicalTestDefinition"">
                                                <xs:all>
                                                  <xs:element name=""FieldRef"" type=""FieldRefDefinitionQueryTest"" minOccurs=""1"" maxOccurs=""1"" />
                                                  <xs:element name=""Value"" type=""ValueDefinition"" minOccurs=""1"" maxOccurs=""1"" />
                                                </xs:all>
                                              </xs:complexType>");

                            // Since the Value element is required to exist by its schema definition (see the above MS-WSSCAML_R79),  and its schema has been validated before de-serialization; so this requirement MS-WSSCAML_R82 can be captured.
                            Site.CaptureRequirementIfIsTrue(
                                 this.PassSchemaValidation,
                                 "MS-WSSCAML",
                                 82,
                                 @"[In Schema] [The schema definition of ValueDefinition is as follows:]
                                                        <xs:complexType name=""ValueDefinition"" mixed=""true"">
                                                        <xs:sequence>
                                                        <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
                                                        <xs:any namespace=""##any"" processContents=""skip"" />
                                                        </xs:choice>
                                                        </xs:sequence>
                                                        <xs:attribute name=""Type"" type=""xs:string"" use=""optional"" />
                                                        </xs:complexType>");

                            // Since FieldRef is required to exist by its schema definition (see the above MS-WSSCAML_R79), and its schema has been validated before de-serialization; so this requirement MS-WSSCAML_R87 can be captured.
                            Site.CaptureRequirementIfIsTrue(
                                 this.PassSchemaValidation,
                                 "MS-WSSCAML",
                                 87,
                                 @"[In Schema] [The schema definition of FieldRefDefinitionQueryTest is as follows:] 
                                                        <xs:complexType name=""FieldRefDefinitionQueryTest"">
                                                        <xs:attribute name=""ID"" type="" UniqueIdentifierWithOrWithoutBraces"" use=""optional"" />
                                                        <xs:attribute name=""Name"" type=""xs:string"" use=""optional"" />
                                                        <xs:attribute name=""LookupId"" type=""TRUE_Case_Insensitive_Else_Anything"" use=""optional"" default=""FALSE"" />
                                                        </xs:complexType>");
                            break;
                        case ItemsChoiceType1.And:
                        case ItemsChoiceType1.Or:
                        case ItemsChoiceType1.In:
                        case ItemsChoiceType1.IsNull:
                        case ItemsChoiceType1.IsNotNull:
                        case ItemsChoiceType1.Membership:
                        case ItemsChoiceType1.DateRangesOverlap:
                            break;
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Used to get the query of a view.
        /// </summary>
        /// <param name="query">Specify the type of Query.</param>
        /// <param name="isLookupId">Explicitly specify whether the field referenced in the logical test query condition is a look up field.</param>
        /// <returns>A constructed query root element.</returns>
        protected CamlQueryRoot GetCamlQueryRoot(Query query, bool isLookupId)
        {
            CamlQueryRoot camlQueryRoot = null;
            switch (query)
            {
                case Query.AvailableQueryInfo:
                    camlQueryRoot = this.GetCamlQueryRootForWhere(isLookupId);
                    break;

                case Query.EmptyQueryInfo:
                    camlQueryRoot = new CamlQueryRoot();
                    break;

                case Query.IsCollapse:
                    camlQueryRoot = this.GetCamlQueryRootForGroupBy(true);
                    break;

                case Query.IsNotCollapse:
                    camlQueryRoot = this.GetCamlQueryRootForGroupBy(false);
                    break;

                default:
                    Site.Debug.Fail("Not supported Query type {0}", query.ToString());
                    break;
            }

            return camlQueryRoot;
        }
Пример #8
0
        /// <summary>
        /// Used to get the query with GroupBy and OrderBy condition.
        /// </summary>
        /// <param name="isCollapse">Indicate whether the result set is collapsed.</param>
        /// <returns>A constructed query with GroupBy and OrderBy condition.</returns>
        protected CamlQueryRoot GetCamlQueryRootForGroupBy(bool isCollapse)
        {
            CamlQueryRoot camlQuery = new CamlQueryRoot();
            GroupByDefinition groupBy = new GroupByDefinition();

            FieldRefDefinitionGroupBy fieldRefGroupBy = new FieldRefDefinitionGroupBy();
            fieldRefGroupBy.Ascending = Common.GetConfigurationPropertyValue("FieldRefGroupBy_Ascending", this.Site);
            fieldRefGroupBy.Name = Common.GetConfigurationPropertyValue("FieldRefGroupBy_Name", this.Site);
            FieldRefDefinitionGroupBy[] fieldRefs = { fieldRefGroupBy };

            groupBy.FieldRef = fieldRefs;
            groupBy.Collapse = isCollapse.ToString();
            groupBy.GroupLimit = int.Parse(Common.GetConfigurationPropertyValue("FieldRefGroupBy_RowLimit", this.Site));

            camlQuery.GroupBy = groupBy;

            return camlQuery;
        }
Пример #9
0
        /// <summary>
        /// Used to get the query root element containing the where condition.
        /// </summary>
        /// <param name="isLookupId">Explicitly specify whether the field referenced in the logical test query condition is a look up field.</param>
        /// <returns>The query root element containing a where condition.</returns>
        protected CamlQueryRoot GetCamlQueryRootForWhere(bool isLookupId)
        {
            CamlQueryRoot camlQuery = new CamlQueryRoot();

            // Construct a LogicalTestDefinition based on PTF Configure file.
            LogicalTestDefinition logicalTest = new LogicalTestDefinition();
            FieldRefDefinitionQueryTest fieldRef = new FieldRefDefinitionQueryTest();
            fieldRef.Name = Common.GetConfigurationPropertyValue("FieldRefWhere_Name", this.Site);
            logicalTest.FieldRef = fieldRef;
            logicalTest.FieldRef.LookupId = isLookupId.ToString().ToUpper();
            ValueDefinition value = new ValueDefinition();
            value.Type = Common.GetConfigurationPropertyValue("FieldRefWhere_Type", this.Site);
            value.Text = new string[] { Common.GetConfigurationPropertyValue("FieldRefWhere_Text", this.Site) };
            logicalTest.Value = value;

            // Use Equal to construct a Where condition.
            camlQuery.Where = new LogicalJoinDefinition();
            camlQuery.Where.ItemsElementName = new ItemsChoiceType1[] { ItemsChoiceType1.Eq };
            camlQuery.Where.Items = new LogicalTestDefinition[] { logicalTest };

            // Construct an OrderBy element.
            camlQuery.OrderBy = new OrderByDefinition();
            camlQuery.OrderBy.FieldRef = new FieldRefDefinitionOrderBy[1];
            camlQuery.OrderBy.FieldRef[0] = new FieldRefDefinitionOrderBy();
            camlQuery.OrderBy.FieldRef[0].Ascending = Common.GetConfigurationPropertyValue("FieldRefOrderBy_Ascending", this.Site);
            camlQuery.OrderBy.FieldRef[0].Name = Common.GetConfigurationPropertyValue("FieldRefOrderBy_Name", this.Site);

            return camlQuery;
        }