示例#1
0
            public ReplBackend(ReplProcessor replProcessor, JSession jSession)
            {
                this._replProc = replProcessor;
                this._COMMANDS = new Dictionary <string, Action>()
                {
                    { "run ", this.CmdRun },
                    { "abrt", this.CmdAbrt },
                    { "exit", this.CmdExit },
                    { "mems", this.CmdMems },
                    { "sigs", this.CmdSigs },
                    { "locs", this.CmdLocs },
                    { "setl", this.CmdSetl },
                    { "sett", this.CmdSett },
                    { "inpl", this.CmdInpl },
                    { "excf", this.CmdExcf },
                    { "dbga", this.CmdDebugAttach }
                };
                this._jSession = jSession;
                this._disposed = false;

                this._conn        = null;
                this._stream      = null;
                this._sendLocker  = new object();
                this._inputLocker = new object();
                this._inputEvent  = new InputLock(this); // lock starts acquired (we use it like a manual reset event)

                this._inputString   = null;
                this._exitRequested = false;
            }
示例#2
0
            /// <summary>
            /// loop on created thread which processes communicates with the REPL window
            /// </summary>
            private void ReplLoop()
            {
                try
                {
                    byte[] inp  = new byte[4];
                    int    size = 0;
                    while (true)
                    {
                        if (this.CheckForExitReplLoop())
                        {
                            break;
                        }

                        /* we receive a series of 4 byte commands. Each command then has it's
                         * own format which we must parse before continuing to the next command. */
                        this.Flush();
                        this._stream.ReadTimeout = 10000; // 10 sec
                        try
                        {
                            size = this._stream.Read(inp, 0, 4);
                        }
                        catch (IOException ex)
                        {
                            SocketException se = null;
                            if (null != ex.InnerException && null != (se = ex.InnerException as SocketException) && SocketError.TimedOut == se.SocketErrorCode)
                            {
#if DEBUG
                                ReplProcessor.DebugWrite("Time out reading from server.");
#endif
                                continue;
                            }
                            throw;
                        }
                        this._stream.ReadTimeout = Timeout.Infinite;

                        if (size < 1)
                        {
                            break;
                        }
                        this.Flush();
                        Action cmd = null;
                        if (this._COMMANDS.TryGetValue(ReplProcessor.Cmd(inp), out cmd))
                        {
                            cmd();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ReplProcessor.DebugWrite("Error in ReplLoop");
                    ReplProcessor.DebugWrite(ex.ToString());
                    this.ExitProcess();
                    Thread.Sleep(2000);   // try and exit gracefully, then interrupt main if necessary
                    Environment.Exit(1);
                    this.InterruptMain(); // will never happen
                }
            }
示例#3
0
            internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession, string locale)
                : base(replProcessor, jSession)
            {
                this._executeItemLocker = new object();

                if (null != locale && string.Empty != locale.Trim())
                {
                    this._jSession.Do(string.Format("18!:4 <'{0}'", locale));
                }
                this._executeItemLock = new ExecuteItemLock(this); // lock starts acquired (we use it like manual reset event)
            }
示例#4
0
 private void Send(params string[] data)
 {
     if (null == data || 0 == data.Length)
     {
         return;
     }
     using (new SendLock(this))
     {
         foreach (var d in data)
         {
             ReplProcessor.DebugWrite(d + '\n');
             this._stream.Write(ReplProcessor.Cmd(d));
         }
     }
 }
示例#5
0
 static ReplBackend()
 {
     _MRES           = ReplProcessor.Cmd("MRES");
     _SRES           = ReplProcessor.Cmd("SRES");
     _LOCS           = ReplProcessor.Cmd("LOCS");
     _IMGD           = ReplProcessor.Cmd("IMGD");
     _PRPC           = ReplProcessor.Cmd("PRPC");
     _RDLN           = ReplProcessor.Cmd("RDLN");
     _STDO           = ReplProcessor.Cmd("STDO");
     _STDE           = ReplProcessor.Cmd("STDE");
     _DBGA           = ReplProcessor.Cmd("DBGA");
     _DETC           = ReplProcessor.Cmd("DETC");
     _DPNG           = ReplProcessor.Cmd("DPNG");
     _UNICODE_PREFIX = ReplProcessor.Cmd("U");
     _ASCII_PREFIX   = ReplProcessor.Cmd("A");
 }
示例#6
0
            /// <summary>
            /// gets the signatures for the given expression
            /// </summary>
            private void CmdSigs()
            {
                string expression = this.ReadString();
                object sigs       = null;

                try
                {
                    // TODO
                    sigs = this.GetSignatures();
                }
                catch (Exception ex)
                {
                    this.Send("SERR");
                    ReplProcessor.DebugWrite("error in eval");
                    ReplProcessor.DebugWrite(ex.ToString());
                    return;
                }
                using (new SendLock(this))
                {
                    this._stream.Write(ReplBackend._SRES);
                    // TODO
                }
            }
示例#7
0
            /// <summary>
            /// gets the list of members available for the given expression
            /// </summary>
            private void CmdMems()
            {
                string      expression = this.ReadString();
                MemberTuple memberTuple;

                try
                {
                    memberTuple = this.GetMembers(expression);
                }
                catch (Exception ex)
                {
                    this.Send("MERR");
                    ReplProcessor.DebugWrite("error in eval");
                    ReplProcessor.DebugWrite(ex.ToString());
                    return;
                }
                using (new SendLock(this))
                {
                    this._stream.Write(ReplBackend._MRES);
                    this.WriteString(memberTuple.Name);
                    this.WriteMemberDict(memberTuple.InstMembers);
                    this.WriteMemberDict(memberTuple.TypeMembers);
                }
            }
示例#8
0
            public ReplBackend(ReplProcessor replProcessor, JSession jSession)
            {
                this._replProc = replProcessor;
                this._COMMANDS = new Dictionary<string, Action>()
                {
                    { "run ", this.CmdRun },
                    { "abrt", this.CmdAbrt },
                    { "exit", this.CmdExit },
                    { "mems", this.CmdMems },
                    { "sigs", this.CmdSigs },
                    { "locs", this.CmdLocs },
                    { "setl", this.CmdSetl },
                    { "sett", this.CmdSett },
                    { "inpl", this.CmdInpl },
                    { "excf", this.CmdExcf },
                    { "dbga", this.CmdDebugAttach }
                };
                this._jSession = jSession;
                this._disposed = false;

                this._conn = null;
                this._stream = null;
                this._sendLocker = new object();
                this._inputLocker = new object();
                this._inputEvent = new InputLock(this); // lock starts acquired (we use it like a manual reset event)

                this._inputString = null;
                this._exitRequested = false;
            }
示例#9
0
            internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession, string locale)
                : base(replProcessor, jSession)
            {
                this._executeItemLocker = new object();

                if (null != locale && string.Empty != locale.Trim())
                {
                    this._jSession.Do(string.Format("18!:4 <'{0}'", locale));
                }
                this._executeItemLock = new ExecuteItemLock(this); // lock starts acquired (we use it like manual reset event)
            }
示例#10
0
 internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession)
     : this(replProcessor, jSession, null)
 {
 }
示例#11
0
        static int Main(string[] args)
        {
            _programName = JSession.ProgramName;
            _options     = new CmdLineOptions();

            bool showHelp  = false;
            var  optionSet = new OptionSet()
            {
                { "p|port=", "{PORT} to connect to.", (ushort v) => _options.Port = v },
                { "s|server:", "Repl {SERVER} to connect to. Default is 127.0.0.1.", v => _options.Server = v },
                { "f|launch_file:", "{SCRIPT} file to run on startup.", v => _options.LaunchFile = v },
                { "m|mode:", "Interactive {MODE} to use. Defaults to Standard.", v => _options.Backend = v },
                { "a|enable-attach", "Enable attaching the debugger via )attach.\n", v => _options.EnableAttach = v != null },
                { "h|help", "Show this message and exit.", v => showHelp = v != null }
            };

            try
            {
                _options.JOptions = optionSet.Parse(args).ToArray();
                if (showHelp)
                {
                    ShowHelp(optionSet);
                    return(0);
                }
                if (_options.Port < 1)
                {
                    throw new Exception(string.Format("Missing PORT for repl processor client session."));
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.Message);
                System.Console.Error.WriteLine(string.Format("Try '{0} --help' for more information.", _programName));
                return(1);
            }

            try
            {
                using (_jSession = new JSession(_options.JOptions))
                {
                    System.Console.CancelKeyPress += (sender, e) =>
                    {
                        e.Cancel = true;
                        _jSession.IncAdBreak();
                    };
                    _jSession.SetType(JSession.SMCON);
                    throw new NotImplementedException();
                    ReplProcessor.Run(_options, _jSession);
                }
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine();
                System.Console.Error.Write(string.Format("{0}: ", _programName));
                System.Console.Error.WriteLine(ex.ToString());
                return(1);
            }
            return(0);
        }
示例#12
0
 internal BasicReplBackend(ReplProcessor replProcessor, JSession jSession)
     : this(replProcessor, jSession, null)
 {
 }