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);
            }
        }
예제 #2
0
 internal static ObjectBuildState GetObjectState(Type type)
 {
     if (!_globalObjectBuildStateCache.ContainsKey(type))
     {
         return(ObjectBuildState.None);
     }
     return(_globalObjectBuildStateCache[type]);
 }
예제 #3
0
        internal virtual void Add(IChoProfile profile)
        {
            ChoGuard.ArgumentNotNull(profile, "Profile");

            if (_childProfiles.ContainsKey(profile.ProfilerName))
            {
                return;
            }
            _childProfiles.Add(profile.ProfilerName, profile);
        }
예제 #4
0
        public IEnumerable <ChoLogListener[]> Find(string category)
        {
            ChoGuard.ArgumentNotNull(category, "Category");

            foreach (string key in _logSources.Keys)
            {
                if (key == category && _logSources.ContainsKey(key))
                {
                    yield return(_logSources[key]);
                }
            }
        }
예제 #5
0
        public static ChoIniDocument GetDocument(string filePath)
        {
            lock (_iniDocuments.SyncRoot)
            {
                if (IsModified(filePath) && _iniDocuments.ContainsKey(filePath))
                {
                    _iniDocuments.Remove(filePath);
                }

                return(LoadDocument(filePath));
            }
        }
예제 #6
0
        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));
                    }
                }
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
        }
예제 #9
0
        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));
            }
        }
예제 #10
0
        public static void UnregisterMe(Type type)
        {
            ChoGuard.ArgumentNotNull(type, "Type");

            if (!_onDomainUnloadHandlers.ContainsKey(type))
            {
                return;
            }
            _onDomainUnloadHandlers.Remove(type);
        }
예제 #11
0
 public string this[string typeShortName]
 {
     get
     {
         ChoGuard.ArgumentNotNullOrEmpty(typeShortName, "TypeShortName");
         lock (_padLock)
         {
             return(_typeShortNameMap.ContainsKey(typeShortName) ? _typeShortNameMap[typeShortName] : null);
         }
     }
 }
        public static IChoSurrogateValidator GetValidator(MemberInfo memberInfo)
        {
            ChoGuard.ArgumentNotNull(memberInfo, "memberInfo");
            if (!ChoType.IsValidObjectMember(memberInfo))
            {
                return(null);
            }

            //If the cache doesn't have, build it
            if (!_objectMemberValidatorCache.ContainsKey(memberInfo))
            {
                lock (_objectMemberValidatorCache.SyncRoot)
                {
                    if (!_objectMemberValidatorCache.ContainsKey(memberInfo))
                    {
                        Build(memberInfo);
                    }
                }
            }

            return(_objectMemberValidatorCache[memberInfo]);
        }
        public IChoConfigStorage GetConfigStorage(string configStorageName)
        {
            ChoGuard.ArgumentNotNullOrEmpty(configStorageName, "Config Storage Name");

            lock (_padLock)
            {
                if (_configStorages != null && _configStorages.ContainsKey(configStorageName))
                {
                    return(_configStorages[configStorageName]);
                }
            }

            return(null);
        }
예제 #14
0
        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));
        }
예제 #15
0
        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]);
                }
            }
        }
예제 #16
0
        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);
        }
예제 #17
0
 public ChoLogListener this[string name]
 {
     get { return(_logListeners != null && _logListeners.ContainsKey(name) ? _logListeners[name] : null); }
 }
예제 #18
0
        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);
                    }
                }
            }
        }
예제 #19
0
 public IChoLogFormatter this[string name]
 {
     get { return(_logFormatters != null && _logFormatters.ContainsKey(name) ? _logFormatters[name] : null); }
 }
예제 #20
0
        public static bool ContainsAssembly(string assemblyName)
        {
            ChoGuard.ArgumentNotNullOrEmpty(assemblyName, "AssemblyName");

            return(_assemblyCache.ContainsKey(assemblyName));
        }
예제 #21
0
        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);
        }
예제 #22
0
        internal static T CreateInstance <T>(Type objType, ChoObjectConstructionType defaultObjectConstructionType,
                                             bool beforeFieldInit, out Exception exception)
        {
            exception = null;

            ChoGuard.ArgumentNotNull(objType, "objType");

            T instance = default(T);
            ChoObjectConstructionType objectConstructionType = defaultObjectConstructionType;

            if (IsConstructing(objType))
            {
                instance = New <T>(objType, null);
                if (instance != null)
                {
                    ChoObjectInitializer.Initialize(instance, beforeFieldInit);
                }
            }
            else
            {
                try
                {
                    _globalObjectBuildStateCache[objType] = ObjectBuildState.Constructing;
                    IChoCustomObjectFactory   customObjectFactory    = null;
                    ChoObjectFactoryAttribute objectFactoryAttribute = ChoType.GetAttribute(objType, typeof(ChoObjectFactoryAttribute)) as ChoObjectFactoryAttribute;

                    if (objectFactoryAttribute != null)
                    {
                        objectConstructionType = objectFactoryAttribute.ObjectConstructionType;
                        customObjectFactory    = objectFactoryAttribute.CustomObjectFactory;
                    }

                    switch (objectConstructionType)
                    {
                    case ChoObjectConstructionType.Singleton:
                        //lock (_globalObjectCache.SyncRoot)
                        //{
                        if (_globalObjectCache.ContainsKey(objType))
                        {
                            return((T)_globalObjectCache[objType]);
                        }
                        else
                        {
                            instance = New <T>(objType, customObjectFactory);
                            _globalObjectCache[objType] = instance;
                        }
                        //}
                        break;

                    default:
                        instance = New <T>(objType, customObjectFactory);
                        break;
                    }

                    if (instance != null)
                    {
                        try
                        {
                            ChoObjectInitializer.Initialize(instance, beforeFieldInit);
                        }
                        catch (TypeInitializationException)
                        {
                            throw;
                        }
                        catch (ChoFatalApplicationException)
                        {
                            throw;
                        }
                        catch (Exception ex)
                        {
                            exception = ex;
                        }
                    }
                }
                finally
                {
                    _globalObjectBuildStateCache[objType] = ObjectBuildState.Constructed;
                }
            }

            return(instance);
        }