/// <summary>
        /// 添加全局配置
        /// </summary>
        /// <param name="code">配置编码</param>
        /// <param name="value">配置值</param>
        /// <param name="pCode">上级编码</param>
        /// <param name="desc">配置描述</param>
        /// <param name="cType">配置类型、分类、环境</param>
        /// <param name="st">生效开始时间</param>
        /// <param name="et">生效结束时间</param>
        /// <param name="extVal">扩展值</param>
        /// <param name="isAdd">是否是添加操作</param>
        /// <returns></returns>
        public static long Set(string code, string value, string pCode = null, string desc = null, string cType = null, DateTime?st = null, DateTime?et = null, string extVal = null, bool isAdd = false)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                throw new Exception("配置编码不可为空");
            }
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new Exception("配置值不可为空");
            }

            var ac = new AtomConfig
            {
                ConfigCode  = code,
                ConfigValue = value,
                ParentCode  = pCode,
                ConfigDesc  = desc,
                ConfigType  = string.IsNullOrWhiteSpace(cType) ? "default" : cType,
                ExtValue    = extVal,
                StartTime   = st,
                EndTime     = et,
                AddTime     = DateTime.Now,
                Enable      = true
            };

            return(AtomConfigCenterManage.Set(ac, isAdd));
        }
        //TODO: 添加上下级,阻止无限递归
        public static long Set(AtomConfig ac, bool isAdd)
        {
            lock (locker)
            {
                var exist = SonFact.Cur.Top <AtomConfig>(t => t.ConfigCode == ac.ConfigCode);
                if (exist != null && isAdd)
                {
                    throw new Exception("code 已经存在");
                }
                if (exist != null && !isAdd)
                {
                    ac.ConfigId = exist.ConfigId;
                    var result = SonFact.Cur.Update(ac);
                    return(Convert.ToInt64(result));
                }

                return(SonFact.Cur.Insert(ac));
            }
        }
Beispiel #3
0
    public void Init()
    {
        Config = new GameConfig();

        rawAtoms = new AtomConfig();
        rawAtoms.Load();
        Atoms         = rawAtoms.atoms;
        AtomsBySymbol = rawAtoms.AtomsBySymbol;

        rawUser = new UserConfig();
        rawUser.Load();
        User = rawUser.userModel;

        rawRecipes = new RecipeConfig();
        rawRecipes.Load(AtomsBySymbol);
        Recipes = rawRecipes.Data;

        AMM = new AtomsModelManager();
        AMM.Setup(this);

        Messenger.Dispatch(GameMessage.MODEL_LOADED);
    }
Beispiel #4
0
        protected override IEnumerable <GeneratorResult> Generate()
        {
            AtomConfig config = TryLoadAtomConfig();

            if (config == null)
            {
                yield break;
            }

            var sqlConfig    = config.Targets.Values.OfType <SqlTargetConfig>().Single();
            var csharpConfig = config.Targets.Values.OfType <CSharpTargetConfig>().Single();

            var defaults = AtomCreator.LoadDefaults(config.AtomPath);

            var sqlArgs = new GeneratorArguments <SqlTargetConfig>(sqlConfig, config.AtomPath, defaults);
            var args    = new GeneratorArguments <CSharpTargetConfig>(csharpConfig, config.AtomPath, defaults, sqlArgs.Atoms);

            var sqlResult = new SqlGenerator().Generate(sqlArgs);

            sqlResult.OutputPath = sqlConfig.OutputPath;

            //if (Directory.Exists(sqlResult.OutputPath))
            //{
            //    foreach (var file in Directory.EnumerateFiles(sqlResult.OutputPath, "*.generated.sql", SearchOption.AllDirectories))
            //    {
            //        sqlResult.Deletions.Add(file);
            //    }
            //}

            string redGateFile = Path.Combine(sqlConfig.OutputPath, "RedGateDatabaseInfo.xml");

            Log.Information("Looking for redgate database info xml at {RedGateDatabaseInfoXml}", redGateFile);


            if (sqlResult.DataFiles.Any() &&
                File.Exists(redGateFile))
            {
                Log.Information("Found redgate file, updating...");

                var regate       = XDocument.Load(uri: redGateFile);
                var dataFiles    = regate.Root.Elements("DataFileSet").First();
                var allDataFiles = dataFiles.Elements("DataFile")
                                   .Select(n => n.Value).Union(sqlResult.DataFiles, StringComparer.OrdinalIgnoreCase).ToList();

                dataFiles.Elements("Count")
                .First()
                .Value = allDataFiles.Count().ToString();

                Log.Information("DataFiles Count: {DataFileCount}", allDataFiles.Count());

                dataFiles.Elements("DataFile").Remove();

                dataFiles.Add(allDataFiles.Select(s => new XElement("DataFile", s)));

                var genResult = new GeneratorResult()
                {
                    OutputPath = sqlConfig.OutputPath
                };

                genResult.AddOutput("RedGateDatabaseInfo.xml", regate.ToString());

                yield return(genResult);
            }

            yield return(sqlResult);

            if (csharpConfig.Repository != null)
            {
                var repoResult = new RepositoryGenerator(sqlResult).Generate(args);

                repoResult.OutputPath = csharpConfig.Repository.OutputPath;

                yield return(repoResult);
            }

            var codeResult = new CodeGenerator().Generate(args);

            codeResult.OutputPath = csharpConfig.Entities.OutputPath;

            yield return(codeResult);
        }