Example #1
0
        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);
        }
Example #2
0
        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));
                    }
                }
            }
        }
Example #3
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));
            }
        }
Example #4
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);
        }
        public void Initialize(bool beforeInit)
        {
            //Create the default/built-in objects
            _logFormatters = new ChoDictionary <string, IChoLogFormatter>(DefaultLogFormatters);

            ChoObjConfigurable.Load <IChoLogFormatter>(typeof(ChoLogFormatterSettings).Name, ChoType.GetTypes(typeof(ChoLogFormatterAttribute)),
                                                       _logFormatters, LogFormatterTypes);
        }
Example #6
0
 public static void Load <T>(string logFileName, Type type, ChoDictionary <string, T> objDictionary,
                             ChoObjConfigurable[] objTypeConfigurables, ChoTypeNameSpecifier defaultObjectKey) where T : class
 {
     if (type == null)
     {
         return;
     }
     Load <T>(logFileName, new Type[] { type }, objDictionary, objTypeConfigurables, defaultObjectKey);
 }
Example #7
0
 public void Initialize(bool beforeInit)
 {
     _logManagers = new ChoDictionary <string, IChoLogManager>(DefaultLogManagers);
     if (!beforeInit)
     {
         ChoObjConfigurable.Load <IChoLogManager>(typeof(ChoLogManagerSettings).Name, ChoType.GetTypes(typeof(ChoLogManagerAttribute)),
                                                  _logManagers, LogManagerTypes);
     }
 }
Example #8
0
 public static void Load <T>(string logFileName, string typeName, ChoDictionary <string, T> objDictionary,
                             ChoObjConfigurable[] objTypeConfigurables, ChoTypeNameSpecifier defaultObjectKey) where T : class
 {
     if (String.IsNullOrEmpty(typeName))
     {
         return;
     }
     Load <T>(logFileName, new string[] { typeName }, objDictionary, objTypeConfigurables, defaultObjectKey);
 }
Example #9
0
        public bool Initialize(bool beforeFieldInit, object state)
        {
            //Create the default/built-in objects
            _validationManagers = new ChoDictionary <string, IChoValidationManager>(DefaultValidationManagers);

            //ChoObjConfigurable.Load<IChoValidationManager>(ChoType.GetLogFileName(typeof(ChoValidationManagerSettings)), ChoType.GetTypes(typeof(ChoValidationManagerAttribute)),
            //    _validationManagers, ValidationManagerTypes);

            return(false);
        }
Example #10
0
        public bool Initialize(bool beforeFieldInit, object state)
        {
            _logManagers = new ChoDictionary <string, IChoLogManager>(DefaultLogManagers);
            if (!beforeFieldInit)
            {
                ChoObjConfigurable.Load <IChoLogManager>(ChoType.GetLogFileName(typeof(ChoLogManagerSettings)), ChoType.GetTypes(typeof(ChoLogManagerAttribute)),
                                                         _logManagers, LogManagerTypes);
            }

            return(false);
        }
        public bool Initialize(bool beforeFieldInit, object state)
        {
            lock (_padLock)
            {
                _configStorages = new ChoDictionary <string, IChoConfigStorage>(DefaultConfigStorages);
                //if (!beforeFieldInit)
                //    ChoObjConfigurable.Load<IChoConfigStorage>(ChoType.GetLogFileName(typeof(ChoConfigStorageManagerSettings)), ChoType.GetTypes(typeof(ChoConfigStorageAttribute)),
                //        _configStorages, ConfigStorageTypes);

                return(false);
            }
        }
Example #12
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));
                    }
                }
            }
        }
Example #13
0
        public void Log(ChoLogEntry message)
        {
            ChoDictionary <string, ChoLogListener[]> logListeners = ChoLoggerSettings.Me.Find(message.Categories);

            foreach (string key in logListeners.Keys)
            {
                if (logListeners[key] != null)
                {
                    foreach (ChoLogListener logListener in logListeners[key])
                    {
                        logListener.TraceData(new TraceEventCache(), key, message.Severity, 100, message.Message);
                    }
                }
            }
        }
Example #14
0
        public bool Initialize(bool beforeFieldInit, object state)
        {
            if (beforeFieldInit)
            {
                //Create the default/built-in objects
                _logListeners = new ChoDictionary <string, ChoLogListener>(DefaultLogListeners);
            }
            else
            {
                ChoObjConfigurable.Load <ChoLogListener>(ChoType.GetLogFileName(typeof(ChoLogListenerSettings)), ChoType.GetTypes(typeof(ChoLogListenerAttribute)),
                                                         _logListeners, LogListenerTypes);
            }

            return(false);
        }
Example #15
0
        public static void Load <T>(string logFileName, Type[] types, ChoDictionary <string, T> objDictionary,
                                    ChoObjConfigurable[] objTypeConfigurables, ChoTypeNameSpecifier defaultObjectKey) where T : class
        {
            ChoGuard.ArgumentNotNull(logFileName, "LogFileName");
            ChoGuard.ArgumentNotNull(objDictionary, "ObjectDictionary");

            if (types == null || types.Length == 0)
            {
                return;
            }

            foreach (Type type in types)
            {
                Add <T>(logFileName, objDictionary, defaultObjectKey, type.SimpleQualifiedName());
            }

            Adjust <T>(logFileName, objDictionary, objTypeConfigurables, defaultObjectKey);
        }
Example #16
0
        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);
        }
Example #17
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));
        }
Example #18
0
        public static void Load <T>(string logFileName, string[] typeNames, ChoDictionary <string, T> objDictionary,
                                    ChoObjConfigurable[] objTypeConfigurables, ChoTypeNameSpecifier defaultObjectKey) where T : class
        {
            ChoGuard.ArgumentNotNull(logFileName, "LogFileName");
            ChoGuard.ArgumentNotNull(objDictionary, "ObjectDictionary");

            if (typeNames == null || typeNames.Length == 0)
            {
                return;
            }

            foreach (string typeName in typeNames)
            {
                if (String.IsNullOrEmpty(typeName))
                {
                    continue;
                }
                Add <T>(logFileName, objDictionary, defaultObjectKey, typeName);
            }
            Adjust <T>(logFileName, objDictionary, objTypeConfigurables, defaultObjectKey);
        }
Example #19
0
        public bool Initialize(bool beforeFieldInit, object state)
        {
            if (beforeFieldInit)
            {
                return(false);
            }

            //REVISIT
            //ChoProfile.InitializeProfile(GetType());

            ChoDictionary <string, string> typeShortNameMap = ChoDictionary <string, string> .Synchronized(new ChoDictionary <string, string>());

            using (ChoBufferProfileEx errProfile = ChoBufferProfileEx.DelayedAutoStart(new ChoBufferProfileEx(true, ChoPath.AddExtension(typeof(ChoTypeFactory).FullName, ChoReservedFileExt.Err), "Below are the duplicate type short names founds...")))
            {
                foreach (Type type in ChoType.GetTypes(typeof(ChoTypeShortNameAttribute)))
                {
                    ChoTypeShortNameAttribute typeShortNameAttribute = ChoType.GetAttribute <ChoTypeShortNameAttribute>(type);
                    AddToMap(typeShortNameMap, errProfile, type, typeShortNameAttribute.Name, false);
                }
                if (ChoShortTypeNameSettings.Me.ValidTypsShortNames != null)
                {
                    foreach (ChoTypsShortName typsShortName in ChoShortTypeNameSettings.Me.ValidTypsShortNames)
                    {
                        if (typsShortName.Type == null)
                        {
                            continue;
                        }
                        AddToMap(typeShortNameMap, errProfile, typsShortName.Type, typsShortName.TypeShortName, typsShortName.Override);
                    }
                }
            }
            lock (_padLock)
            {
                _typeShortNameMap = typeShortNameMap;
            }

            return(false);
        }
Example #20
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);
                    }
                }
            }
        }
        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);
        }
Example #22
0
 public static void Load <T>(string logFileName, Type[] types, ChoDictionary <string, T> objDictionary,
                             ChoObjConfigurable[] objTypeConfigurables) where T : class
 {
     Load <T>(logFileName, types, objDictionary, objTypeConfigurables, ChoTypeNameSpecifier.FullName);
 }
Example #23
0
 public static void Load <T>(string logFileName, string[] typeNames, ChoDictionary <string, T> objDictionary,
                             ChoObjTypeConfigurable[] objTypeConfigurables) where T : class
 {
     Load <T>(logFileName, typeNames, objDictionary, objTypeConfigurables, ChoDefaultObjectKey.FullName);
 }