예제 #1
0
        //used for development, decodes then displays the generated code
        public void GenerateDebug(string inputFileContent, string inputFileName)
        {
            CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider();

            SourceDom source = new SourceDom(new SourceShader(inputFileContent, inputFileName, true), "test", provider);

            string src = source.GenerateCodeString();

            System.Windows.Forms.Clipboard.SetText(src);

            if (src.Length > 8192)
            {
                src = src.Substring(0, 8192);
            }
            System.Windows.Forms.MessageBox.Show(src);
        }
예제 #2
0
        public byte[] GenerateCode(string inputFileName, string inputFileContent, string fileNameSpace, CodeDomProvider codeProvider)
        {
            //make sure the culture is invariant while processing.
            CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                try
                {
                    SourceDom source = new SourceDom(new SourceShader(inputFileContent, inputFileName, true), fileNameSpace, codeProvider);

                    return(Encoding.ASCII.GetBytes(source.GenerateCodeString()));
                }
                catch (CompileExceptionCollection ex)
                {
                    for (int i = 0; i < ex.Count; i++)
                    {
                        CompileException cx = ex.GetException(i);
                        this.GeneratorErrorCallback(false, 1, cx.Text, cx.Line, cx.Coloumn);
                        Console.WriteLine(string.Format("Error generating shader: {0} (line: {1} col: {2}, error {3} of {4})", cx.Text, cx.Line, cx.Coloumn, i + 1, ex.Count));
                    }
                    return(Encoding.ASCII.GetBytes(SourceDom.GenerateErrorString(ex, codeProvider)));
                }
                catch (CompileException ex)
                {
                    this.GeneratorErrorCallback(false, 1, ex.Text, ex.Line, ex.Coloumn);
                    Console.WriteLine(string.Format("Error generating shader: {0} (line: {1} col: {2})", ex.Text, ex.Line, ex.Coloumn));
                    return(Encoding.ASCII.GetBytes(SourceDom.GenerateErrorString(ex, codeProvider)));
                }
                catch (Exception ex)
                {
                    this.GeneratorErrorCallback(false, 1, string.Format("Unhandled exception in XenFX:{0}{1}", Environment.NewLine, ex.ToString()), 0, 0);
                    Console.WriteLine(string.Format("Unhandled exception in XenFX: {0}", ex.ToString()));
                    return(Encoding.ASCII.GetBytes(SourceDom.GenerateErrorString(ex, codeProvider)));
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }