private static WSSources <WSTableSource> LoadMetaSources() { LoadStatusStatic.AddNote($"IOSB.LoadMetaSources()"); WSSources <WSTableSource> ORG_SOURCES = new WSSources <WSTableSource>(); Dictionary <Type, WSDataContext> dbList = new Dictionary <Type, WSDataContext>(); try { if (EntityTypes != null && EntityTypes.Any()) { IEnumerable <string> namespaces_ = EntityTypes.Select(t => t.Namespace).Distinct(); Dictionary <string, List <Type> > nsList = namespaces_.ToDictionary(key => key, val => new List <Type>()); foreach (Type type in EntityTypes) { nsList[type.Namespace].Add(type); } foreach (KeyValuePair <string, List <Type> > ns in nsList) { if (ns.Value.Any()) { foreach (Type type in ns.Value) { try { Type DCType = GetDCTypeByEntityType(type); WSDataContext db = null; if (dbList.Any(x => x.Key == DCType)) { db = dbList.FirstOrDefault(x => x.Key == DCType).Value; } else { db = GetServerContext(DCType, null, $"{typeof(WSServerMeta).Name}.LoadMetaSources() => [{type.FullName}:{DCType.Name}"); dbList.Add(DCType, db); } if (db != null) { string DBName = db.GetType().CustomAttribute <DatabaseAttribute>(true).Name; WSTableSource tSrc = new WSTableSource( type, SecurityMap.FirstOrDefault(m => m.Key.Equals(DBName)).Value.Zone, type.Name, ServerFunctions, WSConstants.ACCESS_LEVEL.READ ); #region READ PROPERTIES List <MetaDataMember> eProps = db.ReadProperties(type, ref LoadStatusStatic); if (eProps != null && eProps.Any()) { List <WSTableParam> _params = new List <WSTableParam>(); foreach (MetaDataMember prop in eProps) { try { WSTableParam tParam = new WSTableParam(type, next_code, prop.Name, new WSColumnRef(prop.Name), prop.Type, ServerFunctions); object[] CustomAttributes = prop.Member.GetCustomAttributes(true); IEnumerable <AssociationAttribute> assAttributes = CustomAttributes.OfType <AssociationAttribute>(); if (assAttributes != null && assAttributes.Any()) { tParam.IsAssociation = true; } IEnumerable <ColumnAttribute> cAttributes = CustomAttributes.OfType <ColumnAttribute>(); if (cAttributes != null && cAttributes.Any()) { tParam.IsColumn = true; if (cAttributes.FirstOrDefault().IsPrimaryKey) { tParam.WRITE_ACCESS_MODE = new WSAccessMode(WSConstants.ACCESS_LEVEL.LOCK, false); if (!tSrc.Params.Any(p => p.Match(WSConstants.PARAMS.RECORD_ID.NAME))) { tParam.DISPLAY_NAME = WSConstants.PARAMS.RECORD_ID.NAME; if (!tParam.ALIACES.Any(a => a.Equals(WSConstants.PARAMS.RECORD_ID.NAME))) { tParam.ALIACES.Add(WSConstants.PARAMS.RECORD_ID.NAME); } } } } _params.Add(tParam); } catch (Exception) { } } tSrc.AddParams(_params); tSrc.ClearDublicatedAliaces(); } #endregion if (!ORG_SOURCES.Any(x => x.Match(tSrc))) { ORG_SOURCES.Add(tSrc); } } } catch (Exception) { } } } } } } catch (Exception) { } finally { foreach (Type t in dbList.Keys) { try { if (dbList[t] != null) { dbList[t].Dispose(); } } catch (Exception e) { } } } return(ORG_SOURCES); }