public bool Initialize(bool beforeFieldInit, object state) { _logSources = ChoDictionary <string, ChoLogListener[]> .Unique(new ChoDictionary <string, ChoLogListener[]>(DefaultLogSources)); if (!beforeFieldInit) { if (LoggerTypes == null) { return(false); } foreach (ChoLogSource loggerType in LoggerTypes) { try { ChoValidation.Validate(loggerType); _logSources.Add(loggerType.Category, loggerType.LogListeners); } catch (Exception) { //ChoStreamProfile.WriteLine(ChoReservedDirectoryName.Settings, ChoPath.AddExtension(typeof(ChoLoggerSettings).FullName, ChoReservedFileExt.Err), // String.Format("Failed to initialize '{0}' object. {1}", loggerType.Category, ex.Message)); } } } return(false); }
public void Initialize(bool beforeInit) { _logSources = ChoDictionary <string, ChoLogListener[]> .Unique(new ChoDictionary <string, ChoLogListener[]>(DefaultLogSources)); if (!beforeInit) { if (LoggerTypes == null) { return; } foreach (ChoLogSource loggerType in LoggerTypes) { try { ChoValidation.Validate(loggerType); _logSources.Add(loggerType.Category, loggerType.LogListeners); } catch (Exception ex) { ChoStreamProfile.WriteLine(ChoLogDirectories.Settings, Path.ChangeExtension(typeof(ChoLoggerSettings).Name, ChoExt.Err), String.Format("Failed to initialize '{0}' object. {1}", loggerType.Category, ex.Message)); } } } }
private static void DoObjectMemberValidation(object target) { if (target == null) { return; } if (target.GetType().IsPrimitive || target is string || target is Enum ) { } else { //Call the initialize to all members foreach (FieldInfo fieldInfo in ChoType.GetFields(target.GetType())) { if (fieldInfo.IsReadOnly()) { continue; } object fieldValue = ChoType.GetFieldValue(target, fieldInfo.Name); if (fieldValue == null) { continue; } if (!(fieldValue is string) && fieldValue is IEnumerable) { foreach (object fieldItemValue in (IEnumerable)fieldValue) { DoObjectMemberValidation(fieldItemValue); } } else { DoObjectMemberValidation(fieldValue); } } } if (target != null && !(target is ChoRealProxy)) { //Do Validate ChoDoObjectValidationAfterInitializationAttribute doObjectValidationAfterInitializationAttribute = ChoType.GetAttribute <ChoDoObjectValidationAfterInitializationAttribute>(target.GetType()); if (doObjectValidationAfterInitializationAttribute != null && doObjectValidationAfterInitializationAttribute.DoObjectValidation) { ChoValidationResults validationResults = ChoValidation.Validate(target); if (validationResults != null && validationResults.Count > 0) { throw new ChoValidationException("Failed to validate object.", validationResults); } } } }
public virtual bool PreMethodInvoke(object owner, MethodCallMessageWrapper methodCallMsg, ChoMemberInfo memberInfo) { MethodInfo methodInfo = (MethodInfo)methodCallMsg.MethodBase; ChoInterceptableObject interceptableObject = owner as ChoInterceptableObject; if (interceptableObject != null) { if (memberInfo.DirtyOperation && !interceptableObject.Silent) { if (interceptableObject.PreInvokeInternal(memberInfo)) { if (interceptableObject.Initialized) { interceptableObject.SetDirty(memberInfo.DirtyOperation); } else { interceptableObject.IsModified = true; } } else { return(false); } } } if (memberInfo.Info != null) { if (memberInfo.DirtyOperation) { ChoValidation.Validate(memberInfo.Info, memberInfo.Value); if (interceptableObject != null && interceptableObject.Initialized) { ChoConfigurationObjectErrorManagerService.ResetObjectMemberError(interceptableObject, memberInfo.Name); } } } return(true); }