public void teste2()
        {
            String text = File.ReadAllText("script2.txt");
            List<String> references = new List<String> { "System.dll", "mscorlib.dll", "test.exe" };
            List<String> imports = new List<String> { "test" };

            Generator GenerateClassCode = new PloobsScripts.Generator(references, imports, "TesteInter");
            GenerateClassCode.GenerateClass("teste", "interteste");

            GenerateClassCode.GenerateMethod("handle", text, typeof(void), System.CodeDom.MemberAttributes.Public);

            String srt = GenerateClassCode.GetCode();

            Console.WriteLine(srt);
            StreamWriter sw = File.CreateText("teste2.cs");
            sw.Write(srt);
            sw.Close();

            String erro;
            Assembly Assembly = Compilers.GenerateAssembly(srt, references, out erro);
            if (erro != null)
            {
                MessageBox.Show(erro);
                return;
            }

            interteste interteste = Executor.BindTypeFromAssembly<interteste>(Assembly, GenerateClassCode.TypeName);

            interteste.handle();

            Console.ReadLine();
        }
        public static Assembly GenerateAssembly(Generator GenerateClassCode, out String errors)
        {
            CSharpCodeProvider csp = new CSharpCodeProvider();

            CompilerParameters cp = new CompilerParameters();
            foreach (var item in GenerateClassCode.References)
            {
                cp.ReferencedAssemblies.Add(item);
            }

            cp.WarningLevel = 3;
            cp.IncludeDebugInformation = false;
            cp.CompilerOptions = "/target:library /optimize";
            cp.GenerateExecutable = false;
            cp.GenerateInMemory = true;
            CompilerResults results = csp.CompileAssemblyFromDom(cp,GenerateClassCode.CodeCompileUnit);
            if (results.Errors.HasErrors)
            {
                string errorMessage = "";
                errorMessage = results.Errors.Count.ToString() + " Errors:";
                for (int x = 0; x < results.Errors.Count; x++)
                {
                    errorMessage = errorMessage + "\r\nLine: " +
                        results.Errors[x].Line.ToString() + " - " + results.Errors[x].ErrorText;
                }
                errors = errorMessage;
            }
            else
            {
                errors = null;
            }
            return results.CompiledAssembly;
        }
Beispiel #3
0
        public void teste4()
        {
            ScriptParsed ScriptParsed = Parser.ParseScriptFile("script4.txt");

            List <String> references = new List <string>()
            {
                "test.exe"
            };

            List <String> usings = new List <string>()
            {
                "test", "System", "System.Collections.Generic"
            };

            usings.AddRange(ScriptParsed.UsingStatements);

            Generator GenerateClassCode = new PloobsScripts.Generator(references, usings, "TesteInter");

            GenerateClassCode.GenerateClass("teste", "interteste");

            GenerateClassCode.GenerateMethod("handle", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public);

            String srt = GenerateClassCode.GetCode(ScriptParsed);

            Console.WriteLine(srt);
            StreamWriter sw = File.CreateText("teste3.cs");

            sw.Write(srt);
            sw.Close();

            String   erro;
            Assembly Assembly = Compilers.GenerateAssembly(srt, references, out erro);

            if (erro != null)
            {
                MessageBox.Show(erro);
                return;
            }

            interteste interteste = Executor.BindTypeFromAssembly <interteste>(Assembly, GenerateClassCode.TypeName);

            interteste.handle();
            interteste.handle();
            interteste.handle();

            Console.ReadLine();
        }
Beispiel #4
0
        public void teste2()
        {
            String        text       = File.ReadAllText("script2.txt");
            List <String> references = new List <String> {
                "System.dll", "mscorlib.dll", "test.exe"
            };
            List <String> imports = new List <String> {
                "test"
            };

            Generator GenerateClassCode = new PloobsScripts.Generator(references, imports, "TesteInter");

            GenerateClassCode.GenerateClass("teste", "interteste");

            GenerateClassCode.GenerateMethod("handle", text, typeof(void), System.CodeDom.MemberAttributes.Public);

            String srt = GenerateClassCode.GetCode();

            Console.WriteLine(srt);
            StreamWriter sw = File.CreateText("teste2.cs");

            sw.Write(srt);
            sw.Close();

            String   erro;
            Assembly Assembly = Compilers.GenerateAssembly(srt, references, out erro);

            if (erro != null)
            {
                MessageBox.Show(erro);
                return;
            }

            interteste interteste = Executor.BindTypeFromAssembly <interteste>(Assembly, GenerateClassCode.TypeName);

            interteste.handle();

            Console.ReadLine();
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            ScriptParsed ScriptParsed = Parser.ParseScriptFile("Content//Script//script.txt");

            ScriptParsed.References.AddRange(new String[] { "IntroductionDemo4.0.exe", "PloobsEngineDebug.dll" });

            ScriptParsed.UsingStatements.AddRange(new String[] { "IntroductionDemo4._0", "System", "System.Collections.Generic", "System.Text"
                                                                 , "PloobsEngine.Engine", "PloobsEngine.Modelo", "PloobsEngine.Physics.Bepu", "PloobsEngine.Material", "PloobsEngine.SceneControl"
                                                                 , "Microsoft.Xna.Framework", "PloobsEngine.Physics", "PloobsEngine.Utils", "PloobsEngine.Light"
                                                                 , "Microsoft.Xna.Framework.Graphics", "PloobsEngine.Cameras", "PloobsEngine.Features", "PloobsEngine.Commands" });

            Generator GenerateClassCode = new PloobsScripts.Generator(ScriptParsed, "TesteInter", true, true);

            GenerateClassCode.GenerateClass("teste", "ISceneBuilder");
            GenerateClassCode.GenerateMethod("BuildScene", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Override);
            String srt = GenerateClassCode.GetCode(ScriptParsed);

            String   erro     = null;
            Assembly Assembly = Compilers.GenerateAssembly(srt, ScriptParsed.References, out erro);

            if (erro != null)
            {
                throw new Exception(erro);
            }

            ISceneBuilder interteste = Executor.BindTypeFromAssembly <ISceneBuilder>(Assembly, GenerateClassCode.TypeName);

            interteste.graphicFactory = GraphicFactory;
            interteste.graphicInfo    = GraphicInfo;
            interteste.world          = this.World;
            interteste.renderTechnic  = RenderTechnic;

            interteste.BuildScene();
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo,factory, contentManager);

            ScriptParsed ScriptParsed = Parser.ParseScriptFile("Content//Script//script.txt");
            ScriptParsed.References.AddRange(new String[] {"IntroductionDemo4.0.exe", "PloobsEngineDebug.dll"                
            });

            ScriptParsed.UsingStatements.AddRange(new String[] { "IntroductionDemo4._0" , "System" , "System.Collections.Generic" , "System.Text"
            , "PloobsEngine.Engine", "PloobsEngine.Modelo" , "PloobsEngine.Physics.Bepu", "PloobsEngine.Material", "PloobsEngine.SceneControl"
            , "Microsoft.Xna.Framework" , "PloobsEngine.Physics" , "PloobsEngine.Utils" , "PloobsEngine.Light"
            , "Microsoft.Xna.Framework.Graphics" , "PloobsEngine.Cameras" , "PloobsEngine.Features", "PloobsEngine.Commands"
            });

            Generator GenerateClassCode = new PloobsScripts.Generator(ScriptParsed, "TesteInter",true,true);
            GenerateClassCode.GenerateClass("teste", "ISceneBuilder");
            GenerateClassCode.GenerateMethod("BuildScene", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Override);
            String srt = GenerateClassCode.GetCode(ScriptParsed);
            
            String erro = null;
            Assembly Assembly = Compilers.GenerateAssembly(srt, ScriptParsed.References, out erro);
            if (erro != null)
            {
                throw new Exception(erro);
            }

            ISceneBuilder interteste = Executor.BindTypeFromAssembly<ISceneBuilder>(Assembly, GenerateClassCode.TypeName);

            interteste.graphicFactory = GraphicFactory;
            interteste.graphicInfo = GraphicInfo;
            interteste.world = this.World;
            interteste.renderTechnic = RenderTechnic;

            interteste.BuildScene();            

        }
        public void teste3()
        {
            ScriptParsed ScriptParsed = Parser.ParseScriptFile("script3.txt");

            List<String> references = new List<string>()
            {             
            "test.exe"
            };

            List<String> usings = new List<string>()
            {
                "test"
            };
            usings.AddRange(ScriptParsed.UsingStatements);

            Generator GenerateClassCode = new PloobsScripts.Generator(references,usings, "TesteInter");
            GenerateClassCode.GenerateClass("teste", "interteste");

            GenerateClassCode.GenerateMethod("handle", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public);

            String srt = GenerateClassCode.GetCode(ScriptParsed);

            Console.WriteLine(srt);
            StreamWriter sw = File.CreateText("teste3.cs");
            sw.Write(srt);
            sw.Close();

            String erro;
            Assembly Assembly = Compilers.GenerateAssembly(srt, references, out erro);
            if (erro != null)
            {
                MessageBox.Show(erro);
                return;
            }

            interteste interteste = Executor.BindTypeFromAssembly<interteste>(Assembly, GenerateClassCode.TypeName);

            interteste.handle();

            Console.ReadLine();

        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            ///script to build the scene
            {
                ScriptParsed ScriptParsed = Parser.ParseScriptFile("Content//Script//script.txt");
                ScriptParsed.References.AddRange(new String[] { "IntroductionDemo4.0.exe", "PloobsEngineDebug.dll" });

                ScriptParsed.UsingStatements.AddRange(new String[] { "IntroductionDemo4._0", "System", "System.Collections.Generic", "System.Text"
                                                                     , "PloobsEngine.Engine", "PloobsEngine.Modelo", "PloobsEngine.Physics.Bepu", "PloobsEngine.Material", "PloobsEngine.SceneControl"
                                                                     , "Microsoft.Xna.Framework", "PloobsEngine.Physics", "PloobsEngine.Utils", "PloobsEngine.Light"
                                                                     , "Microsoft.Xna.Framework.Graphics", "PloobsEngine.Cameras", "PloobsEngine.Features", "PloobsEngine.Commands" });


                Generator GenerateClassCode = new PloobsScripts.Generator(ScriptParsed, "TesteInter", true, true);
                GenerateClassCode.GenerateClass("teste", "ISceneBuilder");
                GenerateClassCode.GenerateMethod("BuildScene", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Override);
                String srt = GenerateClassCode.GetCode(ScriptParsed);

                String   erro     = null;
                Assembly Assembly = Compilers.GenerateAssembly(srt, ScriptParsed.References, out erro);
                if (erro != null)
                {
                    throw new Exception(erro);
                }

                ISceneBuilder interteste = Executor.BindTypeFromAssembly <ISceneBuilder>(Assembly, GenerateClassCode.TypeName);

                interteste.graphicFactory = GraphicFactory;
                interteste.graphicInfo    = GraphicInfo;
                interteste.world          = this.World;
                interteste.renderTechnic  = RenderTechnic;

                interteste.BuildScene();
            }

            ///script to handle messages
            {
                ScriptParsed ScriptParsed = Parser.ParseScriptFile("Content//Script//talk1.txt");
                ScriptParsed.References.AddRange(new String[] { "IntroductionDemo4.0.exe", "PloobsEngineDebug.dll" });

                ScriptParsed.UsingStatements.AddRange(new String[] { "IntroductionDemo4._0", "System", "System.Collections.Generic", "System.Text"
                                                                     , "PloobsEngine.Engine", "PloobsEngine.Modelo", "PloobsEngine.Physics.Bepu", "PloobsEngine.Material", "PloobsEngine.SceneControl"
                                                                     , "Microsoft.Xna.Framework", "PloobsEngine.Physics", "PloobsEngine.Utils", "PloobsEngine.Light"
                                                                     , "Microsoft.Xna.Framework.Graphics", "PloobsEngine.Cameras", "PloobsEngine.MessageSystem", "PloobsEngine.Features", "PloobsEngine.Commands" });

                Generator GenerateClassCode = new PloobsScripts.Generator(ScriptParsed, "IntroductionDemo4._0", true, true);
                GenerateClassCode.GenerateClass("talk", "InterScriptTalking");
                GenerateClassCode.GenerateMethod("execute", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Override);
                String srt = GenerateClassCode.GetCode(ScriptParsed);

                String   erro     = null;
                Assembly Assembly = Compilers.GenerateAssembly(srt, ScriptParsed.References, out erro);
                if (erro != null)
                {
                    throw new Exception(erro);
                }

                interteste = Executor.BindTypeFromAssembly <InterScriptTalking>(Assembly, GenerateClassCode.TypeName);

                interteste.graphicFactory = GraphicFactory;
                interteste.graphicInfo    = GraphicInfo;
                interteste.world          = this.World;
                interteste.renderTechnic  = RenderTechnic;

                interteste.execute();
                EntityMapper.getInstance().AddEntity(interteste);

                SystemRecieverMessage            = new SystemRecieverMessage();
                SystemRecieverMessage.OnMessage += new Action <Message>(SystemRecieverMessage_OnMessage);
                EntityMapper.getInstance().AddgrouptagRecieveEntity("teste", SystemRecieverMessage);

                this.BindInput(new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Space,
                                                                       (a) =>
                {
                    ///5000 is the id of the script
                    ///defined inside it =P look talk1.txt
                    MessageDeliver.SendMessage(new Message(-1, 5000, null, Priority.LOW, 0, SenderType.NORMAL, StaticRandom.PickRandomPoint(new Vector3(100, 100, 100), new Vector3(200, 100, 200), new Vector3(-100, 100, -100)), null));
                }
                                                                       ));
            }
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            ///script to build the scene
            {
                ScriptParsed ScriptParsed = Parser.ParseScriptFile("Content//Script//script.txt");
                ScriptParsed.References.AddRange(new String[] { "EngineTestes.exe", "PloobsEngine.dll" });
            

                ScriptParsed.UsingStatements.AddRange(new String[] { "EngineTestes.Scripts" , "System" , "System.Collections.Generic" , "System.Text"
            , "PloobsEngine.Engine", "PloobsEngine.Modelo" , "PloobsEngine.Physics.Bepu", "PloobsEngine.Material", "PloobsEngine.SceneControl"
            , "Microsoft.Xna.Framework" , "PloobsEngine.Physics" , "PloobsEngine.Utils" , "PloobsEngine.Light"
            , "Microsoft.Xna.Framework.Graphics" , "PloobsEngine.Cameras" , "PloobsEngine.Features", "PloobsEngine.Commands"});
            

                Generator GenerateClassCode = new PloobsScripts.Generator(ScriptParsed, "TesteInter", true, true);
                GenerateClassCode.GenerateClass("teste", "ISceneBuilder");
                GenerateClassCode.GenerateMethod("BuildScene", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Override);
                String srt = GenerateClassCode.GetCode(ScriptParsed);

                String erro = null;
                Assembly Assembly = Compilers.GenerateAssembly(srt, ScriptParsed.References, out erro);
                if (erro != null)
                {
                    throw new Exception(erro);
                }

                ISceneBuilder interteste = Executor.BindTypeFromAssembly<ISceneBuilder>(Assembly, GenerateClassCode.TypeName);

                interteste.graphicFactory = GraphicFactory;
                interteste.graphicInfo = GraphicInfo;
                interteste.world = this.World;
                interteste.renderTechnic = RenderTechnic;

                interteste.BuildScene();
            }




            ///script to handle messages
            {
                ScriptParsed ScriptParsed = Parser.ParseScriptFile("Content//Script//talk1.txt");
                ScriptParsed.References.AddRange(new String[] {"EngineTestes.exe", "PloobsEngine.dll"});

                ScriptParsed.UsingStatements.AddRange(new String[] { "EngineTestes.Scripts" , "System" , "System.Collections.Generic" , "System.Text"
            , "PloobsEngine.Engine", "PloobsEngine.Modelo" , "PloobsEngine.Physics.Bepu", "PloobsEngine.Material", "PloobsEngine.SceneControl"
            , "Microsoft.Xna.Framework" , "PloobsEngine.Physics" , "PloobsEngine.Utils" , "PloobsEngine.Light"
            , "Microsoft.Xna.Framework.Graphics" , "PloobsEngine.Cameras" , "PloobsEngine.Features", "PloobsEngine.Commands", "PloobsEngine.MessageSystem"
            , "EngineTestes.Scripts" });

                Generator GenerateClassCode = new PloobsScripts.Generator(ScriptParsed, "talking", true, true);
                GenerateClassCode.GenerateClass("talk", "InterScriptTalking");
                GenerateClassCode.GenerateMethod("execute", ScriptParsed.MethodCode, typeof(void), System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Override);
                String srt = GenerateClassCode.GetCode(ScriptParsed);

                String erro = null;
                Assembly Assembly = Compilers.GenerateAssembly(srt, ScriptParsed.References, out erro);
                if (erro != null)
                {
                    throw new Exception(erro);
                }

                InterScriptTalking interteste = Executor.BindTypeFromAssembly<InterScriptTalking>(Assembly, GenerateClassCode.TypeName);

                interteste.graphicFactory = GraphicFactory;
                interteste.graphicInfo = GraphicInfo;
                interteste.world = this.World;
                interteste.renderTechnic = RenderTechnic;

                interteste.execute();
                EntityMapper.getInstance().AddEntity(interteste);

                SystemRecieverMessage = new SystemRecieverMessage(SenderType.NORMAL);
                SystemRecieverMessage.OnMessage += new Action<Message>(SystemRecieverMessage_OnMessage);
                EntityMapper.getInstance().AddgrouptagRecieveEntity("teste", SystemRecieverMessage);

                this.BindInput(new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS,Keys.Space,                
                (a) => 
                    {                        
                        ///5000 is the id of the script
                        ///defined inside it =P look talk1.txt
                        MessageDeliver.SendMessage(new Message(-1,5000,null,Priority.LOW,0,SenderType.NORMAL,StaticRandom.PickRandomPoint(new Vector3(100,100,100),new Vector3(200,100,200),new Vector3(-100,100,-100)),null));
                    }
                ));
            }
        }