public MvdPropertyRuleValue(string varDataIndicator, string varDataValue, string varDataComparison)
 {
     DataIndicator  = new DataIndicator(varDataIndicator);
     DataComparison = varDataComparison;
     DataValue      = varDataValue;
 }
Example #2
0
        private DataFragment ExtractRulesValues(IPersistEntity entity, DataIndicatorLookup dataIndicators, AttributeRule[] rules, string prefix)
        {
            var tmp = new List <DataFragment>();

            if (rules == null)
            {
                return(null);
            }
            foreach (var attributeRule in rules)
            {
                // sort out values at current level
                // we have an id and indicators require it
                if (string.IsNullOrEmpty(attributeRule.RuleID))
                {
                    continue;
                }
                var storageName = prefix + attributeRule.RuleID;
                if (!dataIndicators.Contains(storageName))
                {
                    continue;
                }
                ExpressMetaProperty retProp;
                var value = GetFieldValue(entity, attributeRule.AttributeName, out retProp);
                if (retProp == null)
                {
                    // propery not found in class... ignore
                    //
                    continue;
                }
                // set the value
                if (dataIndicators.Requires(storageName, DataIndicator.ValueSelectorEnum.Value))
                {
                    DataFragment tF;
                    if (value is IEnumerable <object> )
                    {
                        var asEnum = value as IEnumerable <object>;
                        tF = new DataFragment(storageName, asEnum);
                    }
                    else
                    {
                        tF = new DataFragment(storageName, value);
                    }
                    tmp.Add(tF);
                }

                // set the type
                //
                if (dataIndicators.Requires(storageName, DataIndicator.ValueSelectorEnum.Type))
                {
                    var storName = DataIndicator.GetColumnName(storageName, DataIndicator.ValueSelectorEnum.Type);
                    tmp.Add(new DataFragment(storName, value.GetType().Name));
                }

                // set the Size
                //
                if (dataIndicators.Requires(storageName, DataIndicator.ValueSelectorEnum.Size))
                {
                    var storName = DataIndicator.GetColumnName(storageName, DataIndicator.ValueSelectorEnum.Size);

                    if (value is IEnumerable <object> )
                    {
                        var asEnum = value as IEnumerable <object>;
                        tmp.Add(new DataFragment(storName, asEnum.Count()));
                    }
                    else if (value == null)
                    {
                        tmp.Add(new DataFragment(storName, 0));
                    }
                    else
                    {
                        tmp.Add(new DataFragment(storName, 1)); // there's one entity
                    }
                }

                // set Existence
                // ReSharper disable once InvertIf // for symmetry in code
                //
                if (dataIndicators.Requires(storageName, DataIndicator.ValueSelectorEnum.Exists))
                {
                    var storName  = DataIndicator.GetColumnName(storageName, DataIndicator.ValueSelectorEnum.Exists);
                    var storValue = value != null;
                    if (value != null)
                    {
                        storValue = value.ToString().Trim() != "";
                    }
                    tmp.Add(new DataFragment(storName, storValue)); // true if not null
                }
            }
            return(DataFragment.Combine(tmp));
        }