12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using CommonFroms.Drawing;
- using CommonLang;
- using CommonNetwork.Net;
- using CommonNetwork.Sockets;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace CommonFroms.Net
- {
- public partial class FormSessionTracer : Form
- {
- public interface ISession
- {
- long TotalRecvBytes { get; }
- long TotalSentBytes { get; }
- }
- private ISession mSession;
- private BytesSecondRateTracker mTrackerRecv;
- private BytesSecondRateTracker mTrackerSend;
- private StringBuilder textBuffer = new StringBuilder();
-
- public FormSessionTracer(ISession session)
- {
- InitializeComponent();
- this.mSession = session;
- this.mTrackerRecv = new BytesSecondRateTracker(600, this.Font, new Pen(Color.Blue), new SolidBrush(Color.Blue));
- this.mTrackerRecv.Title = "Recv";
- this.mTrackerSend = new BytesSecondRateTracker(600, this.Font, new Pen(Color.Red), new SolidBrush(Color.Red));
- this.mTrackerSend.Title = "Send";
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- mTrackerRecv.Record(mSession.TotalRecvBytes);
- mTrackerSend.Record(mSession.TotalSentBytes);
- pictureBox1.Refresh();
- lock (textBuffer)
- {
- if (textBuffer.Length > 0)
- {
- richTextBox1.AppendText(textBuffer.ToString());
- textBuffer.Clear();
- }
- }
- }
-
- private void pictureBox1_Paint(object sender, PaintEventArgs e)
- {
- try
- {
- float px = 0;
- float py = 0;
- float pw = pictureBox1.Width;
- float ph = pictureBox1.Height / 2;
- mTrackerRecv.DrawGrap(e.Graphics, px + 1, py + 1, pw - 2, ph - 2);
- py += ph;
- mTrackerSend.DrawGrap(e.Graphics, px + 1, py + 1, pw - 2, ph - 2);
- }
- catch (Exception err) { }
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void onMessageReceived(INetSession session, object msg)
- {
- lock(textBuffer)
- {
- textBuffer.AppendLine(DateTime.Now + " : Recv <- " + msg);
- }
- }
- private void onMessageSent(INetSession session, object msg)
- {
- lock (textBuffer)
- {
- textBuffer.AppendLine(DateTime.Now + " : Send -> " + msg);
- }
- }
- }
- }
|