DebugResult CreateDebugResult(string message)
        {
            var debugResult = new DebugResult();

            debugResult.Add(new OutputEvent(message));
            return(debugResult);
        }
Beispiel #2
0
 public void WriteLog(DebugResult result)
 {
     try {
         string logContent = FormatResult(result);
         var    logBinaray = Encoding.Default.GetBytes(logContent);
         using (FileStream logFile = new FileStream(logPathName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
         {
             logFile.Seek(0, SeekOrigin.End);
             logFile.Write(logBinaray, 0, logBinaray.Length);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Beispiel #3
0
        public string FormatResult(DebugResult result)
        {
            var           now     = DateTime.Now;
            StringBuilder builder = new StringBuilder();
            string        ipv4    = LocalInfoUtil.GetLocalIPv4();
            string        pcName  = LocalInfoUtil.GetLocalUsername();

            builder.Append("\r\n");
            builder.Append("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\r\n");
            builder.Append("┃******************* Gossip Debug Info *********************\r\n");
            builder.AppendFormat("┃ Operator	:{0}	\r\n", pcName);
            builder.AppendFormat("┃ LocalIP	:{0}	\r\n", ipv4);
            builder.Append("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\r\n");
            //builder.AppendFormat("{0} :\r\n", result.Result);
            try
            {
                viewInfos infos = result.InputViews;
                int       len   = result.InputViews.Views.Count;
                builder.AppendFormat("#####>>>{0}:{1}>>>Begin:\r\n", "IN", result.InputViews.Views.Count);

                for (int i = 0; i < len; i++)
                {
                    string s = result.InputViews.Views[i];
                    builder.Append(s);
                    builder.AppendLine();
                }
                viewInfos outviews = result.OutputViews;
                builder.AppendFormat("#####>>>{0}:{1}>>>Begin:\r\n", "OUT", outviews.Views.Count);
                for (int j = 0; j < outviews.Views.Count; j++)
                {
                    string s = outviews.Views[j];
                    builder.Append(s);
                    builder.AppendLine();
                }
                builder.AppendFormat("############## {0} #############\r\n", now.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            catch (Exception e)
            {
                builder.AppendFormat("Error:{0} \r\n {1}", now.ToString("yyyy-MM-dd HH:mm:ss"), e.Message);
            }

            return(builder.ToString());
        }
Beispiel #4
0
        public override Task <DebugResult> Attach(dynamic args)
        {
            string name      = getString(args, "name");
            var    nameLower = name.ToLower();

            if (nameLower.Contains("unity") && nameLower.Contains("editor"))
            {
                var editorProcess = FindUnityEditorProcess();

                if (editorProcess == null)
                {
                    return(Task.FromResult(new DebugResult(8001, "Could not find Unity editor process", new {})));
                }

                Debugger.Connect(IPAddress.Loopback, GetDebuggerPort(editorProcess));

                var debugResult = new DebugResult();
                debugResult.Add(new OutputEvent("UnityDebug: Attached to Unity editor process '" + editorProcess.ProcessName + "' (" + editorProcess.Id + ")\n"));

                return(Task.FromResult(debugResult));
            }

            return(Task.FromResult(new DebugResult(8002, "Unknown target name '{_name}'. Did you mean 'Unity Editor'?", new { _name = name })));
        }
Beispiel #5
0
        static void Dispatch(Stream inputStream, Stream outputStream)
        {
            V8ServerProtocol protocol = new V8ServerProtocol(inputStream, outputStream);

            protocol.TRACE          = false;
            protocol.TRACE_RESPONSE = false;

            IDebugSession debugSession = null;

            var r = protocol.Start((string command, dynamic args, IResponder responder) => {
                if (args == null)
                {
                    args = new { };
                }

                if (command == "initialize")
                {
                    string adapterID = Utilities.GetString(args, "adapterID");
                    if (adapterID == null)
                    {
                        responder.SetBody(new ErrorResponseBody(new Message(1101, "initialize: property 'adapterID' is missing or empty")));
                        return;
                    }

                    debugSession = EngineFactory.CreateDebugSession(adapterID, (e) => protocol.SendEvent(e.type, e));
                    if (debugSession == null)
                    {
                        responder.SetBody(new ErrorResponseBody(new Message(1103, "initialize: can't create debug session for adapter '{_id}'", new { _id = adapterID })));
                        return;
                    }
                }

                if (debugSession != null)
                {
                    try {
                        DebugResult dr = debugSession.Dispatch(command, args);
                        if (dr != null)
                        {
                            responder.SetBody(dr.Body);

                            if (dr.Events != null)
                            {
                                foreach (var e in dr.Events)
                                {
                                    responder.AddEvent(e.type, e);

                                    var outputEvent = e as OutputEvent;
                                    if (outputEvent != null)
                                    {
                                        Log.Write(outputEvent.output);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e) {
                        responder.SetBody(new ErrorResponseBody(new Message(1104, "error while processing request '{_request}' (exception: {_exception})", new { _request = command, _exception = e.Message })));

                        var message     = string.Format("error while processing request '{0}' (exception: {1})\n{2}", command, e.Message, e);
                        var outputEvent = new OutputEvent(message);

                        responder.AddEvent(outputEvent.type, outputEvent);
                        Log.Write(message);
                    }

                    if (command == "disconnect")
                    {
                        protocol.Stop();
                    }
                }
            }).Result;
        }