예제 #1
0
        /// <summary>
        /// Creates a <see cref="ScriptTypeCollection"/> with the specified name.
        /// </summary>
        /// <param name="name">Name of the <see cref="ScriptTypeCollection"/>.</param>
        static void CreateScriptTypeCollection(string name)
        {
            if (log.IsInfoEnabled)
            {
                log.InfoFormat("Loading scripts `{0}`.", name);
            }

            string path        = ContentPaths.Build.Data.Join("ServerScripts").Join(name);
            var    scriptTypes = new ScriptTypeCollection(name, path);

            // Display warnings
            if (log.IsWarnEnabled)
            {
                foreach (var warning in scriptTypes.CompilerErrors.Where(x => x.IsWarning))
                {
                    log.Warn(warning);
                }
            }

            // Display errors
            if (log.IsErrorEnabled)
            {
                foreach (var error in scriptTypes.CompilerErrors.Where(x => !x.IsWarning))
                {
                    log.Error(error);
                }
            }

            // Check if the compilation failed
            if (scriptTypes.CompilationFailed && log.IsFatalEnabled)
            {
                log.FatalFormat("Failed to compile scripts for `{0}`!", name);
            }
        }
예제 #2
0
        public static IEnumerable <Type> GetTableTypes(string tableName, Action <MySqlClassGenerator> additionalProcessing = null)
        {
            IEnumerable <GeneratedTableCode> codeItems;

            // Generate
            using (var generator = TestDb.CreateMySqlClassGenerator())
            {
                if (additionalProcessing != null)
                {
                    additionalProcessing(generator);
                }

                generator.TablesToGenerate = new string[] { tableName };

                codeItems = generator.Generate(GeneratedNamespace, GeneratedNamespace);
                codeItems = codeItems.Where(x => x.CodeType != GeneratedCodeType.ClassDbExtensions);
                codeItems =
                    codeItems.Where(
                        x =>
                        x.Table == tableName || x.CodeType == GeneratedCodeType.ColumnMetadata ||
                        x.CodeType == GeneratedCodeType.ColumnCollectionClass).ToImmutable();
            }

            // Get the temp files and write the code to them
            var tempFiles = new List <string>(codeItems.Count());
            ScriptTypeCollection ret;

            try
            {
                foreach (var item in codeItems)
                {
                    var tempFile = Path.GetTempFileName() + ".cs";
                    tempFiles.Add(tempFile);
                    File.WriteAllText(tempFile, item.Code);
                }

                // Generate assembly
                ret = new ScriptTypeCollection("testdb_table_" + tableName, tempFiles);
            }
            finally
            {
                // Delete the temp files
                foreach (var file in tempFiles)
                {
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                }
            }

            return(ret);
        }
예제 #3
0
        public static IEnumerable<Type> GetTableTypes(string tableName, Action<MySqlClassGenerator> additionalProcessing = null)
        {
            IEnumerable<GeneratedTableCode> codeItems;

            // Generate
            using (var generator = TestDb.CreateMySqlClassGenerator())
            {
                if (additionalProcessing != null)
                    additionalProcessing(generator);

                generator.TablesToGenerate = new string[] { tableName };

                codeItems = generator.Generate(GeneratedNamespace, GeneratedNamespace);
                codeItems = codeItems.Where(x => x.CodeType != GeneratedCodeType.ClassDbExtensions);
                codeItems =
                    codeItems.Where(
                        x =>
                        x.Table == tableName || x.CodeType == GeneratedCodeType.ColumnMetadata ||
                        x.CodeType == GeneratedCodeType.ColumnCollectionClass).ToImmutable();
            }

            // Get the temp files and write the code to them
            var tempFiles = new List<string>(codeItems.Count());
            ScriptTypeCollection ret;
            try
            {
                foreach (var item in codeItems)
                {
                    var tempFile = Path.GetTempFileName() + ".cs";
                    tempFiles.Add(tempFile);
                    File.WriteAllText(tempFile, item.Code);
                }

                // Generate assembly
                ret = new ScriptTypeCollection("testdb_table_" + tableName, tempFiles);
            }
            finally
            {
                // Delete the temp files
                foreach (var file in tempFiles)
                {
                    if (File.Exists(file))
                        File.Delete(file);
                }
            }

            return ret;
        }
예제 #4
0
파일: Server.cs 프로젝트: wtfcolt/game
        /// <summary>
        /// Creates a <see cref="ScriptTypeCollection"/> with the specified name.
        /// </summary>
        /// <param name="name">Name of the <see cref="ScriptTypeCollection"/>.</param>
        static void CreateScriptTypeCollection(string name)
        {
            if (log.IsInfoEnabled)
                log.InfoFormat("Loading scripts `{0}`.", name);

            string path = ContentPaths.Build.Data.Join("ServerScripts").Join(name);
            var scriptTypes = new ScriptTypeCollection(name, path);

            // Display warnings
            if (log.IsWarnEnabled)
            {
                foreach (var warning in scriptTypes.CompilerErrors.Where(x => x.IsWarning))
                {
                    log.Warn(warning);
                }
            }

            // Display errors
            if (log.IsErrorEnabled)
            {
                foreach (var error in scriptTypes.CompilerErrors.Where(x => !x.IsWarning))
                {
                    log.Error(error);
                }
            }

            // Check if the compilation failed
            if (scriptTypes.CompilationFailed && log.IsFatalEnabled)
                log.FatalFormat("Failed to compile scripts for `{0}`!", name);
        }