コード例 #1
0
        public QueryProperty FindPropertyByText(QueryProperty testProperty, DbPropertyType direction, IList <QueryProperty> propertyList)
        {
            // Remove the alias if it exists at the end since the name of the
            // alias might have changed.

            if (string.IsNullOrEmpty(testProperty.Text)) //thro
            {
                return(null);
            }

            string testText = Regex.Replace(testProperty.Text, string.Format(@"\s+{0}$", testProperty.Name), string.Empty);

            IEnumerable <QueryProperty> foundProperties =
                from QueryProperty property in propertyList
                where !string.IsNullOrEmpty(property.Text) && Regex.Replace(property.Text, string.Format(@"\s+{0}$", property.Name), string.Empty) == testText &&
                property.PropertyType == direction
                select property;

            if (foundProperties.Count() > 0)
            {
                return(foundProperties.First());
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public static bool IsMultiValue(this QueryProperty property)
        {
            ExceptionUtilities.CheckArgumentNotNull(property, "property");
            var bagType = property.PropertyType as QueryCollectionType;

            return((bagType != null) && (bagType.ElementType is QueryScalarType || bagType.ElementType is QueryComplexType));
        }
コード例 #3
0
        private void ComparePrimitiveBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable <NamedValue> namedValues)
        {
            int i = 0;

            var collection = instance.GetCollectionValue(memberProperty.Name);

            if (!this.WriteErrorIfNull(propertyPath, collection))
            {
                List <NamedValue> primitiveItemNamedValues = namedValues.Where(pp => pp.Name == propertyPath + "." + i).ToList();
                while (primitiveItemNamedValues.Any())
                {
                    if (i < collection.Elements.Count)
                    {
                        var scalarQueryValue = collection.Elements[i] as QueryScalarValue;
                        ExceptionUtilities.Assert(primitiveItemNamedValues.Count() < 2, "Should not get more than one value for a primitive Bag item for path '{0}'", propertyPath + "." + i);
                        var value = primitiveItemNamedValues.Single();
                        this.WriteErrorIfNotEqual(propertyPath, value.Value, scalarQueryValue);
                        this.unusedNamedValuePaths.Remove(value.Name);
                    }

                    i++;
                    primitiveItemNamedValues = namedValues.Where(pp => pp.Name == propertyPath + "." + i).ToList();
                }

                this.WriteErrorIfNotEqual(propertyPath, collection.Elements.Count, i, "The number of expected items '{0}' does not match the actual '{1}' for propertyPath {2}", collection.Elements.Count, i, propertyPath);
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates new members on a structural type
        /// </summary>
        /// <param name="library">Type library</param>
        /// <param name="result">Structural Type to add members to</param>
        /// <param name="properties">Properties of the Structural Type member</param>
        /// <param name="pathToProperty">Path to the Property</param>
        protected void CreateMembers(QueryTypeLibrary library, QueryStructuralType result, IEnumerable <MemberProperty> properties, PathToProperty pathToProperty)
        {
            // TODO: Some Taupo framework pieces skip over StreamDataType properties
            foreach (var prop in properties.Where(p => !(p.PropertyType is StreamDataType)))
            {
                QueryProperty queryProperty = null;
                pathToProperty.PathStackWithinEntityType.Add(prop.Name);

                var pdt = prop.PropertyType as PrimitiveDataType;
                var cdt = prop.PropertyType as ComplexDataType;
                if (pdt != null)
                {
                    QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, pdt);
                    queryProperty = QueryProperty.Create(prop.Name, queryPropertyType);
                }
                else if (cdt != null)
                {
                    ComplexType      ct = cdt.Definition;
                    QueryComplexType queryComplexType = this.CreateStubComplexType(ct);
                    this.CreateMembers(library, queryComplexType, ct.Properties, pathToProperty);
                    library.SetQueryComplexType(ct, queryComplexType);
                    queryProperty = QueryProperty.Create(prop.Name, queryComplexType);
                }
                else
                {
                    queryProperty = this.CreateNonentityCollectionMember(library, result, prop, pathToProperty);
                }

                pathToProperty.PathStackWithinEntityType.RemoveAt(pathToProperty.PathStackWithinEntityType.Count - 1);

                queryProperty.SetPrimaryKey(prop.IsPrimaryKey);
                result.Add(queryProperty);
            }
        }
コード例 #5
0
        public static QueryProperty Between <T>(this QueryProperty property, T min, T max)
        {
            AddExpression(property, "$gte", min.ToString());
            AddExpression(property, "$lte", max.ToString());

            return(property);
        }
コード例 #6
0
        /// <summary>
        /// Factory method to create the <see cref="QueryPropertyExpression"/>.
        /// </summary>
        /// <param name="instance">Instance expression.</param>
        /// <param name="queryProperty">The property.</param>
        /// <returns>The <see cref="QueryPropertyExpression"/> with the provided instance, name and type.</returns>
        public static QueryExpression Property(this QueryExpression instance, QueryProperty queryProperty)
        {
            ExceptionUtilities.CheckArgumentNotNull(instance, "instance");
            ExceptionUtilities.CheckArgumentNotNull(queryProperty, "queryProperty");

            return(instance.Property(queryProperty.Name));
        }
コード例 #7
0
        /// <summary>
        /// Creates a QueryProperty for a property that is a non entity Collection
        /// </summary>
        /// <param name="library">Library Query Type</param>
        /// <param name="result">resulting Query Structural Type</param>
        /// <param name="collectionProperty">Member to calculate</param>
        /// <param name="pathToProperty">Path to the Property</param>
        /// <returns>A Query Property of the collectionType</returns>
        protected override QueryProperty CreateNonentityCollectionMember(QueryTypeLibrary library, QueryStructuralType result, MemberProperty collectionProperty, PathToProperty pathToProperty)
        {
            ExceptionUtilities.CheckArgumentNotNull(collectionProperty, "collectionProperty");

            var collectionType = collectionProperty.PropertyType as CollectionDataType;

            ExceptionUtilities.Assert(collectionType != null, "This type of property is not supported.");
            var collectionPrimitiveElementType      = collectionType.ElementDataType as PrimitiveDataType;
            var collectionComplexElementType        = collectionType.ElementDataType as ComplexDataType;
            QueryCollectionType queryCollectionType = null;

            if (collectionPrimitiveElementType != null)
            {
                QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, collectionPrimitiveElementType);
                queryCollectionType = queryPropertyType.CreateCollectionType();
            }
            else
            {
                ExceptionUtilities.Assert(collectionComplexElementType != null, "This type of property is not supported.");
                QueryComplexType queryComplexType = this.CreateStubComplexType(collectionComplexElementType.Definition);
                CreateMembers(library, queryComplexType, collectionComplexElementType.Definition.Properties, pathToProperty);
                queryCollectionType = queryComplexType.CreateCollectionType();
            }

            return(QueryProperty.Create(collectionProperty.Name, queryCollectionType));
        }
コード例 #8
0
        public override QueryEntityRelationCondition toObject(JsonObject jsonObject)
        {
            // this is limited in that it allows only String values;
            // that is sufficient for current use case with task filters
            // but could be extended by a data type in the future
            string scalarValue = null;

            if (jsonObject.has(SCALAR_VALUE))
            {
                scalarValue = JsonUtil.getString(jsonObject, SCALAR_VALUE);
            }

            QueryProperty baseProperty = null;

            if (jsonObject.has(BASE_PROPERTY))
            {
                baseProperty = new QueryPropertyImpl(JsonUtil.getString(jsonObject, BASE_PROPERTY));
            }

            QueryProperty comparisonProperty = null;

            if (jsonObject.has(COMPARISON_PROPERTY))
            {
                comparisonProperty = new QueryPropertyImpl(JsonUtil.getString(jsonObject, COMPARISON_PROPERTY));
            }

            return(new QueryEntityRelationCondition(baseProperty, comparisonProperty, scalarValue));
        }
コード例 #9
0
        private void UpdateBagPropertyWithNullOrEmpty(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable <NamedValue> namedValues)
        {
            List <NamedValue> exactMatches = namedValues.Where(nv => nv.Name == propertyPath).ToList();

            if (!exactMatches.Any())
            {
                return;
            }

            ExceptionUtilities.Assert(exactMatches.Count == 1, "Should only find at most one property path {0} when looking for null or empty value", propertyPath);

            NamedValue expectedBagValue = exactMatches.Single();
            var        bagType          = memberProperty.PropertyType as QueryCollectionType;

            if (expectedBagValue.Value == null)
            {
                instance.SetValue(memberProperty.Name, bagType.NullValue);
                this.unusedNamedValuePaths.Remove(expectedBagValue.Name);
            }
            else if (expectedBagValue.Value == EmptyData.Value)
            {
                QueryCollectionValue value = bagType.CreateCollectionWithValues(new QueryValue[] { });
                instance.SetValue(memberProperty.Name, value);
                this.unusedNamedValuePaths.Remove(expectedBagValue.Name);
            }
        }
コード例 #10
0
        private QueryProperty GetProperty([NotNull] Expression expression, [NotNull] Context context)
        {
            Guard.Argument(expression).NotNull();
            Guard.Argument(context).NotNull();
            var member = expression as MemberExpression;

            if (member == null)
            {
                throw new NotSupportedException();
            }

            QueryProperty property = null;

            if (member.Expression is MemberExpression child)
            {
                property = GetProperty(child, context);
                if (property.Properties.All(x => x.Alias != member.Member.Name))
                {
                    property.AddProperty(member.Member.Name);
                }
            }
            else
            {
                if (context.Properties.ContainsKey(member.Member.Name))
                {
                    return(context.Properties[member.Member.Name]);
                }

                property = new QueryProperty(member.Member.Name);
            }

            return(property);
        }
コード例 #11
0
 public override int InsertLoanQuickQuery(QueryProperty objQuickQuery, out string errMsg)
 {
     errMsg          = "";
     _objDataWrapper = new DbWrapper(Common.CnnString, CommandType.StoredProcedure);
     try
     {
         _objDataWrapper.AddParameter("@UserEmailId", objQuickQuery.UserEmailId);
         _objDataWrapper.AddParameter("@UserName", objQuickQuery.StudentName);
         _objDataWrapper.AddParameter("@UserMobile", objQuickQuery.UserMobileNo);
         _objDataWrapper.AddParameter("@UserPasseord", _objCrypto.Encrypt(objQuickQuery.UserMobileNo));
         _objDataWrapper.AddParameter("@UserCity", objQuickQuery.StudentCityName);
         _objDataWrapper.AddParameter("@UserQuerySourceTypeId", QueryType.Loan);
         _objDataWrapper.AddParameter("@UserCourseId", objQuickQuery.StudentCourseId);
         _objDataWrapper.AddParameter("@UserQuery", objQuickQuery.StudentQuery);
         var ObjerrMsg =
             (SqlParameter)(_objDataWrapper.AddParameter("@ErrMsg", "", SqlDbType.VarChar, ParameterDirection.Output, 128));
         _i = _objDataWrapper.ExecuteNonQuery("Aj_Proc_InsertUserQuery");
         if (ObjerrMsg != null && ObjerrMsg.Value != null)
         {
             errMsg = Convert.ToString(ObjerrMsg.Value);
         }
     }
     catch (Exception ex)
     {
         var err = ex.Message;
         if (ex.InnerException != null)
         {
             err = err + " :: Inner Exception :- " + ex.ToString();
         }
         const string addInfo = "Error while executing InsertLoanQuickQuery in Query.cs  :: -> ";
         var          objPub  = new ClsExceptionPublisher();
         objPub.Publish(err, addInfo);
     }
     return(_i);
 }
コード例 #12
0
        public QueryProperty SaveOrUpdateMerge(QueryProperty property)
        {
            object mergedObj = Session.Merge(property);

            HibernateTemplate.SaveOrUpdate(property);
            return((QueryProperty)mergedObj);
        }
コード例 #13
0
 public override int UpdateQueryReplyStatus(QueryProperty objQuickQuery, out string errMsg)
 {
     errMsg          = "";
     _objDataWrapper = new DbWrapper(Common.CnnString, CommandType.StoredProcedure);
     try
     {
         _objDataWrapper.AddParameter("@UserId", objQuickQuery.UserId);
         _objDataWrapper.AddParameter("@QueryId", objQuickQuery.StudentQueryId);
         _objDataWrapper.AddParameter("@ReplyStatus", objQuickQuery.ReplyStatus);
         var ObjerrMsg =
             (SqlParameter)(_objDataWrapper.AddParameter("@ErrMsg", "", SqlDbType.VarChar, ParameterDirection.Output, 128));
         _i = _objDataWrapper.ExecuteNonQuery("Aj_Proc_UpdateQyeryStatus");
         if (ObjerrMsg != null && ObjerrMsg.Value != null)
         {
             errMsg = Convert.ToString(ObjerrMsg.Value);
         }
     }
     catch (Exception ex)
     {
         var err = ex.Message;
         if (ex.InnerException != null)
         {
             err = err + " :: Inner Exception :- " + ex.ToString();
         }
         const string addInfo = "Error while executing UpdateQueryReplyStatus in Query.cs  :: -> ";
         var          objPub  = new ClsExceptionPublisher();
         objPub.Publish(err, addInfo);
     }
     return(_i);
 }
コード例 #14
0
        private void CreateNavigationMembers(QueryTypeLibrary library, QueryEntityType result, IEnumerable <NavigationProperty> navigationProperties, EntityContainer container)
        {
            foreach (var navprop in navigationProperties)
            {
                // handle MEST scenario where there are multiple association sets corresponding to a navigation property
                var asets = container.AssociationSets.Where(c => c.AssociationType == navprop.Association);
                var aset  = asets.Single(set => set.Ends.Any(end => end.AssociationEnd == navprop.FromAssociationEnd && end.EntitySet == result.EntitySet));

                var toSet            = aset.Ends.Single(e => e.AssociationEnd == navprop.ToAssociationEnd).EntitySet;
                var targetEntityType = library.GetQueryEntityType(toSet, navprop.ToAssociationEnd.EntityType);

                QueryProperty property;

                if (navprop.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
                {
                    // collection property
                    property = QueryProperty.Create(navprop.Name, targetEntityType.CreateCollectionType());
                }
                else
                {
                    // reference property
                    property = QueryProperty.Create(navprop.Name, targetEntityType);
                }

                result.Add(property);
            }
        }
コード例 #15
0
ファイル: Property.cs プロジェクト: sharpezoid/CardyBoi
 public Property(string _Name, int _Value, QueryProperty _Activation, int _ActivationValue)
 {
     Name            = _Name;
     Value           = _Value;
     Activation      = _Activation;
     ActivationValue = _ActivationValue;
 }
コード例 #16
0
        public virtual JsonObject toJsonObject(QueryOrderingProperty property)
        {
            JsonObject jsonObject = JsonUtil.createObject();

            JsonUtil.addField(jsonObject, RELATION, property.Relation);

            QueryProperty queryProperty = property.QueryProperty;

            if (queryProperty != null)
            {
                JsonUtil.addField(jsonObject, QUERY_PROPERTY, queryProperty.Name);
                JsonUtil.addField(jsonObject, QUERY_PROPERTY_FUNCTION, queryProperty.Function);
            }

            Direction direction = property.Direction;

            if (direction != null)
            {
                JsonUtil.addField(jsonObject, DIRECTION, direction.Name);
            }

            if (property.hasRelationConditions())
            {
                JsonArray relationConditionsJson = JsonQueryFilteringPropertyConverter.ARRAY_CONVERTER.toJsonArray(property.RelationConditions);
                JsonUtil.addField(jsonObject, RELATION_CONDITIONS, relationConditionsJson);
            }

            return(jsonObject);
        }
コード例 #17
0
        public static QueryProperty Mod(this QueryProperty property, int num, int denom)
        {
            var expression = string.Format("[{0},{1}]", num, denom);

            property.AddOperator(new QueryOperator("$mod", expression));

            return property;
        }
コード例 #18
0
        private static QueryProperty Exists(QueryProperty property, bool exists)
        {
            var expression = exists.ToString().ToLower(); //QueryOperator.ConvertOperandToJson(exists);

            property.AddOperator(new QueryOperator("$exists", expression));

            return property;
        }
コード例 #19
0
        private static QueryProperty Exists(QueryProperty property, bool exists)
        {
            var expression = exists.ToString().ToLower(); //QueryOperator.ConvertOperandToJson(exists);

            property.AddOperator(new QueryOperator("$exists", expression));

            return(property);
        }
コード例 #20
0
 public QueryProperty Save(QueryProperty property)
 {
     if (property.Id == Guid.Empty)
     {
         property.Id = Guid.NewGuid();
     }
     HibernateTemplate.Save(property);
     return(property);
 }
コード例 #21
0
        public static QueryProperty NotEq <T>(this QueryProperty property, T operand)
        {
            AddExpression(property, "$ne", QueryOperator.ConvertOperandToJson <T>(operand).ToString());
            //AddExpression(property, "$ne",
            //    operand is string ?
            //        string.Format("'{0}'", operand) :
            //        operand.ToString());

            return(property);
        }
コード例 #22
0
        /// <summary>
        /// Resolves types for the specified expression.
        /// </summary>
        /// <param name="expression">The expression to resolve types for.</param>
        /// <returns>Expression with resolved types.</returns>
        public QueryExpression Visit(LinqNewExpression expression)
        {
            var members = expression.Members.Select(this.ResolveTypes).ToList();
            var type    = new QueryAnonymousStructuralType(this.EvaluationStrategy);

            for (int i = 0; i < members.Count; i++)
            {
                type.Add(QueryProperty.Create(expression.MemberNames[i], members[i].ExpressionType));
            }

            return(LinqBuilder.New(expression.MemberNames, members, type));
        }
コード例 #23
0
        private void SetCollectionProperty(QueryStructuralValue instance, QueryProperty memberProperty, List <QueryValue> collectionElements)
        {
            QueryCollectionValue queryCollectionValue = instance.GetCollectionValue(memberProperty.Name);

            queryCollectionValue.Elements.Clear();
            foreach (QueryValue queryValue in collectionElements)
            {
                queryCollectionValue.Elements.Add(queryValue);
            }

            instance.SetValue(memberProperty.Name, queryCollectionValue);
        }
コード例 #24
0
 public bool AreQueryPropertiesTheSame(QueryProperty firstProp, QueryProperty secondProp)
 {
     return
         (
         (firstProp.DbDatatype == secondProp.DbDatatype) &&
         (firstProp.Length == secondProp.Length) &&
         (firstProp.Precision == secondProp.Precision) &&
         (firstProp.Scale == secondProp.Scale) &&
         (firstProp.OriginalColumn == secondProp.OriginalColumn) &&
         (firstProp.OriginalTable == secondProp.OriginalTable) &&
         (firstProp.Sequence == secondProp.Sequence)
         );
 }
コード例 #25
0
        private void UpdateBagProperty(QueryStructuralValue instance, QueryProperty memberProperty, QueryType elementType, string propertyPath, IEnumerable <NamedValue> namedValues)
        {
            var scalarElementDataType      = elementType as QueryScalarType;
            var complexTypeElementDataType = elementType as QueryComplexType;

            if (scalarElementDataType != null)
            {
                this.UpdateScalarBag(instance, memberProperty, propertyPath, namedValues, scalarElementDataType);
            }
            else
            {
                ExceptionUtilities.CheckObjectNotNull(complexTypeElementDataType, "PropertyPath '{0}' is an invalid type '{1}'", propertyPath, memberProperty.PropertyType);

                this.UpdateComplexBag(instance, memberProperty, propertyPath, namedValues, complexTypeElementDataType);
            }
        }
コード例 #26
0
        // Method to bind the QueryList
        private List <QueryProperty> BindQueryObjectList(DataTable datatable)
        {
            List <QueryProperty> listQueryProperty = new List <QueryProperty>();

            try
            {
                if (datatable != null && datatable.Rows.Count > 0)
                {
                    for (int i = 0; i < datatable.Rows.Count; i++)
                    {
                        var objQueryProperty = new QueryProperty
                        {
                            UserId            = Convert.ToInt32(datatable.Rows[i]["AjUserId"]),
                            UserMobileNo      = Convert.ToString(datatable.Rows[i]["AjUserMobile"]),
                            UserEmailId       = Convert.ToString(datatable.Rows[i]["AjUserEmail"]),
                            StudentSourceId   = Convert.ToInt32(datatable.Rows[i]["SourceId"]),
                            StudentCourseId   = Convert.ToInt32(datatable.Rows[i]["AjCourseId"]),
                            StudentCourseName = Convert.ToString(datatable.Rows[i]["CourseName"]),
                            StudentName       = Convert.ToString(datatable.Rows[i]["AjUserFullName"]),
                            StudentQuery      = Convert.ToString(datatable.Rows[i]["AjStudentQueryText"]),
                            SourceTypeName    = Convert.ToString(datatable.Rows[i]["Source"]),
                            StudentQueryId    = Convert.ToString(datatable.Rows[i]["AjStudentQueryId"]),
                            StudentCityName   = Convert.ToString(datatable.Rows[i]["AjCityName"]),
                            SourceName        = Convert.ToString(datatable.Rows[i]["SourceName"]),
                            ReplyStatus       = Convert.ToBoolean(datatable.Rows[i]["AjStudentQueryReplyStatus"]),
                            QueryReply        = datatable.Columns.Contains("AjQueryReply") == true ? ((datatable.Rows[i]["AjQueryReply"] is DBNull) ? null : Convert.ToString(datatable.Rows[i]["AjQueryReply"])) : null,
                            CreatedOn         = Convert.ToDateTime(datatable.Rows[i]["CreatedOn"]),
                            QueryStatus       = datatable.Columns.Contains("AjQueryStatus") == true ? ((datatable.Rows[i]["AjQueryStatus"] is DBNull) ? false : Convert.ToBoolean(datatable.Rows[i]["AjQueryStatus"])) : false,
                        };
                        listQueryProperty.Add(objQueryProperty);
                    }
                }
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                if (ex.InnerException != null)
                {
                    err = err + " :: Inner Exception :- " + ex.ToString();
                }
                const string addInfo = "Error while executing BindQueryObjectList in Query.cs  :: -> ";
                var          objPub  = new ClsExceptionPublisher();
                objPub.Publish(err, addInfo);
            }
            return(listQueryProperty);
        }
コード例 #27
0
        public static bool IsMultiValue(this QueryProperty property, MultiValueType specificType)
        {
            ExceptionUtilities.CheckArgumentNotNull(property, "property");

            var propertyBagType = property.PropertyType as QueryCollectionType;

            if (propertyBagType != null && specificType == MultiValueType.Primitive && propertyBagType.ElementType is QueryScalarType)
            {
                return(true);
            }
            else if (propertyBagType != null && specificType == MultiValueType.Complex && propertyBagType.ElementType is QueryComplexType)
            {
                return(true);
            }

            return(false);
        }
コード例 #28
0
        private void BuildStructuralPropertiesQueryValue(QueryStructuralValue instance, string propertyPath, IList <MemberProperty> properties, IList <QueryProperty> queryProperties, EntitySetDataRow row)
        {
            ExceptionUtilities.Assert(properties.Count == queryProperties.Count, "QueryProperties '{0}' and MemberProperties '{1}' are not the same number!", CreateQueryPropertyList(queryProperties), CreateMemberPropertyList(properties));

            // TODO: Some Taupo framework pieces skip over StreamDataType properties
            foreach (MemberProperty childProperty in properties.Where(p => !(p.PropertyType is StreamDataType)))
            {
                string childPropertyPath = propertyPath + childProperty.Name;
                List <QueryProperty> childQueryProperties = queryProperties.Where(p => p.Name == childProperty.Name).ToList();
                ExceptionUtilities.Assert(childQueryProperties.Count == 1, "Could not find query property based on MemberProperty Name '{0}' in list of query properties '{1}'", childProperty.Name, CreateQueryPropertyList(childQueryProperties));

                QueryProperty childQueryProperty = childQueryProperties.First();

                QueryCollectionType childCollectionDataType = childQueryProperty.PropertyType as QueryCollectionType;
                QueryScalarType     childScalarType         = childQueryProperty.PropertyType as QueryScalarType;
                QueryComplexType    childComplexType        = childQueryProperty.PropertyType as QueryComplexType;

                if (childCollectionDataType != null)
                {
                    instance.SetValue(childProperty.Name, this.BuildCollectionQueryValue(childPropertyPath + ".", childCollectionDataType, row));
                }
                else if (childScalarType != null)
                {
                    var value      = row[childPropertyPath];
                    var queryValue = childScalarType.CreateValue(value);
                    instance.SetValue(childQueryProperty.Name, queryValue);
                }
                else
                {
                    ExceptionUtilities.CheckObjectNotNull(childComplexType, "Unknown type '{0}'", childProperty.PropertyType);

                    // If a complex type instance is null in the datarow, we will create a QueryStructuralValue indicating null and set it on the instance.
                    if (row.PropertyPaths.Contains(childPropertyPath) && row[childPropertyPath] == null)
                    {
                        instance.SetValue(childProperty.Name, new QueryStructuralValue(childComplexType, true, null, childComplexType.EvaluationStrategy));
                    }
                    else
                    {
                        QueryStructuralValue childInstance = childComplexType.CreateNewInstance();
                        this.BuildStructuralPropertiesQueryValue(childInstance, childPropertyPath + ".", childComplexType.ComplexType.Properties, childComplexType.Properties, row);
                        instance.SetValue(childProperty.Name, childInstance);
                    }
                }
            }
        }
コード例 #29
0
        private void AddToSQLInputList(QueryProperty qp)
        {
            ListViewItem item = lvInput.Items.Add(qp.Sequence.ToString());

            item.SubItems.Add(qp.Name);

            if (String.IsNullOrEmpty(qp.OriginalTable))
            {
                item.SubItems.Add("");
            }
            else
            {
                item.SubItems.Add(qp.OriginalTable + "." + qp.OriginalColumn);
            }

            item.SubItems.Add(qp.Text);
            item.Tag = qp;
        }
コード例 #30
0
        public virtual JsonObject toJsonObject(QueryEntityRelationCondition filteringProperty)
        {
            JsonObject jsonObject = JsonUtil.createObject();

            JsonUtil.addField(jsonObject, BASE_PROPERTY, filteringProperty.Property.Name);

            QueryProperty comparisonProperty = filteringProperty.ComparisonProperty;

            if (comparisonProperty != null)
            {
                JsonUtil.addField(jsonObject, COMPARISON_PROPERTY, comparisonProperty.Name);
            }

            object scalarValue = filteringProperty.ScalarValue;

            if (scalarValue != null)
            {
                JsonUtil.addFieldRawValue(jsonObject, SCALAR_VALUE, scalarValue);
            }

            return(jsonObject);
        }
コード例 #31
0
        private void UpdateComplexBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable <NamedValue> namedValues, QueryComplexType complexTypeElementDataType)
        {
            int i = 0;

            var complexCollection = new List <QueryValue>();
            List <NamedValue> complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();

            while (complexInstanceNamedValues.Any())
            {
                QueryStructuralValue complexValue = complexTypeElementDataType.CreateNewInstance();
                this.UpdateValues(complexValue, complexInstanceNamedValues, propertyPath + "." + i);
                complexCollection.Add(complexValue);

                i++;
                complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
            }

            if (complexCollection.Any())
            {
                this.SetCollectionProperty(instance, memberProperty, complexCollection);
            }
        }
コード例 #32
0
        private void UpdateBagPropertyWithNullOrEmpty(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues)
        {
            List<NamedValue> exactMatches = namedValues.Where(nv => nv.Name == propertyPath).ToList();
            if (!exactMatches.Any())
            {
                return;
            }

            ExceptionUtilities.Assert(exactMatches.Count == 1, "Should only find at most one property path {0} when looking for null or empty value", propertyPath);

            NamedValue expectedBagValue = exactMatches.Single();
            var bagType = memberProperty.PropertyType as QueryCollectionType;

            if (expectedBagValue.Value == null)
            {
                instance.SetValue(memberProperty.Name, bagType.NullValue);
                this.unusedNamedValuePaths.Remove(expectedBagValue.Name);
            }
            else if (expectedBagValue.Value == EmptyData.Value)
            {
                QueryCollectionValue value = bagType.CreateCollectionWithValues(new QueryValue[] { });
                instance.SetValue(memberProperty.Name, value);
                this.unusedNamedValuePaths.Remove(expectedBagValue.Name);
            }
        }
コード例 #33
0
        /// <summary>
        /// Adds the specified property to the type Properties.
        /// </summary>
        /// <param name="property">The property to add.</param>
        public void Add(QueryProperty property)
        {
            ExceptionUtilities.CheckArgumentNotNull(property, "property");

            this.AssertNotReadOnly();
            this.Properties.Add(property);
        }
コード例 #34
0
        private void CompareBagPropertyWithNullOrEmpty(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues)
        {
            List<NamedValue> exactMatches = namedValues.Where(nv => nv.Name == propertyPath).ToList();

            if (!exactMatches.Any())
            {
                return;
            }

            ExceptionUtilities.Assert(exactMatches.Count == 1, "Should only find at most one property path {0} when looking for null or empty value", propertyPath);
            
            QueryCollectionValue actualQueryBagValue = instance.GetCollectionValue(memberProperty.Name);
            NamedValue expectedBagValue = exactMatches.Single();

            if (expectedBagValue.Value == null)
            {
                this.WriteErrorIfNotNull(propertyPath, actualQueryBagValue);
                this.unusedNamedValuePaths.Remove(propertyPath);
            }
            else if (expectedBagValue.Value == EmptyData.Value)
            {
                if (!this.WriteErrorIfNull(propertyPath, actualQueryBagValue))
                {
                    this.WriteErrorIfNotEqual(propertyPath, actualQueryBagValue.Elements.Count, 0, "Expected zero elements in BagProperty");
                    this.unusedNamedValuePaths.Remove(propertyPath);
                }
            }
        }
コード例 #35
0
        private void ComparePrimitiveBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues)
        {
            int i = 0;

            var collection = instance.GetCollectionValue(memberProperty.Name);

            if (!this.WriteErrorIfNull(propertyPath, collection))
            {
                List<NamedValue> primitiveItemNamedValues = namedValues.Where(pp => pp.Name == propertyPath + "." + i).ToList();
                while (primitiveItemNamedValues.Any())
                {                    
                    if (i < collection.Elements.Count)
                    {
                        var scalarQueryValue = collection.Elements[i] as QueryScalarValue;
                        ExceptionUtilities.Assert(primitiveItemNamedValues.Count() < 2, "Should not get more than one value for a primitive Bag item for path '{0}'", propertyPath + "." + i);
                        var value = primitiveItemNamedValues.Single();
                        this.WriteErrorIfNotEqual(propertyPath, value.Value, scalarQueryValue);
                        this.unusedNamedValuePaths.Remove(value.Name);
                    }

                    i++;
                    primitiveItemNamedValues = namedValues.Where(pp => pp.Name == propertyPath + "." + i).ToList();
                }

                this.WriteErrorIfNotEqual(propertyPath, collection.Elements.Count, i, "The number of expected items '{0}' does not match the actual '{1}' for propertyPath {2}", collection.Elements.Count, i, propertyPath);
            }
        }
コード例 #36
0
        private void UpdateScalarBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues, QueryScalarType scalarElementDataType)
        {
            int i = 0;

            var scalarCollection = new List<QueryValue>();
            List<NamedValue> scalarItemNamedValues = namedValues.Where(pp => pp.Name == propertyPath + "." + i).ToList();
            while (scalarItemNamedValues.Any())
            {
                ExceptionUtilities.Assert(scalarItemNamedValues.Count() < 2, "Should not get more than one value for a scalar Bag item for path '{0}'", propertyPath + "." + i);
                var value = scalarItemNamedValues.Single();
                scalarCollection.Add(scalarElementDataType.CreateValue(value.Value));
                this.unusedNamedValuePaths.Remove(value.Name);

                i++;
                scalarItemNamedValues = namedValues.Where(pp => pp.Name == propertyPath + "." + i).ToList();
            }

            if (scalarCollection.Any())
            {
                this.SetCollectionProperty(instance, memberProperty, scalarCollection);
            }
        }
コード例 #37
0
        private void CompareBagProperty(QueryStructuralValue instance, QueryProperty memberProperty, QueryType elementType, string propertyPath, IEnumerable<NamedValue> namedValues)
        {
            var scalarElementDataType = elementType as QueryScalarType;
            var complexTypeElementDataType = elementType as QueryComplexType;
     
            if (scalarElementDataType != null)
            {
                this.ComparePrimitiveBag(instance, memberProperty, propertyPath, namedValues);
            }
            else
            {
                ExceptionUtilities.CheckObjectNotNull(complexTypeElementDataType, "PropertyPath '{0}' is an invalid type '{1}'", propertyPath, memberProperty.PropertyType);

                this.CompareComplexBag(instance, memberProperty, propertyPath, namedValues);
            }
        }
コード例 #38
0
ファイル: StreamServices.cs プロジェクト: AlineGuan/odata.net
        private StreamData GenerateStreamData(EntityInstance entityInstance, XmlBaseAnnotation baseAddressAnnotation, QueryProperty streamProperty)
        {
            string editLinkValue;
            string contentType;
            string etag;
            if (streamProperty.Name == AstoriaQueryStreamType.DefaultStreamPropertyName)
            {
                editLinkValue = entityInstance.StreamEditLink;
                contentType = entityInstance.StreamContentType;
                etag = entityInstance.StreamETag;
            }
            else
            {
                var namedStream = entityInstance.Properties.OfType<NamedStreamInstance>().SingleOrDefault(p => p.Name == streamProperty.Name);
                ExceptionUtilities.CheckObjectNotNull(namedStream, "Could not find name stream '{0}' in entity payload", streamProperty.Name);
                editLinkValue = namedStream.EditLink;
                contentType = namedStream.EditLinkContentType;
                etag = namedStream.ETag;
            }

            if (contentType == null)
            {
                // TODO: add atom/json?
                contentType = this.Random.ChooseFrom(new[] { MimeTypes.TextPlain, MimeTypes.ApplicationOctetStream, MimeTypes.ApplicationHttp });
            }

            var streamData = new StreamData()
            {
                ContentType = contentType,
                ETag = etag,
                Content = this.Random.NextBytes(this.Random.Next(100)),
            };

            if (editLinkValue != null)
            {
                var editLink = new Uri(editLinkValue, UriKind.RelativeOrAbsolute);
                if (!editLink.IsAbsoluteUri)
                {
                    ExceptionUtilities.CheckObjectNotNull(baseAddressAnnotation, "Cannot construct absolute uri for edit link because xml:base annotation was missing");
                    editLink = new Uri(new Uri(baseAddressAnnotation.Value), editLinkValue);
                }

                streamData.EditLink = editLink.AbsoluteUri;
            }

            return streamData;
        }
コード例 #39
0
        private void UpdateComplexBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues, QueryComplexType complexTypeElementDataType)
        {
            int i = 0;

            var complexCollection = new List<QueryValue>();
            List<NamedValue> complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
            while (complexInstanceNamedValues.Any())
            {
                QueryStructuralValue complexValue = complexTypeElementDataType.CreateNewInstance();
                this.UpdateValues(complexValue, complexInstanceNamedValues, propertyPath + "." + i);
                complexCollection.Add(complexValue);

                i++;
                complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
            }

            if (complexCollection.Any())
            {
                this.SetCollectionProperty(instance, memberProperty, complexCollection);
            }
        }
コード例 #40
0
        private void SetCollectionProperty(QueryStructuralValue instance, QueryProperty memberProperty, List<QueryValue> collectionElements)
        {
            QueryCollectionValue queryCollectionValue = instance.GetCollectionValue(memberProperty.Name);

            queryCollectionValue.Elements.Clear();
            foreach (QueryValue queryValue in collectionElements)
            {
                queryCollectionValue.Elements.Add(queryValue);
            }

            instance.SetValue(memberProperty.Name, queryCollectionValue);
        }
コード例 #41
0
        /// <summary>
        /// Factory method to create the <see cref="QueryPropertyExpression"/>.
        /// </summary>
        /// <param name="instance">Instance expression.</param>
        /// <param name="queryProperty">The property.</param>
        /// <returns>The <see cref="QueryPropertyExpression"/> with the provided instance, name and type.</returns>
        public static QueryExpression Property(this QueryExpression instance, QueryProperty queryProperty)
        {
            ExceptionUtilities.CheckArgumentNotNull(instance, "instance");
            ExceptionUtilities.CheckArgumentNotNull(queryProperty, "queryProperty");

            return instance.Property(queryProperty.Name);
        }
コード例 #42
0
        private void CompareComplexBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues)
        {
            int i = 0;

            var collection = instance.GetCollectionValue(memberProperty.Name);

            if (!this.WriteErrorIfNull(propertyPath, collection))
            {
                List<NamedValue> complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
                while (complexInstanceNamedValues.Any())
                {
                    if (i < collection.Elements.Count)
                    {
                        var complexValue = collection.Elements[i] as QueryStructuralValue;
                        this.CompareValues(complexValue, complexInstanceNamedValues, propertyPath + "." + i);
                    }

                    i++;
                    complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
                }

                this.WriteErrorIfNotEqual(propertyPath, collection.Elements.Count, i, "The number of expected items '{0}' does not match the actual '{1}' for propertyPath {2}", collection.Elements.Count, i, propertyPath);
            }
        }