Esempio n. 1
0
        string ReadLineSub()
        {
            List <byte> rv;

            for (int i = 0; i < StdOutputBuf.Count; ++i)
            {
                byte b;
                b = StdOutputBuf[i];
                if (b == '\r' || b == '\n')
                {
                    var j = i;
                    if (b == '\r')
                    {
                        if (i + 1 < StdOutputBuf.Count && StdOutputBuf[i + 1] == '\n')
                        {
                            ++i;
                        }
                    }
                    lock (lockObj) {
                        rv = StdOutputBuf.GetRange(0, j);
                        StdOutputBuf.RemoveRange(0, i + 1);
                    }
                    string buf = Encoding.UTF8.GetString(rv.ToArray());
                    return(buf);
                    //return Encoding.UTF8.GetString(rv.ToArray());
                }
            }
            return(null);
        }
Esempio n. 2
0
        string ReadString()
        {
            int size = Int32.Parse(ReadLine(), enUS);

            for (int i = 0; i < 15; ++i)
            {
                if (StdOutputBuf.Count >= size)
                {
                    System.Diagnostics.Debug.WriteLine(i);
                    break;
                }
                System.Threading.Thread.Sleep(i < 5 ? 1 : (i < 10 ? 10 : 100));
            }
            if (StdOutputBuf.Count < size)
            {
                System.Threading.Thread.Sleep(100);
            }
            if (StdOutputBuf.Count < size)
            {
                throw new TimeoutException();
            }
            ;
            List <byte> buf;

            lock (lockObj) {
                buf = StdOutputBuf.GetRange(0, size);
                StdOutputBuf.RemoveRange(0, size);
            }
            ReadLine();
            return(Encoding.UTF8.GetString(buf.ToArray()));
        }
Esempio n. 3
0
 public void ClearError()
 {
     error_occured = false;
     error_str     = "";
     lock (lockObj) {
         StdInputBuf.Clear();
         StdOutputBuf.Clear();
     }
 }
Esempio n. 4
0
 void ReadFromStdOutput()
 {
     Properties.Settings.SetCurrentLanguage();
     while (true)
     {
         var b = process.StandardOutput.BaseStream.ReadByte();
         if (b == -1)
         {
             if (process.HasExited)
             {
                 return;
             }
             process.WaitForExit(100);
             b = process.StandardOutput.BaseStream.ReadByte();
         }
         if (b == -1)
         {
             return;
         }
         lock (lockObj) { StdOutputBuf.Add((byte)b); }
     }
 }