public void SaveStaticSource(WSSource src) { try { if (!STATIC_SOURCES.Any(s => s.Match(src))) { STATIC_SOURCES.Add(src); } else { STATIC_SOURCES.FirstOrDefault(x => x.Match(src)).Merge(src); } } catch (Exception e) { RegError(GetType(), e, ref LoadStatus); } }
private static bool resetSchema(FileInfo _SRC_CONFIG, WSSources <WSTableSource> _SOURCES) { WSLogRecord Log = new WSLogRecord("RESET SCHEMA"); Log.Add($"RESET SCHEMA START"); Log.Add($"Original schema:[{(_SRC_CONFIG != null ? ("Path:" + _SRC_CONFIG.FullName + ", Exists:" + _SRC_CONFIG.Exists) : "null")}]"); Log.Add($"WSSources:[{((_SOURCES != null && _SOURCES.Any()) ? _SOURCES.Select(s => s.NAME).Aggregate((a, b) => a + "," + b) : "none")}]"); bool done = false; try { if (_SOURCES != null && _SRC_CONFIG != null) { if (!File.Exists(_SRC_CONFIG.FullName) || saveArchive(_SRC_CONFIG, ref Log)) { if (File.Exists(_SRC_CONFIG.FullName)) { _SRC_CONFIG.IsReadOnly = false; Log.Add($"Original schema:[{_SRC_CONFIG.FullName}] set 'ReadOnly' attribute to:[{_SRC_CONFIG.IsReadOnly}]"); } string orgPath = _SRC_CONFIG.FullName; string tempPath = orgPath + ".temp"; using (TextWriter writer = new StreamWriter(tempPath)) { new XmlSerializer(typeof(WSSources <WSTableSource>)).Serialize(writer, _SOURCES); Log.Add($"Temp schema:[{tempPath}] created"); File.Delete(orgPath); Log.Add($"Original schema:[{orgPath}] deleted"); File.Copy(tempPath, orgPath); Log.Add($"Temp schema:[{tempPath}] copied to [{orgPath}]"); _SRC_CONFIG = new FileInfo(orgPath); Log.Add($"Original schema {(_SRC_CONFIG.Exists ? "recreated" : "FAILED recreate")}"); } if (_SRC_CONFIG != null && File.Exists(_SRC_CONFIG.FullName)) { File.Delete(tempPath); Log.Add($"Temp schema {(!File.Exists(tempPath) ? "deleted" : "FAILED to delete")}"); done = true; } } } } catch (Exception e) { Log.Add($"\n-----------------------Exception ------------------------"); Log.Add($"Message:\n{e.Message}"); Log.Add($"StackTrace:\n{e.StackTrace}"); Log.Add($"-----------------------Exception END -------------------\n"); WSStatus status = WSStatus.NONE.clone(); LogError(typeof(WSServerMeta), e, ref status); } ReloadXMLSet[_SRC_CONFIG.Name] = (_SRC_CONFIG != null && File.Exists(_SRC_CONFIG.FullName)) ? _SRC_CONFIG.LastWriteTime.Ticks : ReloadXMLSet[_SRC_CONFIG.Name]; Log.Add($"Schema 'LastModified' set to : [{ReloadXMLSet[_SRC_CONFIG.Name].ToString(WSConstants.DATE_FORMAT)}]"); Log.Add($"RESET SCHEMA DONE"); Log.Save(); return(done); }
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); }