protected override void PerformDataBinding(IEnumerable data)
		{
			base.PerformDataBinding(data);

			var dataObject = GetDataObject(data);

			var entity = dataObject as Entity;

			// The extracted data item is not an Entity, go down non-entity path.
			if (entity == null)
			{
				PerformDataBindingOfNonCrmEntity(dataObject);

				return;
			}
			
			// No property name provided, bind directly against the entity itself.
			if (string.IsNullOrEmpty(PropertyName))
			{
				PerformDataBindingOfCrmEntity(entity);

				return;
			}

			var property = GetAttributeValue(entity, PropertyName.Split(','));

			// No property was found.
			if (property == null)
			{
				PerformDataBindingOfCrmEntityProperty(entity, null, null);

				return;
			}

			// Property was found, but none of the property fallbacks had a non-null value.
			if (property.Value == null)
			{
				PerformDataBindingOfCrmEntityProperty(entity, property.Name, null);

				return;
			}

			var textValue = (Format ?? "{0}").FormatWith(property.Value);

			var contentFormatter = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency<ICrmEntityContentFormatter>(GetType().FullName);

			if (contentFormatter != null)
			{
				textValue = contentFormatter.Format(textValue, entity, this);
			}

			if (HtmlEncode)
			{
				textValue = HttpUtility.HtmlEncode(textValue);
			}

			PerformDataBindingOfCrmEntityProperty(entity, property.Name, textValue);
		}
Exemplo n.º 2
0
 public FilterProperty(PropertyInfo property, FilterPropertyAttribute propertyAttribute, FilterOperation operation, FuzzyMatchMode fuzzyMatchMode)
 {
     Property          = property;
     Operation         = operation;
     PropertyName      = propertyAttribute?.PropertyName ?? Property.Name;
     SplitPropertyName = PropertyName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
     Test           = propertyAttribute?.Test ?? FilterTest.Equal;
     FuzzyMatchMode = fuzzyMatchMode;
 }
Exemplo n.º 3
0
        public bool validateAttractor(object obj)
        {
            bool isMatch = true;

            if (PropertyName != null && PropertyName != "")
            {
                var      o    = obj;
                string[] toks = PropertyName.Split('.');
                for (int i = 0; i < toks.Length; ++i)
                {
                    if (o == null)
                    {
                        break;
                    }

                    var f = o.GetType().GetField(toks[i], BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                    if (f == null)
                    {
                        o = null;
                        break;
                    }
                    o = f.GetValue(o);
                }

                if (o != null)
                {
                    if (IsType != null && IsType != "" && !o.GetType().IsInstanceOfType(Type.GetType(IsType)))
                    {
                        isMatch = false;
                    }
                    else if (IsValue != null && IsValue != "" && !o.ToString().Equals(IsValue))
                    {
                        isMatch = false;
                    }
                }
            }
            return(isMatch);
        }
Exemplo n.º 4
0
        string ToSubQuerySql(SqlConversionContext context)
        {
            var parts = PropertyName.Split('.');

            return(ToNestedSubQuerySql(context, parts));
        }
        private object GetPropertyValue(object o)
        {
            if (PropertyName == "")
            {
                return(o);
            }
            object propertyValue = null;

            string[] nameParts = PropertyName.Split('.');
            if (nameParts.Length == 1)
            {
                // Get the object's properties
                PropertyInfo[] properties = o.GetType().GetProperties();

                //if the object has the property, get it's value. Otherwise, then see if there is an ExtendedProperties property and check there

                PropertyInfo theNamedProperty = properties.Where(a => a.Name == PropertyName).FirstOrDefault();
                if (theNamedProperty != null)
                {
                    propertyValue = theNamedProperty.GetValue(o);
                }
                else
                {
                    PropertyInfo extendedProperties = properties
                                                      .Where(a => a.Name == "ExtendedProperties")
                                                      .FirstOrDefault();
                    if (extendedProperties != null)
                    {
                        dynamic x = o;
                        propertyValue = x.ExtendedProperties[PropertyName];
                    }
                }
            }
            else
            {
                propertyValue = o;

                foreach (string namePart in nameParts)
                {
                    PropertyInfo[] properties = o.GetType().GetProperties();
                    Type           t          = propertyValue.GetType();
                    PropertyInfo   info       = t.GetProperty(namePart);
                    if (info == null)
                    {
                        PropertyInfo extendedProperties = properties
                                                          .Where(a => a.Name == "ExtendedProperties")
                                                          .FirstOrDefault();
                        if (extendedProperties != null)
                        {
                            dynamic x = o;
                            propertyValue = x.ExtendedProperties[namePart];
                        }
                        //return null;
                    }
                    else
                    {
                        propertyValue = info.GetValue(propertyValue);
                        if (propertyValue == null)
                        {
                            return(null);
                        }
                    }
                }
            }
            return(propertyValue);
        }
Exemplo n.º 6
0
        public bool ApplyUpdate(IMEPackage package, PropertyCollection properties, MergeFileChange1 mfc)
        {
            var propKeys = PropertyName.Split('.');

            PropertyCollection operatingCollection = properties;

            int i = 0;

            while (i < propKeys.Length - 1)
            {
                var matchingProp = operatingCollection.FirstOrDefault(x => x.Name.Instanced == propKeys[i]);
                if (matchingProp is StructProperty sp)
                {
                    operatingCollection = sp.Properties;
                }

                // ARRAY PROPERTIES NOT SUPPORTED
                i++;
            }

            Log.Information($@"Applying property update: {PropertyName} -> {PropertyValue}");
            switch (PropertyType)
            {
            case @"FloatProperty":
                FloatProperty fp = new FloatProperty(float.Parse(PropertyValue, CultureInfo.InvariantCulture), propKeys.Last());
                operatingCollection.AddOrReplaceProp(fp);
                break;

            case @"IntProperty":
                IntProperty ip = new IntProperty(int.Parse(PropertyValue), propKeys.Last());
                operatingCollection.AddOrReplaceProp(ip);
                break;

            case @"BoolProperty":
                BoolProperty bp = new BoolProperty(bool.Parse(PropertyValue), propKeys.Last());
                operatingCollection.AddOrReplaceProp(bp);
                break;

            case @"NameProperty":
                var index      = 0;
                var baseName   = PropertyValue;
                var indexIndex = PropertyValue.IndexOf(@"|", StringComparison.InvariantCultureIgnoreCase);
                if (indexIndex > 0)
                {
                    baseName = baseName.Substring(0, indexIndex);
                    index    = int.Parse(baseName.Substring(indexIndex + 1));
                }

                NameProperty np = new NameProperty(new NameReference(baseName, index), PropertyName);
                operatingCollection.AddOrReplaceProp(np);
                break;

            case @"ObjectProperty":
                // This does not support porting in, only relinking existing items
                ObjectProperty op = new ObjectProperty(0, PropertyName);
                if (PropertyValue != null && PropertyValue != @"M3M_NULL")     //M3M_NULL is a keyword for setting it to null to satisfy the schema
                {
                    var entry = package.FindEntry(PropertyValue);
                    if (entry == null)
                    {
                        throw new Exception(M3L.GetString(M3L.string_interp_mergefile_failedToUpdateObjectPropertyItemNotInPackage, PropertyName, PropertyValue, PropertyValue, package.FilePath));
                    }
                    op.Value = entry.UIndex;
                }
                operatingCollection.AddOrReplaceProp(op);
                break;

            case @"EnumProperty":
                var          enumInfo = PropertyValue.Split('.');
                EnumProperty ep       = new EnumProperty(enumInfo[0], mfc.OwningMM.Game, PropertyName);
                ep.Value = NameReference.FromInstancedString(enumInfo[1]);
                operatingCollection.AddOrReplaceProp(ep);
                break;

            case @"StrProperty":
                var sp = new StrProperty(PropertyValue, propKeys.Last());
                operatingCollection.AddOrReplaceProp(sp);
                break;

            default:
                throw new Exception(M3L.GetString(M3L.string_interp_mergefile_unsupportedPropertyType, PropertyType));
            }
            return(true);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 设置属性信息
 /// </summary>
 /// <param name="type"></param>
 public void SetPropertyInfo(Type type)
 {
     PropertyInfo = type.GetProperty(PropertyName.Split('.')[0]);
 }
Exemplo n.º 8
0
        public object GetRawValue <T>(T entity)
        {
            var v = GetPValue(entity, PropertyInfo, PropertyName.Split('.'), 0) ?? "";

            return(v);
        }
Exemplo n.º 9
0
        private void GetPropertyInfo <TProperty>(

            Expression <Func <T, TProperty> > propertyLambda)
        {
            Type type = typeof(T);

            MemberExpression member = null;

            if (propertyLambda.Body.NodeType == ExpressionType.Convert)
            {
                member = ((UnaryExpression)propertyLambda.Body).Operand as MemberExpression;
            }
            else
            {
                member = propertyLambda.Body as MemberExpression;
            }

            if (member == null)
            {
                throw new ArgumentException(string.Format(
                                                "Expression '{0}' refers to a method, not a property.",
                                                propertyLambda));
            }

            var propInfo = member.Member as PropertyInfo;

            if (propInfo == null)
            {
                throw new ArgumentException(string.Format(
                                                "Expression '{0}' refers to a field, not a property.",
                                                propertyLambda));
            }

            PropertyInfo = propInfo;

            if (type != propInfo.ReflectedType &&
                !type.IsSubclassOf(propInfo.ReflectedType))
            {
                PropertyName = member.ToString().Substring(member.ToString().IndexOf(".") + 1);
            }
            else
            {
                PropertyName = propInfo.Name;
            }

            Type delegateType =
                typeof(Func <,>).MakeGenericType(typeof(T), propInfo.PropertyType);

            var param = Expression.Parameter(type);

            var props = PropertyName.Split(new[] { '.' });

            Expression propId = Expression.Property(param, props[0]);

            for (int n = 1; n < props.Length; n++)
            {
                propId = Expression.Property(propId, props[n]);
            }

            LambdaExpression lambda = Expression.Lambda(delegateType, propId, param);

            OrderByExpression = lambda;
        }