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)); } } } }
public static ChoConfigurationMetaDataState Register(string configSectionName, string metaDataFileName) { ChoGuard.ArgumentNotNullOrEmpty(configSectionName, "ConfigSectionName"); ChoGuard.ArgumentNotNullOrEmpty(metaDataFileName, "MetaDataFileName"); lock (_configMetaData.SyncRoot) { if (_configMetaData.ContainsKey(configSectionName)) { _configMetaData.Remove(configSectionName); } ChoConfigurationMetaDataState configurationMetaDataState = new ChoConfigurationMetaDataState(); _configMetaData.Add(configSectionName, configurationMetaDataState); configurationMetaDataState.ConfigSectionName = configSectionName; configurationMetaDataState.MetaDataFileName = metaDataFileName; configurationMetaDataState.FileWatcher = new ChoFileWatcher(metaDataFileName); configurationMetaDataState.FileWatcher.FileChanged += (target, e) => configurationMetaDataState.OnConfigurationMetaDataChanged(); configurationMetaDataState.FileWatcher.StartWatching(); return(configurationMetaDataState); } }
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); }
private static void Add <T>(string logFileName, ChoDictionary <string, T> objDictionary, ChoTypeNameSpecifier defaultObjectKey, string typeName) where T : class { try { T obj = ChoObjectManagementFactory.CreateInstance(typeName) as T; if (obj != null) { string key; if (obj is IChoObjectNameable) { key = ((IChoObjectNameable)obj).Name; } else { key = ChoObjectNameableAttribute.GetName(obj.GetType(), defaultObjectKey); } ChoGuard.NotNullOrEmpty(key, String.Format("{0}: Name can't be empty.", typeName)); if (!objDictionary.ContainsKey(key)) { objDictionary.Add(key, obj); } } //else // ChoStreamProfile.WriteLine(ChoReservedDirectoryName.Settings, Path.ChangeExtension(logFileName, ChoReservedFileExt.Err), // String.Format("Failed to create {0} object.", typeName)); } catch (Exception) { //ChoStreamProfile.WriteLine(ChoReservedDirectoryName.Settings, Path.ChangeExtension(logFileName, ChoReservedFileExt.Err), // String.Format("Failed to create {0} object. {1}", typeName, ex.Message)); } }
public ChoDictionary <string, ChoObjConfigurable> ConvertToDistinctDictionary(ChoObjConfigurable[] objConfigurables) { ChoDictionary <string, ChoObjConfigurable> _distinctObjectConfigurables = new ChoDictionary <string, ChoObjConfigurable>(); if (ChoGuard.IsArgumentNotNullOrEmpty(objConfigurables)) { return(_distinctObjectConfigurables); } foreach (ChoObjConfigurable objConfigurable in objConfigurables) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (_distinctObjectConfigurables.ContainsKey(objConfigurable.Name)) { ChoTrace.Debug(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _distinctObjectConfigurables.Add(objConfigurable.Name, objConfigurable); } return(_distinctObjectConfigurables); }
public void LoadAssemblies(string[] directories) { if (!ChoGuard.IsArgumentNotNullOrEmpty(directories)) { return; } foreach (Assembly assembly in ChoAssembly.GetAssemblies(directories)) { if (_loadedAssemblies.ContainsKey(assembly.FullName)) { continue; } _loadedAssemblies.Add(assembly.FullName, assembly); } }
internal virtual void Add(IChoProfile profile) { ChoGuard.ArgumentNotNull(profile, "Profile"); if (_childProfiles.ContainsKey(profile.ProfilerName)) { return; } _childProfiles.Add(profile.ProfilerName, profile); }
private static void _Load() { List <MethodInfo> methods = new List <MethodInfo>(); foreach (Type type in ChoType.GetTypes(typeof(ChoAppDomainEventsRegisterableTypeAttribute))) { #region Find and load domain load handlers methods.Clear(); foreach (MethodInfo methodInfo in ChoType.GetMethods(type, typeof(ChoAppDomainLoadMethodAttribute))) { if (methodInfo == null) { continue; } if (methodInfo.GetParameters().Length == 0 && methodInfo.ReturnType == typeof(void) && methodInfo.IsStatic) { methods.Add(methodInfo); } } if (methods != null && methods.Count > 0) { _onDomainLoadHandlers.Add(type, methods.ToArray()); } #endregion Find and load domain load handlers #region Find and load domain unload handlers methods.Clear(); foreach (MethodInfo methodInfo in ChoType.GetMethods(type, typeof(ChoAppDomainUnloadMethodAttribute))) { if (methodInfo == null) { continue; } if (methodInfo.GetParameters().Length == 0 && methodInfo.ReturnType == typeof(void) && methodInfo.IsStatic) { methods.Add(methodInfo); } } if (methods != null && methods.Count > 0) { _onDomainUnloadHandlers.Add(type, methods.ToArray()); } #endregion Find and load domain unload handlers } OnAssemblyLoad(null, null); }
private static IChoProfile Register(string name, string profileName, MemberInfo memberInfo, string typeProfileName, ChoProfileAttribute memberProfileAttribute, ChoProfileAttribute typeProfileAttribute) { lock (MemberProfileCache.SyncRoot) { IChoProfile profile = null; if (MemberProfileCache.TryGetValue(profileName, out profile)) { return(profile); } if (!String.IsNullOrEmpty(typeProfileName) && !MemberProfileCache.ContainsKey(typeProfileName)) { if (typeProfileAttribute != null) { IChoProfile profile1 = typeProfileAttribute.ConstructProfile(ChoThreadLocalStorage.Target, null); //SetAsNotDisposed(profile1, false); MemberProfileCache.Add(typeProfileName, profile1); } else { MemberProfileCache.Add(typeProfileName, GlobalProfile); } } if (memberProfileAttribute == null) { return(MemberProfileCache[typeProfileName]); } else { IChoProfile profile1 = memberProfileAttribute.ConstructProfile(ChoThreadLocalStorage.Target, MemberProfileCache[typeProfileName]); //SetAsNotDisposed(profile1, false); MemberProfileCache.Add(profileName, profile1); return(MemberProfileCache[profileName]); } } }
private static void Adjust <T>(string logFileName, ChoDictionary <string, T> objDictionary, ChoObjTypeConfigurable[] objTypeConfigurables, ChoDefaultObjectKey typeName) where T : class { if (objTypeConfigurables != null && objTypeConfigurables.Length > 0) { foreach (ChoObjTypeConfigurable objTypeConfigurable in objTypeConfigurables) { if (objTypeConfigurable == null) { continue; } try { string key = objTypeConfigurable.Name; T obj = default(T); if (!String.IsNullOrEmpty(objTypeConfigurable.Type)) { obj = ChoObjectManagementFactory.CreateInstance(objTypeConfigurable.Type) as T; if (obj == null) { ChoStreamProfile.WriteLine(ChoLogDirectories.Settings, Path.ChangeExtension(logFileName, ChoExt.Err), String.Format("Failed to create {0} object.", objTypeConfigurable.Type)); } } if (obj != null) { key = ChoObjectNameableAttribute.GetName(obj.GetType(), typeName); } if (objTypeConfigurable.Action == Action.Remove && objDictionary.ContainsKey(key)) { objDictionary.Remove(key); } else if (!objDictionary.ContainsKey(key) && obj != null) { objDictionary.Add(key, obj); } } catch (Exception ex) { ChoStreamProfile.WriteLine(ChoLogDirectories.Settings, Path.ChangeExtension(logFileName, ChoExt.Err), String.Format("Failed to create {0} object. {1}", objTypeConfigurable.Type, ex.Message)); } } } }
public static void AddAssemblyToCache(Assembly assembly) { ChoGuard.ArgumentNotNull(assembly, "Assembly"); lock (_assemblyCache.SyncRoot) { if (ContainsAssembly(assembly)) { return; } _assemblyCache.Add(assembly.FullName, assembly); //ChoLoadedAssemblies.Me.Add(assembly); } }
private static ChoIniDocument LoadDocument(string filePath) { lock (_iniDocuments.SyncRoot) { if (!_iniDocuments.ContainsKey(filePath)) { _iniDocuments.Add(filePath, OpenNLoadDocument(filePath)); } else if (_iniDocuments[filePath].IsDisposed) { _iniDocuments[filePath] = ChoIniDocument.Load(filePath); } return(_iniDocuments[filePath]); } }
public ChoDictionary <string, ChoLogListener[]> Find(ICollection <string> categories) { ChoGuard.ArgumentNotNull(categories, "Categories"); ChoDictionary <string, ChoLogListener[]> logListeners = new ChoDictionary <string, ChoLogListener[]>(); foreach (string category in categories) { foreach (string key in _logSources.Keys) { if (key == category && _logSources.ContainsKey(key)) { logListeners.Add(key, _logSources[key]); } } } return(logListeners); }
private void AddToMap(ChoDictionary <string, string> typeShortNameMap, ChoBufferProfileEx errProfile, Type type, string typeShortName, bool overrideType) { if (typeShortNameMap.ContainsKey(typeShortName)) { if (!overrideType) { errProfile.AppendLine(String.Format("Type: {0}, ShortName: {1}", type.SimpleQualifiedName(), typeShortName)); return; } else { ChoTrace.Debug(String.Format("DELETED: Type: {0}, ShortName: {1}", typeShortNameMap[typeShortName], typeShortName)); typeShortNameMap.Remove(typeShortName); } } typeShortNameMap.Add(typeShortName, type.SimpleQualifiedName()); ChoTrace.Debug(String.Format("ADDED: Type: {0}, ShortName: {1}", type.SimpleQualifiedName(), typeShortName)); }
private static void Build(MemberInfo memberInfo) { List <IChoSurrogateValidator> validators = new List <IChoSurrogateValidator>(); ChoCompositeValidator compositeValidator = new ChoAndCompositeValidator(); foreach (Attribute memberCallAttribute in ChoType.GetMemberAttributesByBaseType(memberInfo, typeof(Attribute))) { foreach (IChoValidationManager validationManager in ChoValidationManagerSettings.Me.ValidationManagers) { if (memberCallAttribute is ChoCompositeValidatorAttribute) { if (((ChoCompositeValidatorAttribute)memberCallAttribute).CompositionType == ChoCompositionType.Or) { if (validators.Count > 0) { compositeValidator.Add(validators.ToArray()); validators.Add(compositeValidator); validators.Clear(); } compositeValidator = new ChoOrCompositeValidator(); } } else if (validationManager.IsValid(memberCallAttribute)) { IChoSurrogateValidator validator = validationManager.CreateValidator(memberCallAttribute, ValidationScope.Before, ValidatorSource.Attribute); if (validator != null) { validators.Add(validator); } } } } if (validators.Count > 0) { compositeValidator.Add(validators.ToArray()); validators.Add(compositeValidator); } _objectMemberValidatorCache.Add(memberInfo, new ChoAndCompositeValidator(validators.ToArray())); }
public static ChoQueuedExecutionService GetService(string name) { ChoQueuedExecutionService queuedExecutionService = null; if (_globalQueuedExecutionServices.TryGetValue(name, out queuedExecutionService)) { return(queuedExecutionService); } lock (_globalQueuedExecutionServices.SyncRoot) { if (_globalQueuedExecutionServices.TryGetValue(name, out queuedExecutionService)) { return(queuedExecutionService); } queuedExecutionService = new ChoQueuedExecutionService(name, true); _globalQueuedExecutionServices.Add(name, queuedExecutionService); return(queuedExecutionService); } }
private static bool IsModified(string filePath) { DateTime lastModifiedDateTime = DateTime.MinValue; if (_iniDocumentsLastModifiedDateTimes.ContainsKey(filePath)) { lastModifiedDateTime = _iniDocumentsLastModifiedDateTimes[filePath]; } else { _iniDocumentsLastModifiedDateTimes.Add(filePath, lastModifiedDateTime); } FileInfo fileInfo = new FileInfo(filePath); if (lastModifiedDateTime < fileInfo.LastWriteTimeUtc) { _iniDocumentsLastModifiedDateTimes[filePath] = fileInfo.LastWriteTimeUtc; return(true); } return(false); }
public void Initialize() { if (_propertyReplacers == null) { _propertyReplacers = new ChoDictionary <string, IChoPropertyReplacer>(DefaultPropertyReplacers); } if (_propertyReplacers.Count == DefaultPropertyReplacers.Count) { if (PropertyDictionaryReplacers != null) { foreach (ChoObjConfigurable objConfigurable in PropertyDictionaryReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoKeyValuePropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } if (CustomPropertyReplacers != null) { foreach (ChoObjConfigurable objConfigurable in CustomPropertyReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoCustomPropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } } }
private static void Build(MemberInfo memberInfo) { string validatorName = null; List <IChoSurrogateValidator> validators = new List <IChoSurrogateValidator>(); Dictionary <string, IChoSurrogateValidator> namedValidators = new Dictionary <string, IChoSurrogateValidator>(); List <ChoCompositeValidatorAttribute> compositeValidatorsAttrs = new List <ChoCompositeValidatorAttribute>(); ChoCompositeValidator topCompositeValidator = new ChoAndCompositeValidator(); ChoCompositeValidator compositeValidator = topCompositeValidator; Attribute[] attrs = ChoType.GetMemberAttributesByBaseType(memberInfo, typeof(Attribute)); //Lookup all non composite validators, build and cache them foreach (Attribute memberCallAttribute in attrs) { if (!(memberCallAttribute is ChoCompositeValidatorAttribute)) { foreach (IChoValidationManager validationManager in ChoValidationManagerSettings.Me.ValidationManagers) { if (validationManager.IsValid(memberCallAttribute, out validatorName)) { if (!validatorName.IsNullOrWhiteSpace() && namedValidators.ContainsKey(validatorName)) { continue; } IChoSurrogateValidator validator = validationManager.CreateValidator(memberCallAttribute, ValidationScope.Before, ValidatorSource.Attribute); if (validator != null) { if (validatorName.IsNullOrWhiteSpace()) { validators.Add(validator); } else { namedValidators.Add(validatorName, validator); } } break; } } } else if (memberCallAttribute is ChoCompositeValidatorAttribute) { compositeValidatorsAttrs.Add(memberCallAttribute as ChoCompositeValidatorAttribute); } } //Build and cache all the composite validators foreach (ChoCompositeValidatorAttribute memberCallAttribute in compositeValidatorsAttrs) { if (memberCallAttribute.Name.IsNullOrWhiteSpace()) { IChoSurrogateValidator validator = BuildCompositeValidator(memberCallAttribute as ChoCompositeValidatorAttribute, namedValidators, compositeValidatorsAttrs.ToArray()); if (validator != null) { validators.Add(validator); } } } _objectMemberValidatorCache.Add(memberInfo, new ChoAndCompositeValidator(validators.ToArray())); }
public bool Initialize(bool beforeFieldInit, object state) { if (_propertyReplacers == null) { //ChoStreamProfile.Clean(ChoReservedDirectoryName.Settings, ChoType.GetLogFileName(typeof(ChoPropertyManagerSettings), ChoReservedFileExt.Err)); _propertyReplacers = new ChoDictionary <string, IChoPropertyReplacer>(DefaultPropertyReplacers); } if (!beforeFieldInit) { if (_propertyReplacers.Count == DefaultPropertyReplacers.Count) { if (PropertyDictionaryReplacers != null) { foreach (ChoObjConfigurable objConfigurable in PropertyDictionaryReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoKeyValuePropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } if (CustomPropertyReplacers != null) { foreach (ChoObjConfigurable objConfigurable in CustomPropertyReplacers) { if (objConfigurable == null) { continue; } if (String.IsNullOrEmpty(objConfigurable.Name)) { continue; } if (!(objConfigurable is IChoCustomPropertyReplacer)) { continue; } if (_propertyReplacers.ContainsKey(objConfigurable.Name)) { ChoProfile.WriteLine(String.Format("Item with {0} key already exists.", objConfigurable.Name)); continue; } _propertyReplacers.Add(objConfigurable.Name, objConfigurable as IChoPropertyReplacer); } } } } return(false); }