Exemplo n.º 1
0
        //
        // A remote version of Evaluate
        //
        protected override string Evaluate(string input)
        {
            ns.WriteString(input);
            while (true)
            {
                AgentStatus s = (AgentStatus)ns.ReadByte();

                switch (s)
                {
                case AgentStatus.PARTIAL_INPUT:
                    return(input);

                case AgentStatus.ERROR:
                    string err = ns.GetString();
                    Console.Error.WriteLine(err);
                    break;

                case AgentStatus.RESULT_NOT_SET:
                    return(null);

                case AgentStatus.RESULT_SET:
                    string res = ns.GetString();
                    Console.WriteLine(res);
                    return(null);
                }
            }
        }
Exemplo n.º 2
0
        public void RunRepl(NetworkStream s)
        {
            string input = null;

            while (!InteractiveBase.QuitRequested)
            {
                try {
                    string       error_string;
                    StringWriter error_output = new StringWriter();
//					Report.Stderr = error_output;

                    string line = s.GetString();

                    bool   result_set;
                    object result;

                    if (input == null)
                    {
                        input = line;
                    }
                    else
                    {
                        input = input + "\n" + line;
                    }

                    try {
                        input = evaluator.Evaluate(input, out result, out result_set);
                    } catch (Exception e) {
                        s.WriteByte((byte)AgentStatus.ERROR);
                        s.WriteString(e.ToString());
                        s.WriteByte((byte)AgentStatus.RESULT_NOT_SET);
                        continue;
                    }

                    if (input != null)
                    {
                        s.WriteByte((byte)AgentStatus.PARTIAL_INPUT);
                        continue;
                    }

                    // Send warnings and errors back
                    error_string = error_output.ToString();
                    if (error_string.Length != 0)
                    {
                        s.WriteByte((byte)AgentStatus.ERROR);
                        s.WriteString(error_output.ToString());
                    }

                    if (result_set)
                    {
                        s.WriteByte((byte)AgentStatus.RESULT_SET);
                        StringWriter sr = new StringWriter();
                        CSharpShell.PrettyPrint(sr, result);
                        s.WriteString(sr.ToString());
                    }
                    else
                    {
                        s.WriteByte((byte)AgentStatus.RESULT_NOT_SET);
                    }
                } catch (IOException) {
                    break;
                } catch (Exception e) {
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 3
0
Arquivo: repl.cs Projeto: GirlD/mono
		public void RunRepl (NetworkStream s)
		{
			string input = null;

			while (!InteractiveBase.QuitRequested) {
				try {
					string error_string;
					StringWriter error_output = (StringWriter)stderr;

					string line = s.GetString ();
	
					bool result_set;
					object result;
	
					if (input == null)
						input = line;
					else
						input = input + "\n" + line;
	
					try {
						input = evaluator.Evaluate (input, out result, out result_set);
					} catch (Exception e) {
						s.WriteByte ((byte) AgentStatus.ERROR);
						s.WriteString (e.ToString ());
						s.WriteByte ((byte) AgentStatus.RESULT_NOT_SET);
						continue;
					}
					
					if (input != null){
						s.WriteByte ((byte) AgentStatus.PARTIAL_INPUT);
						continue;
					}
	
					// Send warnings and errors back
					error_string = error_output.ToString ();
					if (error_string.Length != 0){
						s.WriteByte ((byte) AgentStatus.ERROR);
						s.WriteString (error_output.ToString ());
						error_output.GetStringBuilder ().Clear ();
					}
	
					if (result_set){
						s.WriteByte ((byte) AgentStatus.RESULT_SET);
						StringWriter sr = new StringWriter ();
						CSharpShell.PrettyPrint (sr, result);
						s.WriteString (sr.ToString ());
					} else {
						s.WriteByte ((byte) AgentStatus.RESULT_NOT_SET);
					}
				} catch (IOException) {
					break;
				} catch (Exception e){
					Console.WriteLine (e);
				}
			}
		}