<commit_before>﻿using CSharpShaderLanguage;
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CSharpGL.CSSL2GLSL
{
    class Program
    {
        static void Main(string[] args)
        {
            string time = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
            var originalOutput = Console.Out;
            using (TextWriter writer = File.CreateText(string.Format("CSSL2GLSLDump{0}.log", time)))
            {
                Console.SetOut(writer);

                try
                {
                    string directoryName = string.Empty;
                    if (args.Length > 0)
                    {
                        directoryName = args[0];
                    }
                    else
                    {
                        directoryName = Environment.CurrentDirectory;
                    }
                    Console.WriteLine("Directory: {0}", directoryName);
                    string[] files = System.IO.Directory.GetFiles(directoryName, "*.cs",
                        System.IO.SearchOption.AllDirectories);
                    foreach (var fullname in files)
                    {
                        Console.WriteLine("--> Translating {0}", fullname);
                        TranslateCSharpShaderLanguage2GLSL(fullname);
                        Console.WriteLine();
                    }

                    Console.WriteLine("Translation all done!");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            Console.SetOut(originalOutput);
            Console.WriteLine("All done!");
        }

        private static void TranslateCSharpShaderLanguage2GLSL(string fullname)
        {
            CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();

            CompilerParameters objCompilerParameters = new CompilerParameters();
            objCompilerParameters.ReferencedAssemblies.Add("System.dll");
            objCompilerParameters.ReferencedAssemblies.Add("CSharpShaderLanguage.dll");
            objCompilerParameters.GenerateExecutable = false;
            objCompilerParameters.GenerateInMemory = true;
            objCompilerParameters.IncludeDebugInformation = true;
            CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromFile(
                objCompilerParameters, fullname);

            if (cr.Errors.HasErrors)
            {
                Console.WriteLine(string.Format("Compiling Error：{0}", fullname));
                foreach (CompilerError err in cr.Errors)
                {
                    Console.Write("Error: ");
                    Console.WriteLine(err.ErrorText);
                }
            }
            else
            {
                List<SemanticShader> semanticShaderList = new List<SemanticShader>();
                Assembly assembly = cr.CompiledAssembly;
                Type[] types = assembly.GetTypes();
                foreach (var type in types)
                {
                    if (type.IsSubclassOf(typeof(ShaderCode)))
                    {
                        ShaderCode shaderCode = Activator.CreateInstance(type) as ShaderCode;
                        SemanticShader semanticShader = shaderCode.Dump(fullname);
                        semanticShaderList.Add(semanticShader);
                    }
                }

                //var semanticShaderList =
                //    from type in cr.CompiledAssembly.GetTypes()
                //    where type.IsSubclassOf(typeof(ShaderCode))
                //    select (Activator.CreateInstance(type) as ShaderCode).Dump(fullname);

                foreach (var item in semanticShaderList)
                {
                    item.Dump2File();
                    Console.WriteLine("Dump {0} OK!", item.ShaderCode.GetType().Name);
                }
            }
        }
    }
}
<commit_msg>CSSL2GLSL完工后打开<commit_after>﻿using CSharpShaderLanguage;
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CSharpGL.CSSL2GLSL
{
    class Program
    {
        static void Main(string[] args)
        {
            string time = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
            var originalOutput = Console.Out;
            string logName = string.Format("CSSL2GLSLDump{0}.log", time);
            using (TextWriter writer = File.CreateText(logName))
            {
                Console.SetOut(writer);

                try
                {
                    string directoryName = string.Empty;
                    if (args.Length > 0)
                    {
                        directoryName = args[0];
                    }
                    else
                    {
                        directoryName = Environment.CurrentDirectory;
                    }
                    Console.WriteLine("Directory: {0}", directoryName);
                    string[] files = System.IO.Directory.GetFiles(directoryName, "*.cs",
                        System.IO.SearchOption.AllDirectories);
                    foreach (var fullname in files)
                    {
                        Console.WriteLine("--> Translating {0}", fullname);
                        TranslateCSharpShaderLanguage2GLSL(fullname);
                        Console.WriteLine();
                    }

                    Console.WriteLine("Translation all done2!");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            Console.SetOut(originalOutput);
            Console.WriteLine("All done!");

            string logFullname = Path.Combine(Environment.CurrentDirectory, logName);
            Process.Start("explorer", "/select," + logFullname);
        }

        private static void TranslateCSharpShaderLanguage2GLSL(string fullname)
        {
            CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();

            CompilerParameters objCompilerParameters = new CompilerParameters();
            objCompilerParameters.ReferencedAssemblies.Add("System.dll");
            objCompilerParameters.ReferencedAssemblies.Add("CSharpShaderLanguage.dll");
            objCompilerParameters.GenerateExecutable = false;
            objCompilerParameters.GenerateInMemory = true;
            objCompilerParameters.IncludeDebugInformation = true;
            CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromFile(
                objCompilerParameters, fullname);

            if (cr.Errors.HasErrors)
            {
                Console.WriteLine(string.Format("Compiling Error：{0}", fullname));
                foreach (CompilerError err in cr.Errors)
                {
                    Console.Write("Error: ");
                    Console.WriteLine(err.ErrorText);
                }
            }
            else
            {
                List<SemanticShader> semanticShaderList = new List<SemanticShader>();
                Assembly assembly = cr.CompiledAssembly;
                Type[] types = assembly.GetTypes();
                foreach (var type in types)
                {
                    if (type.IsSubclassOf(typeof(ShaderCode)))
                    {
                        ShaderCode shaderCode = Activator.CreateInstance(type) as ShaderCode;
                        SemanticShader semanticShader = shaderCode.Dump(fullname);
                        semanticShaderList.Add(semanticShader);
                    }
                }

                //var semanticShaderList =
                //    from type in cr.CompiledAssembly.GetTypes()
                //    where type.IsSubclassOf(typeof(ShaderCode))
                //    select (Activator.CreateInstance(type) as ShaderCode).Dump(fullname);

                foreach (var item in semanticShaderList)
                {
                    item.Dump2File();
                    Console.WriteLine("Dump {0} OK!", item.ShaderCode.GetType().Name);
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08520976534723869, 'fraction_numerical': 0.0030812988859919414, 'mean_word_length': 1.473329425556858, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4133321', 'n_tokens_mistral': 2050, 'n_tokens_neox': 1878, 'n_words': 352}