コード例 #1
0
ファイル: FormMain.cs プロジェクト: xinfushe/CSharpGL
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtCSharpShaderFiles.Text) || this.selectedCSharpShaderFiles == null)
            {
                string message = string.Format("{0}", "Please select a C#Shader file first!");
                MessageBox.Show(message);
                return;
            }

            WorkingSwitch(true);

            WorkerData data = new WorkerData(this.selectedCSharpShaderFiles);
            this.bgWorker.RunWorkerAsync(data);
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: ywscr/CSharpGL2
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtCSharpShaderFiles.Text) || this.selectedCSharpShaderFiles == null)
            {
                string message = string.Format("{0}", "Please select a C#Shader file first!");
                MessageBox.Show(message);
                return;
            }

            WorkingSwitch(true);

            WorkerData data = new WorkerData(this.selectedCSharpShaderFiles);

            this.bgWorker.RunWorkerAsync(data);
        }
コード例 #3
0
ファイル: WorkerResult.cs プロジェクト: benlanaaa/CSharpGL
 public WorkerResult(StringBuilder builder, WorkerData data)
 {
     this.builder = builder;
     this.data    = data;
 }
コード例 #4
0
ファイル: FormMain.cs プロジェクト: ywscr/CSharpGL2
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkerData data        = e.Argument as WorkerData;
            int        fileCount   = data.csharpShaderFiles.Length;
            int        fileIndex   = 1;
            const int  magicNumber = 100;

            WorkerResult result = new WorkerResult(null, data);

            e.Result = result;

            StringBuilder builder = new StringBuilder();

            foreach (var fullname in this.selectedCSharpShaderFiles)
            {
                builder.Append(fileIndex); builder.Append("/"); builder.Append(fileCount);
                builder.Append(": "); builder.AppendLine(fullname);

                FileInfo fileInfo = new FileInfo(fullname);
                string   filename = fileInfo.Name;

                try
                {
                    CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();

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

                    if (cr.Errors.HasErrors)
                    {
                        builder.AppendLine(string.Format("编译错误:{0}", fullname));
                        foreach (CompilerError err in cr.Errors)
                        {
                            Console.WriteLine(err.ErrorText);
                            builder.AppendLine(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(CSShaderCode)))
                            {
                                CSShaderCode   shaderCode     = Activator.CreateInstance(type) as CSShaderCode;
                                SemanticShader semanticShader = shaderCode.GetSemanticShader(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();
                        }
                    }
                }
                catch (Exception ex)
                {
                    string message = string.Format("{0}", ex);
                    builder.AppendLine(message);
                    result.builder = builder;
                }

                if (result.builder != builder)
                {
                    builder.AppendLine("sucessfully done!");
                }
                builder.AppendLine();

                SingleFileProgress thisFileDone = new SingleFileProgress()
                {
                    filename = filename,
                    progress = magicNumber,
                    message  = string.Format("All is done for {0}", fileInfo.Name),
                };
                bgWorker.ReportProgress(fileIndex++ *magicNumber / fileCount, thisFileDone);
            }
        }
コード例 #5
0
ファイル: WorkerResult.cs プロジェクト: xinfushe/CSharpGL
 public WorkerResult(StringBuilder builder, WorkerData data)
 {
     this.builder = builder;
     this.data = data;
 }