Пример #1
0
        public CriteriaOperator Parse(string propertyPath, string parameters)
        {
            string path     = null;
            string criteria = "";

            foreach (string split in propertyPath.Split('.'))
            {
                path     += split;
                criteria += split;
                XPMemberInfo memberInfo = XpandReflectionHelper.GetXpMemberInfo(_xpClassInfo, path);
                if (memberInfo.IsCollection)
                {
                    criteria  = criteria.TrimEnd('.');
                    criteria += "[";
                }
                if (criteria.LastIndexOf('[') != criteria.Length - 1)
                {
                    criteria += ".";
                }
                path += ".";
            }

            var count = criteria.Count(c => c == '[');

            criteria += parameters;
            for (int i = 0; i < count; i++)
            {
                criteria = criteria + "]";
            }

            return(_session.ParseCriteria(criteria));
        }
Пример #2
0
        CriteriaOperator GetObjectKeyCriteria(ITypeInfo typeInfo, IEnumerable <XElement> xElements, ElementSchema elementSchema, string prefix = "")
        {
            CriteriaOperator op = CriteriaOperator.Parse("");

            foreach (var xElement in xElements)
            {
                var propertyName = xElement.GetAttributeValue(elementSchema.Name);
                var iMemberInfo  = typeInfo.FindMember(propertyName);

                if (iMemberInfo != null)
                {
                    var memberType = iMemberInfo.MemberTypeInfo;

                    if (typeof(XPBaseObject).IsAssignableFrom(memberType.Type))
                    {
                        op &= GetObjectKeyCriteria(memberType, xElement.Elements().First().Elements(), elementSchema, prefix + propertyName + ".");
                    }
                    else if (iMemberInfo.MemberType == typeof(Type))
                    {
                        var typeName = (string)GetValue(typeof(string), xElement);
                        var type     = XafTypesInfo.Instance.FindTypeInfo(typeName).Type;
                        op &= CriteriaOperator.Parse(prefix + propertyName + "=?", type);
                    }
                    else
                    {
                        op &= CriteriaOperator.Parse(prefix + propertyName + "=?", XpandReflectionHelper.ChangeType(GetValue(iMemberInfo.MemberType, xElement), memberType.Type));
                    }
                }
                else
                {
                    HandleError(xElement, FailReason.PropertyNotFound, elementSchema);
                }
            }
            return(op);
        }
Пример #3
0
 object GetValue(Type type, XElement simpleElement)
 {
     if (type == typeof(byte[]))
     {
         return(string.IsNullOrEmpty(simpleElement.Value) ? null : Convert.FromBase64String(simpleElement.Value));
     }
     return(XpandReflectionHelper.ChangeType(simpleElement.Value, type, CultureInfo.InvariantCulture));
 }
        void _pivotGridControl_EditValueChanged(object sender, EditValueChangedEventArgs e)
        {
            PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();

            for (int j = 0; j < ds.RowCount; j++)
            {
                ds[j][e.DataField] = XpandReflectionHelper.ChangeType(e.Editor.EditValue, ds[j][e.DataField].GetType());
            }
        }
Пример #5
0
        public void When_PropertyPath_Is_A_Reference_Object_Without_Chain()
        {
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Category")).WithExactArguments().WillReturn(associationMemberInfo);
            var propertyPathParser            = new PropertyPathParser(null, Session.DefaultSession);
            CriteriaOperator criteriaOperator = propertyPathParser.Parse("Category", "SomeProperty=50");

            Assert.AreEqual(new BinaryOperator("Category.SomeProperty", 50).ToString(), criteriaOperator.ToString());
        }
Пример #6
0
        private object ChangeType(PropertyInfo propertyInfo, SecurityElement e)
        {
            var typePropertyEditorIsUsed = propertyInfo.PropertyType == typeof(Type);

            if (!typePropertyEditorIsUsed)
            {
                return(XpandReflectionHelper.ChangeType(e.Attributes[propertyInfo.Name].ToString().XMLDecode(), propertyInfo.PropertyType));
            }
            return(string.IsNullOrEmpty((e.Attributes[propertyInfo.Name] + "")) ? null : XafTypesInfo.Instance.FindTypeInfo(e.Attributes[propertyInfo.Name].ToString()).Type);
        }
Пример #7
0
        public void When_PropertyPath_Is_A_Collection_Without_Chain()
        {
            XPMemberInfo collectionMemberInfo = GetCollectionMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Orders")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null, Session.DefaultSession);

            CriteriaOperator criteriaOperator = parser.Parse("Orders", "Amount=50");

            Assert.AreEqual("[Orders][[Amount] = 50]", criteriaOperator.ToString());
        }
Пример #8
0
        public void When_Parameter_Is_A_Chain()
        {
            XPMemberInfo collectionMemberInfo = GetCollectionMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Customers")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null, Session.DefaultSession);

            CriteriaOperator criteriaOperator = parser.Parse("Customers", "Order.OrderLine.Ammount=50");

            Assert.AreEqual(new ContainsOperator("Customers", new BinaryOperator("Order.OrderLine.Ammount", 50)).ToString(), criteriaOperator.ToString());
        }
Пример #9
0
        public void When_PropertyPath_Is_A_Reference_Object_With_A_Reference_Object_In_Chain()
        {
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order")).WillReturn(associationMemberInfo);
            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order.OrderLine")).WillReturn(associationMemberInfo);
            var parser = new PropertyPathParser(null, Session.DefaultSession);

            CriteriaOperator criteriaOperator = parser.Parse("Order.OrderLine", "Amount=50");

            Assert.AreEqual(new BinaryOperator("Order.OrderLine.Amount", 50).ToString(), criteriaOperator.ToString());
        }
Пример #10
0
        CriteriaOperator GetObjectKeyCriteria(ITypeInfo typeInfo, IEnumerable <XElement> xElements)
        {
            string criteria   = "";
            var    parameters = new List <object>();

            foreach (var xElement in xElements)
            {
                var name = xElement.GetAttributeValue("name");
                parameters.Add(XpandReflectionHelper.ChangeType(xElement.Value, typeInfo.FindMember(name).MemberType));
                criteria += name + "=? AND ";
            }
            return(CriteriaOperator.Parse(criteria.TrimEnd("AND ".ToCharArray()), parameters.ToArray()));
        }
Пример #11
0
        public void When_PropertyPath_Is_A_Reference_Object_With_A_Collection_In_Chain()
        {
            XPMemberInfo collectionMemberInfo  = GetCollectionMemberInfo();
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order")).WithExactArguments().WillReturn(associationMemberInfo);
            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order.OrderLines")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null);

            CriteriaOperator criteriaOperator = parser.Parse("Order.OrderLines", "Ammount=50");

            Assert.AreEqual(new ContainsOperator("Order.OrderLines", new BinaryOperator("Ammount", 50)).ToString(), criteriaOperator.ToString());
        }
Пример #12
0
 void SetPropertyValue(NameValueCollection config, PropertyInfo propertyInfo)
 {
     if (!(string.IsNullOrEmpty(config[propertyInfo.Name.MakeFirstCharLower()])))
     {
         propertyInfo.SetValue(this, XpandReflectionHelper.ChangeType(config[propertyInfo.Name.MakeFirstCharLower()], propertyInfo.PropertyType), null);
     }
     else
     {
         var defaultValueAttribute = propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), true).OfType <DefaultValueAttribute>().FirstOrDefault();
         if (defaultValueAttribute != null)
         {
             propertyInfo.SetValue(this, defaultValueAttribute.Value, null);
         }
     }
 }
Пример #13
0
 void ConvertModelNodes(TLogicRule attribute, TModelLogicRule rule)
 {
     if (_explicitProperties == null)
     {
         _explicitProperties = XpandReflectionHelper.GetExplicitProperties(attribute.GetType());
     }
     foreach (PropertyInfo explicitProperty in _explicitProperties)
     {
         object[] customAttributes = explicitProperty.GetCustomAttributes(typeof(TypeConverterAttribute), false);
         if (customAttributes.Length > 0)
         {
             var    converter = (TypeConverter)Type.GetType(((TypeConverterAttribute)customAttributes[0]).ConverterTypeName).CreateInstance(new object[] { rule.Application });
             string name      = explicitProperty.Name.Substring(explicitProperty.Name.LastIndexOf(".", StringComparison.Ordinal) + 1);
             object value     = attribute.GetPropertyValue(name);
             if (value != null)
             {
                 object convertTo = converter.ConvertTo(value, rule.TypeInfo.Type);
                 explicitProperty.SetValue(attribute, convertTo, null);
             }
         }
     }
 }
Пример #14
0
        void CreateObjects(ITypeInfo typeInfo)
        {
            var citynames = new List <string>(GetCitynames());

            XpandReflectionHelper.Shuffle(citynames);
            var rand = new Random();
            int i    = 0;

            foreach (string name in GetCustomerNames())
            {
                i++;
                var customer = (ICustomer)ReflectionHelper.CreateObject(typeInfo.Type, new object[] { _objectSpace.Session });
                customer.Name        = name;
                customer.City        = citynames.Count >= i ? citynames[i - 1] : citynames[rand.Next(citynames.Count - 1)];
                customer.Description = "Here is some description for " + customer.Name;
                _objectSpace.CommitChanges();
                ITypeInfo ordersTypeInfo = GetOrdersTypeInfo(typeInfo);
                if (ordersTypeInfo != null)
                {
                    CreateOrders(customer, ordersTypeInfo);
                }
            }
        }