Example #1
0
        private void Thread_ReadPipeMessage()
        {
            try
            {
                var buffer = new byte[2048];
                while (this.Pipe.IsConnected)
                {
                    var builder = new StringBuilder();
                    do
                    {
                        var ammount = this.Pipe.Read(buffer, 0, buffer.Length);
                        for (int i = 0; i < ammount; i++)
                        {
                            builder.Append((char)buffer[i]);
                        }
                    } while (!this.Pipe.IsMessageComplete);
                    if (builder.Length > 0)
                    {
                        var node = new JsonNode(builder.ToString(), true);
                        Logger.Log(NLog.LogLevel.Info, string.Format("RECV {0}", node.ToString()));
                        if (node.GetValue_Object().ContainsKey("exception"))
                        {
                            this.OnError?.Invoke(this, new OnErrorEventArgs()
                            {
                                Message = node.GetValue_Object()["exception"].GetValue_String()
                            });
                        }
                        else
                        {
                            switch ((ERecvCommands)node.GetValue_Object()["command"].GetValue_Number())
                            {
                            case ERecvCommands.HaltBreakpointInfo:
                            case ERecvCommands.HaltStep:
                            {
                                var callstack      = this.LastCallstack = node.GetValue_Object()["callstack"];
                                var instruction    = node.GetValue_Object()["instruction"];
                                var fileOffsetNode = instruction.GetValue_Object()["fileOffset"];
                                var line           = (int)fileOffsetNode.GetValue_Array()[0].GetValue_Number();
                                var col            = (int)fileOffsetNode.GetValue_Array()[2].GetValue_Number();
                                this.IsHalted = true;
                                this.OnHalt?.Invoke(this, new OnHaltEventArgs(instruction.GetValue_Object()["filename"].GetValue_String(), null, line, col));
                            }
                            break;

                            case ERecvCommands.HaltError:
                            {
                                var callstack      = this.LastCallstack = node.GetValue_Object()["callstack"];
                                var error          = node.GetValue_Object()["error"];
                                var fileOffsetNode = error.GetValue_Object()["fileOffset"];
                                var errorMessage   = error.GetValue_Object()["message"];     //ToDo: display to user
                                var fileContent    = error.GetValue_Object()["content"];     //File content in case we don't have that file
                                var line           = (int)fileOffsetNode.GetValue_Array()[0].GetValue_Number();
                                var col            = (int)fileOffsetNode.GetValue_Array()[2].GetValue_Number();
                                this.IsHalted = true;
                                this.OnHalt?.Invoke(this, new OnHaltEventArgs(error.GetValue_Object()["filename"].GetValue_String(), fileContent.GetValue_String(), line, col));
                            }
                            break;

                            case ERecvCommands.HaltScriptAssert:
                            case ERecvCommands.HaltScriptHalt:
                            {
                                var callstack      = this.LastCallstack = node.GetValue_Object()["callstack"];
                                var halt           = node.GetValue_Object()["halt"];
                                var fileOffsetNode = halt.GetValue_Object()["fileOffset"];
                                var fileContent    = halt.GetValue_Object()["content"];     //File content in case we don't have that file
                                var line           = (int)fileOffsetNode.GetValue_Array()[0].GetValue_Number();
                                var col            = (int)fileOffsetNode.GetValue_Array()[2].GetValue_Number();
                                this.IsHalted = true;
                                this.OnHalt?.Invoke(this, new OnHaltEventArgs(halt.GetValue_Object()["filename"].GetValue_String(), null, line, col));
                            }
                            break;

                            case ERecvCommands.ContinueExecution:
                            {
                                this.IsHalted = false;
                                this.OnContinue?.Invoke(this, new OnContinueEventArgs()
                                    {
                                    });
                            }
                            break;

                            default:
                                this.Messages.Add(node);
                                break;
                            }
                        }
                    }
                    Thread.Sleep(10);
                }
            }
            catch (ObjectDisposedException) { }
            catch (Exception ex) { Virtual.ShowOperationFailedMessageBox(ex); }
        }
Example #2
0
        private void Thread_ReadPipeMessage()
        {
            try
            {
                var buffer = new byte[2048];
                while (this.Pipe.IsConnected)
                {
                    var builder = new StringBuilder();
                    do
                    {
                        var ammount = this.Pipe.Read(buffer, 0, buffer.Length);
                        builder.Append(Encoding.Default.GetString(buffer, 0, ammount));
                    }while (!this.Pipe.IsMessageComplete);
                    if (builder.Length > 0)
                    {
                        var msg = builder.ToString();
                        Logger.Log(NLog.LogLevel.Info, String.Format("RECV {0}", msg));
                        dynamic       token   = Newtonsoft.Json.Linq.JToken.Parse(msg);
                        ERecvCommands command = token.command;
                        switch (command)
                        {
                        case ERecvCommands.VersionInfo:
                            break;

                        case ERecvCommands.ContinueExecution:
                            this.IsHalted = false;
                            this.OnContinue?.Invoke(this, new OnContinueEventArgs()
                            {
                            });
                            break;

                        case ERecvCommands.Halt_breakpoint:
                        case ERecvCommands.Halt_step:
                        case ERecvCommands.Halt_error:
                        case ERecvCommands.Halt_scriptAssert:
                        case ERecvCommands.Halt_scriptHalt:
                        {
                            this.LastCallstack = token.callstack;
                            string filename; try { filename = token.halt.filename; } catch { filename = string.Empty; }
                            int    line; try { line = token.halt.fileOffset[0]; } catch { line = 0; }
                            int    col; try { col = token.halt.fileOffset[2]; } catch { col = 0; }
                            string sample; try { sample = token.halt.content; } catch { sample = string.Empty; }
                            this.IsHalted = true;
                            this.OnHalt?.Invoke(this, new OnHaltEventArgs(filename, sample, line, col));
                        }
                        break;

                        case ERecvCommands.Halt_placeholder:
                            break;

                        case ERecvCommands.VariableReturn:
                            this.Messages.Add(token);
                            break;
                        }
                    }
                    Thread.Sleep(10);
                }
            }
            catch (ObjectDisposedException) { }
            catch (Exception ex) { Virtual.ShowOperationFailedMessageBox(ex); }
        }