Exemplo n.º 1
0
        public void fatalMessageAndException()
        {
            string path = "C:\\UIT";

            System.IO.FileInfo fi            = new System.IO.FileInfo(path + "\\log.txt");
            string             text          = "Log function is OK. Exception is also OK";
            DebugException     ex            = new DebugException("Someone divide 1 by 0");
            string             expectedValue = CurrentUser.Instance.FullName + ". " + DateTime.Now.ToString() + ". " + LogLevel.Fatal.ToString() + ": " + text + ". \r\n" + ex.ToString() + "\r\n";

            FileLogger.getInstance(path, "log.txt", TextFormatter.Instance).fatal(text, ex);

            string actualValue = "";

            using (System.IO.StreamReader file = new System.IO.StreamReader(path + "\\log.txt", true))
            {
                while (!file.EndOfStream)
                {
                    string line = file.ReadLine();
                    actualValue = line;
                    while (line != "")
                    {
                        line         = file.ReadLine();
                        actualValue += "\r\n" + line;
                    }
                }

                file.Close();
            }

            fi.Delete();
            Assert.AreEqual(expectedValue, actualValue);
        }
Exemplo n.º 2
0
        public void canFormatValidLogWithException()
        {
            string    message      = "All is OK";
            string    exMess       = "Exception is OK";
            Exception ex           = new DebugException(exMess);
            string    expectedText = CurrentUser.Instance.FullName + ". " + dateTimeNow.ToString() + ". " + LogLevel.Debug.ToString() + ": " + message + ". \r\n" + ex.ToString();

            Assert.AreEqual(expectedText, formatter.format(new LogData(CurrentUser.Instance, Environment.MachineName, dateTimeNow, LogLevel.Debug, message, ex)));
        }
Exemplo n.º 3
0
        public void canFormatValidLogWithException()
        {
            string    message      = "All is OK";
            string    exMess       = "Exception is OK";
            Exception ex           = new DebugException(exMess);
            string    expectedText = String.Format("<Log>\r\n  <User>{0}</User>\r\n  <Date>{1}</Date>\r\n  <Level>{2}</Level>\r\n  <Message>{3}</Message>\r\n  <Exception Message=\"Exception is OK\">\r\n    <Type>KernelTest.DebugException</Type>\r\n    <StackTrace></StackTrace>\r\n  </Exception>\r\n</Log>", CurrentUser.Instance.FullName, dateTimeNow.ToString(), LogLevel.Debug.ToString(), message);

            //string expectedText = User.Instance.FullName + ". " + DateTime.Now.ToString() + ". " + LogLevel.Debug.ToString() + ": " + message + ". \r\n" + ex.ToString();
            Assert.AreEqual(expectedText, formatter.format(new LogData(CurrentUser.Instance, Environment.MachineName, dateTimeNow, LogLevel.Debug, message, ex)));
        }
Exemplo n.º 4
0
        public static SystemException throwParsePacketException(Exception e, Packet packet)
        {
            SystemException parsePacketException = new ParsePacketException("Unable to parse packet " + packet._PacketName, e);

            if (StaticHandler.Debug)
            {
                parsePacketException = new DebugException("Unable to parse packet data: " + StaticHandler.defaultJsonHandler.toJson(packet), e);
            }

            return(parsePacketException);
        }
Exemplo n.º 5
0
        public void logMessageAndException()
        {
            string         text = "Log function is OK. Exception is OK.";
            DebugException ex   = new DebugException("Debug Exception is OK.");

            logger.log(LogLevel.Debug, text, ex);

            System.Data.DataTable dt = DatabaseContext.Instance.LoadFromDatabase("SELECT TOP 1 * FROM [dbo].[Log] ORDER BY date DESC", System.Data.CommandType.Text);

            Assert.AreEqual("Debug", dt.Rows[0]["level"]);
            Assert.AreEqual(Environment.MachineName, dt.Rows[0]["workstation"]);
            Assert.AreEqual(text, dt.Rows[0]["message"]);
            Assert.IsNotNull(dt.Rows[0]["exception"]);
            Assert.AreEqual(ex.ToString(), dt.Rows[0]["exception"]);
        }
Exemplo n.º 6
0
        public void canFormatValidLogWithExceptionAndTrace()
        {
            string message = "All is OK";
            string exMess  = "Exception is OK";

            try
            {
                DebugException.throwDebugException(exMess);
            }
            catch (Exception ex)
            {
                string expectedText = String.Format("<Log>\r\n  <User>{0}</User>\r\n  <Date>{1}</Date>\r\n  <Level>{2}</Level>\r\n  <Message>{3}</Message>\r\n  <Exception Message=\"{4}\">\r\n    <Type>{5}</Type>\r\n    <StackTrace>{6}</StackTrace>\r\n  </Exception>\r\n</Log>", CurrentUser.Instance.FullName, dateTimeNow.ToString(), LogLevel.Debug.ToString(), message, exMess, ex.GetType(), ex.StackTrace);
                //string expectedText = User.Instance.FullName + ". " + DateTime.Now.ToString() + ". " + LogLevel.Debug.ToString() + ": " + message + ". \r\n" + ex.ToString();
                Assert.AreEqual(expectedText, formatter.format(new LogData(CurrentUser.Instance, Environment.MachineName, dateTimeNow, LogLevel.Debug, message, ex)));
                return;
            }
            Assert.Fail();
        }
Exemplo n.º 7
0
        public void logMessageAndException()
        {
            System.IO.FileInfo fi            = new System.IO.FileInfo(filePath + "\\log.xml");
            string             message       = "Log function is OK. Exception is also OK";
            string             exMess        = "Exception is OK";
            DebugException     ex            = new DebugException(exMess);
            string             expectedValue = String.Format("<Log>\r\n  <User>{0}</User>\r\n  <Date>{1}</Date>\r\n  <Level>{2}</Level>\r\n  <Message>{3}</Message>\r\n  <Exception Message=\"{4}\">\r\n    <Type>{5}</Type>\r\n    <StackTrace>{6}</StackTrace>\r\n  </Exception>\r\n</Log>", CurrentUser.Instance.FullName, DateTime.Now.ToString(), LogLevel.Debug.ToString(), message, exMess, ex.GetType(), ex.StackTrace);

            logger.log(LogLevel.Debug, message, ex);

            string    actualValue = "";
            XDocument xDoc        = XDocument.Load(filePath + "\\log.xml");

            actualValue = xDoc.Root.LastNode.ToString();

            //fi.Delete();
            Assert.AreEqual(expectedValue, actualValue);
        }
Exemplo n.º 8
0
        protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, DebugArgs args, out string error)
        {
#if UNITY_EDITOR
            string message = args.message;

            switch (args.logType)
            {
            case LogType.Error:
                Debug.LogError(message);
                break;

            case LogType.Assert:
                Debug.LogAssertion(message);
                break;

            case LogType.Warning:
                Debug.LogWarning(message);
                break;

            case LogType.Log:
                Debug.Log(message);
                break;

            case LogType.Exception:
                DebugException e = new DebugException(message);
                error = e.ToString();
                Debug.LogException(e);
                return(ActionStatus.Error);

            default:
                break;
            }
#endif
            error = null;
            return(ActionStatus.Continue);
        }
Exemplo n.º 9
0
 private void OnDebugException(DebugExceptionEventArgs e)
 {
     DebugException?.Invoke(this, e);
 }
Exemplo n.º 10
0
 public static void NotImplementedMethod()
 {
     throw DebugException.Wrap(new NotImplementedException());    //Breaks here when debugger is attached
 }
Exemplo n.º 11
0
        public void _doLocalSend(byte[] buffer, int length)
        {
            try
            {
                byte[]  bytes   = buffer.Take(length).ToArray();
                Package package = new Package(bytes);

                Logger.Trace("[{0}] <=== {1}", _connectionInfo.DtuSn, package.ToString());

                if (package.Id == Protocol.ID_HEARTBEAT)
                {
                    HeartBeat heartbeat   = new HeartBeat(package.getPayload());
                    HeartBeat myheartbeat = new HeartBeat();
                    Package   pkg         = new Package(myheartbeat);

                    Logger.Trace("[{0}] ===> {1}", _connectionInfo.DtuSn, pkg.ToString());
                    _socket.Send(pkg.toBytes());
                }
                else if (package.Id == Protocol.ID_CONNECTRESPONSE && !_dtuconnected)
                {
                    ConnectResponse response = new ConnectResponse(package.getPayload());
                    if (response.Result == 0)
                    {
                        //连接成功
                        _dtuconnected = true;
                    }
                    else if (response.Result == 1)
                    {
                        //连接失败
                        if (response.Reason == 1)
                        {
                            //DTU不存在
                            _connectionInfo.Status = (int)RunningStatus.RS_DTUNOTFOUND;
                            Logger.Info("[{0}] dtu:[{1}] not found!", _connectionInfo.DtuSn, _connectionInfo.DtuSn);
                        }
                        else if (response.Reason == 2)
                        {
                            //DTU未在线
                            _connectionInfo.Status = (int)RunningStatus.RS_DTUNOTCONNECTED;
                            Logger.Info("[{0}] dtu:[{1}] not online!", _connectionInfo.DtuSn, _connectionInfo.DtuSn);
                        }
                        else if (response.Reason == 3)
                        {
                            //DTU调试中
                            _connectionInfo.Status = (int)RunningStatus.RS_DTUALREADYDEBUGING;
                            Logger.Info("[{0}] dtu:[{1}] is debugging!", _connectionInfo.DtuSn, _connectionInfo.DtuSn);
                        }
                        else if (response.Reason == 4)
                        {
                            //DTU监控中
                            _connectionInfo.Status = (int)RunningStatus.RS_DTUNOTDEBUGMODE;
                            Logger.Info("[{0}] dtu:[{1}] is monitoring!", _connectionInfo.DtuSn, _connectionInfo.DtuSn);
                        }
                    }
                    _waitdtuconnect = false;
                }
                else if (_dtuconnected)
                {
                    if (package.Id == Protocol.ID_PLCCONNECTRESPONSE && _waitplcconnect)
                    {
                        PlcConnectResponse response = new PlcConnectResponse(package.getPayload());
                        if (response.Result == 0)
                        {
                            //连接成功
                            _plcconnected = true;
                        }
                        else if (response.Result == 1)
                        {
                        }
                        _waitplcconnect = false;
                    }
                    else if (_plcconnected)
                    {
                        if (package.Id == Protocol.ID_PASSTHROUGH)
                        {
                            PassThrough passthrough = new PassThrough(package.getPayload());

                            MonitorDataManager.instance.Add(_connectionInfo.DtuSn, passthrough.Data, MonitorDataType.MDT_NET);

                            _connector.Send(passthrough.Data, passthrough.Data.Length);

                            Logger.Debug("passthrough: {0}", passthrough.ToString());
                        }
                        if (package.Id == Protocol.ID_COMPASSTHROUGH)
                        {
                            ComPassThrough compassthrough = new ComPassThrough(package.getPayload());

                            MonitorDataManager.instance.Add(_connectionInfo.DtuSn, compassthrough.Data, MonitorDataType.MDT_NET);

                            _connector.Send(compassthrough.Data, compassthrough.Data.Length);

                            Logger.Debug("passthrough: {0}", compassthrough.ToString());
                        }
                        else if (package.Id == Protocol.ID_DEBUGEXCEPTION)
                        {
                            DebugException exception = new DebugException(package.getPayload());
                            if (exception.Reason == 1)
                            {
                                _dtuconnected = false;
                                //DTU监控中
                                _connectionInfo.Status = (int)RunningStatus.RS_CONNECTBREAK;
                                Logger.Info("[{0}] connection break!", _connectionInfo.DtuSn);
                            }


                            Logger.Debug("DebugException: {0}", exception.ToString());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.ToString());
            }
        }
Exemplo n.º 12
0
 public override void OnException(DebugThread thread, DebugException exception)
 {
     form.HighlightCurrentInstruction(thread);
 }