Exemple #1
0
 /// <summary>
 /// Add a packet to the log
 /// </summary>
 /// <param name="packet">The packet</param>
 public void AddPacket(LogPacket packet)
 {
     lock (_packets)
     {
         _packets.Add(packet);
     }
 }
Exemple #2
0
        protected override object GetValue(LogPacket p)
        {
            DataNode node = p.Frame.Root.SelectSingleNode(SelectionPath);

            if (node == null)
            {
                node = new StringDataValue("", "");
            }

            if (FormatExpression.IsValid)
            {
                ExpressionResolver          _resolver = new ExpressionResolver(typeof(LogPacket));
                Dictionary <string, object> extras    = new Dictionary <string, object>();
                extras["value"] = node;

                try
                {
                    return(_resolver.Resolve(p, _formatExpression, extras) ?? String.Empty);
                }
                catch (Exception)
                {
                    return(String.Empty);
                }
            }
            else
            {
                return(RawValue ? node.Value : node);
            }
        }
Exemple #3
0
        private void log_AddLogPacket(object sender, LogPacketEventArgs e)
        {
            LogPacket packet = new LogPacket(e);

            if (LogPacketEvent != null)
            {
                PacketLogEventArgs args = new PacketLogEventArgs(packet, sender as NetGraph);

                LogPacketEvent.Invoke(this, args);

                if (args.Filter)
                {
                    packet = null;
                }
                else
                {
                    packet = args.Packet;
                }
            }

            if (packet != null)
            {
                lock (_packetLog)
                {
                    _packetLog.Add(packet);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Add a packet to the input
 /// </summary>
 /// <param name="packet">The packet</param>
 public void AddInputPacket(LogPacket packet)
 {
     lock (_inputPackets)
     {
         _inputPackets.Add(packet);
     }
 }
Exemple #5
0
        private void UpdatePacketDisplay()
        {
            LogPacket p = GetCurrentPacket();

            if (p == null)
            {
                return;
            }

            if (!_newStyleLogViewer)
            {
                frameEditorControl.ReadOnly = ReadOnly;
            }

            frameEditorControl.SetFrame(p.Frame, null, ColorValueConverter.ToColor(p.Color));

            if (p.Frame.IsBasic || (ReadOnly && !_newStyleLogViewer))
            {
                toolStripButtonConvertToBytes.Enabled = false;
            }
            else
            {
                toolStripButtonConvertToBytes.Enabled = true;
            }

            if (_newStyleLogViewer)
            {
                toolStripButtonSave.Enabled   = IsFrameModified();
                toolStripButtonRevert.Enabled = IsFrameModified();
            }

            toolStripLabelPosition.Text = String.Format(CANAPE.Properties.Resources.PacketLogViewerForm_Header, _index + 1,
                                                        _packets.Count, p.Tag, p.Network, p.Timestamp.ToString());
        }
Exemple #6
0
        public static void LogPacket(LogPacket type, PacketServer packet)
        {
            try
            {
                var logFilePath = $"logs/{type}_log-{DateTime.Now:yyyy-M-d}.txt";
                var logFileInfo = new FileInfo(logFilePath);
                var logDirInfo  = new DirectoryInfo(logFileInfo.DirectoryName ?? throw new InvalidOperationException());

                if (!logDirInfo.Exists)
                {
                    logDirInfo.Create();
                }

                using (var fileStream = new FileStream(logFilePath, FileMode.Append))
                {
                    using (var log = new StreamWriter(fileStream))
                    {
                        log.WriteLine(
                            $"[{DateTime.Now:yyyy-M-d H:mm:ss}] OPCode: {(RealmEnums) packet.Opcode} " + // (RealmCMD)
                            $"[Length: {packet.Packet.Length}]");
                        log.Write(Utils.ByteArrayToHex(packet.Packet));
                        log.WriteLine();
                        log.WriteLine();
                    }
                }
            }
            catch (Exception e)
            {
                var trace = new StackTrace(e, true);
                Print(LogType.Error,
                      $"{e.Message}: {e.Source}\n{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
            }
        }
Exemple #7
0
        private LogPacket[] CreatePacketFromSelection()
        {
            LogPacket[] ret = null;

            try
            {
                if (hexBox.CanCopy())
                {
                    long startPos = hexBox.SelectionStart;
                    long length   = hexBox.SelectionLength;

                    if (startPos >= 0)
                    {
                        byte[] data = new byte[length];

                        for (long i = 0; i < length; ++i)
                        {
                            data[i] = _provider.ReadByte(startPos + i);
                        }

                        ret    = new LogPacket[1];
                        ret[0] = new LogPacket("Hex", Guid.NewGuid(), "Hex Copy", new DataFrame(data), ColorValueConverter.FromColor(this.HexColor));
                    }
                }
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            return(ret ?? new LogPacket[0]);
        }
Exemple #8
0
        /// <summary>
        /// Add a simple packet with a tag and a frame
        /// </summary>
        /// <param name="tag">The tag to add</param>
        /// <param name="frame">The frame to add, this will be cloned before putting in log</param>
        /// <returns>The logged packet</returns>
        public LogPacket AddPacket(string tag, DataFrame frame)
        {
            LogPacket ret = new LogPacket(tag, Guid.NewGuid(), "Packet Log", frame.CloneFrame(), ColorValue.White);

            AddPacket(ret);

            return(ret);
        }
Exemple #9
0
 public TextLogInfo(int start, int end, LogPacket packet, LogDataChunk chunk)
 {
     StartPosition = start;
     EndPosition   = end;
     Packet        = packet;
     Chunk         = chunk;
     PacketCount   = 1;
 }
Exemple #10
0
        private LogPacket[] GetSelectedPacket()
        {
            LogPacket[] packets = new LogPacket[1];

            packets[0] = new LogPacket("Text", Guid.NewGuid(), "Text Copy", new DataFrame(ActiveTextAreaControl.SelectionManager.SelectedText), ColorValue.White);

            return(packets);
        }
Exemple #11
0
        /// <summary>
        /// Raise a log event safely
        /// </summary>
        protected virtual void OnLogEvent(LogPacket packet)
        {
            var handler = LogEvent;

            if (handler != null)
            {
                handler(packet);
            }
        }
Exemple #12
0
        private static string GetStartPacketColor(LogPacket packet, bool enable_color)
        {
            if (!enable_color)
            {
                return("");
            }

            ColorValue color = packet.Color;

            return(String.Format("{0}{1}", FormatColor(color, true), FormatColor(PickContrastingColor(color), false)));
        }
Exemple #13
0
 public static string ConvertPacketToString(LogPacket p, bool enable_color)
 {
     using (TextWriter writer = new StringWriter())
     {
         writer.WriteLine(GetHeader(p));
         writer.Write(GetStartPacketColor(p, enable_color));
         writer.Write(ConvertPacketToString(p.Frame));
         writer.WriteLine(GetEndPacketColor(enable_color));
         return(writer.ToString());
     }
 }
Exemple #14
0
        public void PacketCacheTest()
        {
            m_PacketReader.RegisterType(typeof(WrapperPacket));
            m_PacketReader.RegisterType(typeof(LogPacket));
            m_PacketReader.RegisterType(typeof(ThreadInfo));

            //since timestamp length varies by time zone we have to measure it first (sigh..)
            var  timestampLength = DateTimeOffsetSerializedLength();
            bool haveTimeZone    = timestampLength == 12;

            //The first message has to write out a bunch of stuff - definitions, threads, etc.
            LogPacket.Write("message 1", 101, m_PacketWriter);
            Assert.AreEqual(133 + timestampLength, m_MemoryStream.Position,
                            "Serialized value isn't the expected length.  Position is: {1}, expected {0}.\r\nSerialized Value: {2}",
                            m_MemoryStream.Position, 133 + timestampLength, m_MemoryStream.ToArray().ToDisplayString());

            Thread.Sleep(50);

            //having now written that these messages will be smaller because we don't have to write out threads and timestamps are smaller.
            var baseline = m_MemoryStream.Position;

            LogPacket.Write("message 2", 101, m_PacketWriter);
            Assert.AreEqual(haveTimeZone ? 20 : 19, m_MemoryStream.Position - baseline);
            Thread.Sleep(50);

            baseline = m_MemoryStream.Position;
            LogPacket.Write("message 3", 101, m_PacketWriter);
            Assert.AreEqual(haveTimeZone ? 20 : 19, m_MemoryStream.Position - baseline);

            baseline = m_MemoryStream.Position;
            LogPacket.Write("message 1", 101, m_PacketWriter);
            Assert.AreEqual(haveTimeZone ? 20 : 19, m_MemoryStream.Position - baseline);

            m_MemoryStream.Position = 0;

            ThreadInfo threadInfo = (ThreadInfo)m_PacketReader.Read();
            LogPacket  message1   = (LogPacket)m_PacketReader.Read();
            LogPacket  message2   = (LogPacket)m_PacketReader.Read();
            LogPacket  message3   = (LogPacket)m_PacketReader.Read();
            LogPacket  message4   = (LogPacket)m_PacketReader.Read();

            Assert.AreEqual(101, threadInfo.ThreadId);
            Assert.AreEqual(101, message1.ThreadId);
            Assert.AreEqual("message 1", message1.Caption);
            Assert.LessOrEqual(message1.TimeStamp, DateTime.Now);
            Assert.AreEqual(101, message2.ThreadId);
            Assert.AreEqual("message 2", message2.Caption);
            Assert.LessOrEqual(message1.TimeStamp, message2.TimeStamp);
            Assert.AreEqual(101, message3.ThreadId);
            Assert.AreEqual("message 3", message3.Caption);
            Assert.LessOrEqual(message2.TimeStamp, message3.TimeStamp);
            Assert.AreEqual("message 1", message4.Caption);
            Assert.LessOrEqual(message3.TimeStamp, message4.TimeStamp);
        }
        private void UpdatePacketDisplay()
        {
            LogPacket p = GetCurrentPacket();

            if (p == null)
            {
                return;
            }

            toolStripLabelPosition.Text = String.Format(CANAPE.Properties.Resources.PacketLogViewerForm_Header, _index + 1,
                                                        _packets.Count, p.Tag, p.Network, p.Timestamp.ToString());
        }
Exemple #16
0
        public virtual string ToString(LogPacket p, int index)
        {
            object value = GetValue(p);

            byte[] ba = value as byte[];

            if (ba != null)
            {
                int length = ba.Length;
                if (length > 64)
                {
                    length = 64;
                }

                if (!String.IsNullOrWhiteSpace(CustomFormat))
                {
                    try
                    {
                        StringBuilder builder = new StringBuilder();

                        for (int i = 0; i < length; ++i)
                        {
                            builder.AppendFormat(CustomFormat, ba[i]);
                        }

                        return(builder.ToString());
                    }
                    catch (FormatException)
                    {
                        // Error in format
                    }
                }

                return(GeneralUtils.EscapeString(BinaryEncoding.Instance.GetString(ba, 0, length)));
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(CustomFormat))
                {
                    try
                    {
                        return(String.Format(CustomFormat, value));
                    }
                    catch (FormatException)
                    {
                        // Error in format
                    }
                }

                return(value.ToString());
            }
        }
Exemple #17
0
        private void toolStripButtonCopy_Click(object sender, EventArgs e)
        {
            LogPacket currPacket = GetCurrentPacket();

            if (currPacket != null)
            {
                LogPacket[] packets = new LogPacket[1] {
                    currPacket
                };

                Clipboard.SetData(LogPacket.LogPacketArrayFormat, packets);
            }
        }
Exemple #18
0
        protected override object GetValue(LogPacket p)
        {
            object ret = p.Timestamp;

            if (Ticks)
            {
                return(p.Timestamp.Ticks);
            }
            else
            {
                return(p.Timestamp);
            }
        }
Exemple #19
0
        public override string ToString(LogPacket p, int index)
        {
            if (!String.IsNullOrWhiteSpace(CustomFormat))
            {
                try
                {
                    return(String.Format(CustomFormat, index + 1));
                }
                catch (FormatException)
                {
                }
            }

            return((index + 1).ToString());
        }
        internal void HandleLog(Packet pa)
        {
            LogPacket p        = pa as LogPacket;
            string    fullpath = @"clientlogs\" + IPAddress.Address.ToString() + @"\log_" + DateTime.Now.ToString().Replace(":", "-").Replace("/", ".") + ".txt";

            if (!Directory.Exists(Path.GetDirectoryName(fullpath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fullpath));
            }
            try
            {
                File.WriteAllLines(fullpath, p.LogMessages);
            }
            catch (Exception e) { MinecraftModUpdater.Logger.Log(e); }
        }
        private void toolStripButtonCopyFrame_Click(object sender, EventArgs e)
        {
            LogPacket[] packets = new LogPacket[1] {
                new LogPacket("Copied", Guid.Empty, "Copied", _currFrame.CloneFrame(), _color.FromColor())
            };

            try
            {
                Clipboard.SetData(LogPacket.LogPacketArrayFormat, packets);
            }
            catch (ExternalException)
            {
            }
            catch (ThreadStateException)
            {
            }
        }
Exemple #22
0
        public void LogError(string message, string subCategory, string errorCode, string helpString, string file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber)
        {
            this.LogError(message);
            LogPacket packet = new LogPacket()
            {
                Message         = message,
                Subcategory     = subCategory,
                ErrorCode       = errorCode,
                HelpString      = helpString,
                File            = file,
                LineNumber      = lineNumber,
                ColumnNumber    = columnNumber,
                EndLineNumber   = endLineNumber,
                EndColumnNumber = endColumnNumber
            };

            this._errorPackets.Add(packet);
        }
        public PacketDiffLogViewerForm(LogPacket curr, IList <LogPacket> packets)
        {
            for (int i = 0; i < packets.Count; i++)
            {
                if (packets[i] == curr)
                {
                    _index = i;
                    break;
                }
            }

            _packets = packets;
            //_modifiedPackets = new PacketEntry[_packets.Count];
            //_newStyleLogViewer = GlobalControlConfig.NewStyleLogViewer;


            InitializeComponent();
        }
        public void MessageHandler_WillSend_MultipartMessage()
        {
            using (var pullSocket = new PullSocket(">tcp://localhost:" + _port))
            {
                var logPacket = new LogPacket
                {
                    Message = "1"
                };

                var tx = JsonConvert.SerializeObject(logPacket);

                _messageHandler.Transmit(logPacket);

                var message = pullSocket.ReceiveMultipartMessage();

                Assert.IsTrue(message.FrameCount == 1);
                Assert.IsTrue(message[0].ConvertToString() == tx);
            }
        }
Exemple #25
0
        public void PacketCacheTest()
        {
            m_PacketReader.RegisterType(typeof(WrapperPacket));
            m_PacketReader.RegisterType(typeof(LogPacket));
            m_PacketReader.RegisterType(typeof(ThreadInfo));

            LogPacket.Write("message 1", m_PacketWriter);
            Assert.AreEqual(141, m_MemoryStream.Position);
            Thread.Sleep(50);

            LogPacket.Write("message 2", m_PacketWriter);
            Assert.AreEqual(160, m_MemoryStream.Position);
            Thread.Sleep(50);

            LogPacket.Write("message 3", m_PacketWriter);
            Assert.AreEqual(179, m_MemoryStream.Position);

            LogPacket.Write("message 1", m_PacketWriter);
            Assert.AreEqual(198, m_MemoryStream.Position);

            m_MemoryStream.Position = 0;

            ThreadInfo threadInfo = (ThreadInfo)m_PacketReader.Read();
            LogPacket  message1   = (LogPacket)m_PacketReader.Read();
            LogPacket  message2   = (LogPacket)m_PacketReader.Read();
            LogPacket  message3   = (LogPacket)m_PacketReader.Read();
            LogPacket  message4   = (LogPacket)m_PacketReader.Read();

            int threadId = Thread.CurrentThread.ManagedThreadId;

            Assert.AreEqual(threadId, threadInfo.ThreadId);
            Assert.AreEqual(threadId, message1.ThreadId);
            Assert.AreEqual("message 1", message1.Caption);
            Assert.LessOrEqual(message1.TimeStamp, DateTime.Now);
            Assert.AreEqual(message2.ThreadId, threadId);
            Assert.AreEqual("message 2", message2.Caption);
            Assert.LessOrEqual(message1.TimeStamp, message2.TimeStamp);
            Assert.AreEqual(message3.ThreadId, threadId);
            Assert.AreEqual("message 3", message3.Caption);
            Assert.LessOrEqual(message2.TimeStamp, message3.TimeStamp);
            Assert.AreEqual("message 1", message4.Caption);
            Assert.LessOrEqual(message3.TimeStamp, message4.TimeStamp);
        }
Exemple #26
0
        protected override void OnInput(DataFrame frame)
        {
            DataFrame logFrame;

            if (Config.ConvertToBytes)
            {
                logFrame = new DataFrame(frame.ToArray());
            }
            else
            {
                logFrame = frame.CloneFrame();
            }

            LogPacket packet = new LogPacket(Config.Tag, Graph.Uuid, Guid.NewGuid(),
                                             Graph.NetworkDescription, logFrame, Config.Color, DateTime.Now);

            Config.PacketLog.AddPacket(packet);

            WriteOutput(frame);
        }
Exemple #27
0
 private void SendToConsole(string logString, string stackTrace, LogType type)
 {
     if (Application.get_isMobilePlatform())
     {
         if (this.udpClient == null)
         {
             Debug.LogError("udpClient is null.");
             return;
         }
         LogPacket logPacket = default(LogPacket);
         logPacket.logString = string.Concat(new object[]
         {
             "[",
             DateTime.get_Now(),
             "]",
             logString
         });
         logPacket.stackTrace = stackTrace;
         logPacket.type       = type;
         byte[] array = logPacket.ToByteArray();
         this.udpClient.Send(array, array.Length, this.IP, this.Port);
     }
 }
 public void LogWarning(string message, string subCategory, string errorCode, string helpString, string file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber)
 {
     this.LogWarning(message);
     this.LogError(message);
     LogPacket packet = new LogPacket()
     {
         Message = message,
         Subcategory = subCategory,
         ErrorCode = errorCode,
         HelpString = helpString,
         File = file,
         LineNumber = lineNumber,
         ColumnNumber = columnNumber,
         EndLineNumber = endLineNumber,
         EndColumnNumber = endColumnNumber
     };
     this._warningPackets.Add(packet);
 }
Exemple #29
0
 protected override object GetValue(LogPacket p)
 {
     return(p.Hash);
 }
Exemple #30
0
 abstract protected object GetValue(LogPacket p);
Exemple #31
0
 // Not really implemented at the moment, special case
 protected override object GetValue(LogPacket p)
 {
     throw new NotImplementedException();
 }