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)); } }
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)); } } } }