예제 #1
0
        internal WSSources <T> Merge(List <T> extenders)
        {
            WSSources <T> srcs = new WSSources <T>();

            foreach (T src in this.OfType <T>())
            {
                try
                {
                    T extender = extenders.Single(x => x.Match(src));
                    if (extender != null)
                    {
                        if (src is WSTableSource)
                        {
                            (src as WSTableSource).Merge(extender);
                        }
                        else
                        {
                            src.Merge(extender);
                        }
                        srcs.Add(src);
                    }
                }
                catch (Exception) { }
            }
            return(srcs);
        }
예제 #2
0
 public WSSourceSet(WSSources <WSTableSource> sources)
 {
     foreach (WSTableSource src in sources)
     {
         if (!this.Any(x => x.Key.Equals(src.DBName)))
         {
             this.Add(src.DBName, new WSSources <WSSource>());
         }
         if (this.Any(x => x.Key.Equals(src.DBName) && !x.Value.Any(v => v.NAME.Equals(src.NAME))))
         {
             this[src.DBName].Add(src);
         }
     }
 }
예제 #3
0
 public WSSourceSet(WSSources <WSSource> sources, string _CollectionName)
 {
     foreach (WSSource src in sources)
     {
         if (!this.Any(x => x.Key.Equals(_CollectionName)))
         {
             this.Add(_CollectionName, new WSSources <WSSource>());
         }
         if (this.Any(x => x.Key.Equals(_CollectionName) && !x.Value.Any(v => v.NAME.Equals(src.NAME))))
         {
             this[_CollectionName].Add(src);
         }
     }
 }
예제 #4
0
        private WSSources <WSTableSource> ReadFile(string path)
        {
            WSSources <WSTableSource> sources = null;

            try
            {
                if (File.Exists(path))
                {
                    using (XmlReader reader = XmlReader.Create(path))
                    {
                        sources = (WSSources <WSTableSource>) new XmlSerializer(typeof(WSSources <WSTableSource>)).Deserialize(reader);
                    }
                }
            }
            catch (Exception e) { RegError(GetType(), e, ref LoadStatus); }
            return(sources);
        }
예제 #5
0
        public WSSources <T> Clone(ref WSUserDBSet DBSet, MetaFunctions Func)
        {
            WSSources <T> srcs = new WSSources <T>();

            try
            {
                foreach (T src in this)
                {
                    if (src is WSTableSource)
                    {
                        WSSource tSrc = DBSet == null ? (src as WSTableSource).Clone(Func) : (src as WSTableSource).Clone(Func, DBSet.DBSession.user.role);

                        srcs.Add((T)tSrc);
                    }
                    else
                    {
                        srcs.Add((src as WSSource).Clone(Func, DBSet.DBSession.user.role, false) as T);
                    }
                }
            }
            catch (Exception) { }
            return(srcs);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }