コード例 #1
0
ファイル: DebuggerCore.cs プロジェクト: Knightz/ArmA.Studio
        public void WriteMessage(asapJson.JsonNode node)
        {
            var str = node.ToString();

            Logger.Log(NLog.LogLevel.Info, string.Format("SEND {0}", str));
            var bytes = ASCIIEncoding.UTF8.GetBytes(str);

            this.Pipe.Write(bytes, 0, bytes.Length);
        }
コード例 #2
0
ファイル: DebuggerCore.cs プロジェクト: Knightz/ArmA.Studio
        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 asapJson.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.HaltBreakpoint:
                            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.OnHalt?.Invoke(this, new OnHaltEventArgs()
                                    {
                                        DocumentPath = instruction.GetValue_Object()["filename"].GetValue_String(), Col = col, Line = line
                                    });
                            }
                            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.OnHalt?.Invoke(this, new OnHaltEventArgs()
                                    {
                                        DocumentPath = error.GetValue_Object()["filename"].GetValue_String(), Col = col, Line = line
                                    });
                            }
                            break;

                            case ERecvCommands.HaltScriptAssert:
                            case ERecvCommands.HaltScriptHalt:
                            {
                                var callstack      = this.LastCallstack = node.GetValue_Object()["callstack"];
                                var error          = node.GetValue_Object()["halt"];
                                var fileOffsetNode = error.GetValue_Object()["fileOffset"];
                                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.OnHalt?.Invoke(this, new OnHaltEventArgs()
                                    {
                                        DocumentPath = error.GetValue_Object()["filename"].GetValue_String(), Col = col, Line = line
                                    });
                            }
                            break;

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

                            default:
                                this.Messages.Add(node);
                                break;
                            }
                        }
                    }
                    Thread.Sleep(10);
                }
            }
            catch (ObjectDisposedException) { }
        }