コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //build code tree(s)
            textBox2.Text = "";

            string[] lines = textBox1.Text.Split('\n');

            for (int i = 0; i < lines.Length; i++)
            {
                string code = "";
                for (int j = 0; j <= i; j++)
                {
                    code += lines[j] + "\r\n";
                }

                CSharpScriptInstance _instance = new CSharpScriptInstance();
                try
                {
                    var answer = _instance.ExecuteRun(code);
                    var state  = (answer as ScriptState <object>);

                    string vars = "";
                    foreach (var key in state.Variables.Names)
                    {
                        vars += key + ":" + state.Variables[key].Value.ToString() + "  ";
                    }

                    textBox2.Text += vars.ToString() + "\r\n";
                }
                catch (Exception ex)
                {
                    textBox2.Text += ex.Message + "\r\n";
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: muskatel/Jellytots
        private static void DataProcessor(object obj)
        {
            Socket handler        = obj as Socket;
            string data           = null; //TEMP: will handle data slightly better when I get to it
            int    totalBytesRecv = 0;

            byte[] bytes = new byte[1024];
            while (true)
            {
                int bytesRecv = handler.Receive(bytes);

                data += Encoding.ASCII.GetString(bytes, 0, bytesRecv);
                if (data.IndexOf("<EOF>") > -1)
                {
                    break;
                }
            }

            string code = data.Replace("<EOF>", "");

            CSharpScriptInstance instance = new CSharpScriptInstance();
            var    ret      = instance.Execute(code);
            bool   compiled = false;
            string message  = "";

            if (ret is Exception)
            {
                if (ret is CompilationErrorException)
                {
                    var compError = ret as CompilationErrorException;
                    message = "Compilation error: " + compError.Message;
                }
                else
                {
                    message = "Other Exception: " + (ret as Exception).ToString();
                }
            }
            else
            {
                compiled = true;
                message  = "Compilation successful.";
            }

            Console.WriteLine("Got: " + data + " \r\n\t[Payload] Result=" + compiled.ToString() + " | messages=" + message);

            handler.Send(Encoding.ASCII.GetBytes((compiled ? "Successfully compiled." : "Did not compile: " + message) + "<EOF>"));
            handler.Shutdown(SocketShutdown.Both);
            handler.Close();
        }