Ejemplo n.º 1
0
        public ConfigCatalog LoadCatalogForModule(ModuleIdentifier module)
        {
            var dir     = optionsMonitor.CurrentValue.Source;
            var catalog = new ConfigCatalog()
            {
                ModuleInfo = new ModuleInfo()
                {
                    Identifier = module
                }
            };

            var basename = Path.Combine(dir, module.ToString());

            if (File.Exists(basename + ".json"))
            {
                logger.LogTrace($"load catalog file [{basename}.json]");
                string content = File.ReadAllText(basename + ".json");
                catalog = JsonConvert.DeserializeObject <ConfigCatalog>(content);
            }
            if (Directory.Exists(basename))
            {
                logger.LogTrace($"load catalog dir [{basename}]");
                var sections = new List <ConfigCatalog.Section>();
                foreach (var file in Directory.GetFiles(basename))
                {
                    logger.LogTrace($"-> loading {file}");
                    if (Path.GetExtension(file).ToLower() != ".json")
                    {
                        break;
                    }
                    string content = File.ReadAllText(file);
                    if (Path.GetFileNameWithoutExtension(file) == "moduleinfo")
                    {
                        catalog.ModuleInfo = JsonConvert.DeserializeObject <ModuleInfo>(content);
                    }
                    else
                    {
                        var section = JsonConvert.DeserializeObject <ConfigCatalog.Section>(content);
                        sections.Add(section);
                    }
                }
                catalog.Sections = sections.ToArray();
            }

            return(catalog);
        }
Ejemplo n.º 2
0
        public bool InsertConfigCatalog(ConfigCatalog model)
        {
            using (IDbConnection db = new SqlConnection(connectionString))
            {
                var sql = "insert into ConfigCatalog (CPU, OS, RAM, VideoCard, SizeOnDisc,GameId)" +
                          "values (@CPU, @OS, @RAM,@VideoCard, @SizeOnDisc, @GameId)";
                IEnumerable <ConfigCatalog> models = db.Query <ConfigCatalog>(sql);

                db.Execute(sql, new
                {
                    model.CPU,
                    model.OS,
                    model.RAM,
                    model.VideoCard,
                    model.SizeOnDisc,
                    model.GameId
                });
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool DeleteConfigCatalog(ConfigCatalog model)
        {
            int    id  = model.Id;
            string sql = "select ID from ConfigCatalog ";

            using (IDbConnection db = new SqlConnection(connectionString))
            {
                IEnumerable <ConfigCatalog> models = db.Query <ConfigCatalog>(sql);

                if (models.Count(item => item.Id == id) > 0)
                {
                    return(false);
                }

                sql = "DELETE FROM ConfigCatalog WHERE ID = @Id";
                db.Execute(sql, new
                {
                    model.Id
                });
            }
            return(true);
        }