コード例 #1
0
ファイル: ChoETLRecordHelper.cs プロジェクト: xman086/ChoETL
 public static void DoMemberLevelValidation(this IDictionary <string, object> dict, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm)
 {
     if (!fieldConfig.Validators.IsNullOrEmpty() && (vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
     {
         ChoValidator.ValidateFor(dict[fn], fn, fieldConfig.Validators);
     }
 }
コード例 #2
0
ファイル: ChoETLRecordHelper.cs プロジェクト: xman086/ChoETL
        public static void DoMemberLevelValidation(this object rec, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm)
        {
            if (!((vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel))
            {
                return;
            }

            if (rec is IDictionary <string, object> )
            {
                ((IDictionary <string, object>)rec).DoMemberLevelValidation(fn, fieldConfig, vm);
            }
            else
            {
                if (fieldConfig.PI != null)
                {
                    if (fieldConfig.Validators.IsNullOrEmpty())
                    {
                        ChoValidator.ValidateFor(rec, fieldConfig.PI);
                    }
                    else
                    {
                        ChoValidator.ValidateFor(ChoType.GetPropertyValue(rec, fieldConfig.PI), fn, fieldConfig.Validators);
                    }
                }
            }
        }
コード例 #3
0
ファイル: ChoETLRecordHelper.cs プロジェクト: xman086/ChoETL
 public static void DoMemberLevelValidation(this object rec, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm, object fieldValue)
 {
     if ((vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
     {
         if (fieldConfig.Validators.IsNullOrEmpty())
         {
             ChoValidator.ValidateFor(fieldValue, fn, fieldConfig.Validators);
         }
     }
 }
コード例 #4
0
 public static void DoMemberLevelValidation(this object rec, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm, object fieldValue)
 {
     if ((vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
     {
         if (fieldConfig.Validators.IsNullOrEmpty())
         {
             if (!(rec is ExpandoObject))
             {
                 ChoValidator.ValidateFor(fieldValue, fn, ChoTypeDescriptor.GetPropetyAttributes <ValidationAttribute>(ChoTypeDescriptor.GetProperty <ValidationAttribute>(rec.GetType(), fn)).ToArray());
             }
         }
         else
         {
             ChoValidator.ValidateFor(fieldValue, fn, fieldConfig.Validators);
         }
     }
 }
コード例 #5
0
 public static void DoMemberLevelValidation(this IDictionary <string, object> dict, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm)
 {
     if (!fieldConfig.Validators.IsNullOrEmpty() && (vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
     {
         if (fieldConfig.Validator == null)
         {
             ChoValidator.ValidateFor(dict[fn], fn, fieldConfig.Validators);
         }
         else
         {
             if (!fieldConfig.Validator(dict[fn]))
             {
                 throw new ValidationException("Failed to validate '{0}' member. {1}".FormatString(fn, Environment.NewLine));
             }
         }
     }
 }
コード例 #6
0
 public static void DoMemberLevelValidation(this object rec, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm)
 {
     if (rec is ExpandoObject)
     {
         ((IDictionary <string, object>)rec).DoMemberLevelValidation(fn, fieldConfig, vm);
     }
     else
     {
         if ((vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
         {
             if (fieldConfig.Validators.IsNullOrEmpty())
             {
                 ChoValidator.ValidateFor(rec, fn);
             }
             else
             {
                 ChoValidator.ValidateFor(ChoType.GetMemberValue(rec, fn), fn, fieldConfig.Validators);
             }
         }
     }
 }
コード例 #7
0
        public static void DoMemberLevelValidation(this object rec, string fn, ChoRecordFieldConfiguration fieldConfig, ChoObjectValidationMode vm)
        {
            if (!((vm & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel))
            {
                return;
            }

            if (rec is IDictionary <string, object> )
            {
                ((IDictionary <string, object>)rec).DoMemberLevelValidation(fn, fieldConfig, vm);
            }
            else
            {
                if (fieldConfig.Validator == null)
                {
                    if (fieldConfig.PD == null)
                    {
                        fieldConfig.PD = fieldConfig.PropertyDescriptor;
                    }
                    if (fieldConfig.PD != null)
                    {
                        if (fieldConfig.Validators.IsNullOrEmpty())
                        {
                            ChoValidator.ValidateFor(rec, fieldConfig.PD);
                        }
                        else
                        {
                            ChoValidator.ValidateFor(fieldConfig.PD.GetValue(rec), fn, fieldConfig.Validators);
                        }
                    }
                }
                else
                {
                    if (!fieldConfig.Validator(fieldConfig.PD.GetValue(rec)))
                    {
                        throw new ValidationException("Failed to validate '{0}' member. {1}".FormatString(fn, Environment.NewLine));
                    }
                }
            }
        }
コード例 #8
0
        private void Initialize()
        {
            try
            {
                if (!Monitor.TryEnter(_padLock, 1 * 1000))
                {
                    return;
                }

                IDictionary <string, object> kvpDict = null;

                if (_func != null)
                {
                    kvpDict = _func();
                }
                else
                {
                    kvpDict = Seed();
                }

                if (kvpDict == null)
                {
                    return;
                }

                IDictionary <string, object> mkvpDict = _kvpDict;
                bool hasDiff = mkvpDict == null || kvpDict.Except(mkvpDict).Concat(mkvpDict.Except(kvpDict)).Any();
                if (!hasDiff)
                {
                    return;
                }

                _kvpDict = kvpDict;

                ChoPropertyAttribute attr = null;
                object memberValue        = null;
                string propName           = null;
                //scan through members and load them
                foreach (var prop in ChoType.GetMembers(GetType()).Where(m => m.GetCustomAttribute <ChoIgnoreMemberAttribute>() != null && !ChoType.IsReadOnlyMember(m)))
                {
                    attr = ChoType.GetMemberAttribute <ChoPropertyAttribute>(prop);
                    try
                    {
                        SetDefaultValue(prop, true);

                        propName = attr != null && !attr.Name.IsNullOrWhiteSpace() ? attr.Name : prop.Name;

                        if (kvpDict.ContainsKey(propName))
                        {
                            memberValue = AfterKVPLoaded(prop.Name, kvpDict[propName]);
                        }
                        else
                        {
                            memberValue = AfterKVPLoaded(prop.Name, null);
                        }

                        if (memberValue != null && memberValue is string)
                        {
                            string mv = memberValue as string;
                            if (attr != null)
                            {
                                switch (attr.TrimOption)
                                {
                                case ChoPropertyValueTrimOption.Trim:
                                    mv = mv.Trim();
                                    break;

                                case ChoPropertyValueTrimOption.TrimEnd:
                                    mv = mv.TrimEnd();
                                    break;

                                case ChoPropertyValueTrimOption.TrimStart:
                                    mv = mv.TrimStart();
                                    break;
                                }
                            }

                            memberValue = mv;
                        }

                        if (ChoType.GetMemberType(prop) == typeof(string))
                        {
                            if (!((string)memberValue).IsNullOrEmpty())
                            {
                                ChoType.ConvertNSetMemberValue(this, prop, memberValue);
                            }
                        }
                        else
                        {
                            if (memberValue != null)
                            {
                                ChoType.ConvertNSetMemberValue(this, prop, memberValue);
                            }
                        }
                        ChoValidator.ValidateFor(this, prop);
                    }
                    catch (Exception ex)
                    {
                        //ChoLog.Error("{0}: Error loading '{1}' property. {2}".FormatString(NName, prop.Name, ex.Message));
                        SetDefaultValue(prop, false);
                    }
                }
            }
            catch (Exception outerEx)
            {
                //ChoLog.Error("{0}: Error loading options. {1}".FormatString(NName, outerEx.Message));
            }
            finally
            {
                Monitor.Exit(_padLock);
            }
        }