Skip to content

Commit a625134

Browse files
committed
基本功能可用
1 parent 89bc4b7 commit a625134

File tree

152 files changed

+359684
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+359684
-0
lines changed

URLogWin/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

URLogWin/AppCommand.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using SuperSocket.SocketBase;
2+
using SuperSocket.SocketBase.Command;
3+
using SuperSocket.SocketBase.Protocol;
4+
5+
namespace URLogWin
6+
{
7+
public static class LogType
8+
{
9+
public const string Error= "Error";
10+
public const string Assert= "Assert";
11+
public const string Exception= "Exception";
12+
public const string Warning= "Warning";
13+
public const string Log= "Log";
14+
}
15+
16+
public enum ENetEvent
17+
{
18+
Connected,
19+
Disconnected,
20+
Start,
21+
Log,
22+
}
23+
24+
public class LogItem
25+
{
26+
public string log;
27+
public string stack;
28+
public string type;
29+
30+
public void ConvertBase64()
31+
{
32+
log = System.Text.Encoding.UTF8.GetString(
33+
System.Convert.FromBase64String(log)
34+
);
35+
stack = System.Text.Encoding.UTF8.GetString(
36+
System.Convert.FromBase64String(stack)
37+
);
38+
type = System.Text.Encoding.UTF8.GetString(
39+
System.Convert.FromBase64String(type)
40+
);
41+
}
42+
}
43+
44+
public class NetEvent
45+
{
46+
public ENetEvent evt;
47+
public string data;
48+
public LogItem log;
49+
50+
public NetEvent(ENetEvent e, string d)
51+
{
52+
evt = e;
53+
data = d;
54+
}
55+
}
56+
57+
public class CMD_START : CommandBase<AppSession, StringRequestInfo>
58+
{
59+
public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
60+
{
61+
MainForm.NetEventQueue.Enqueue(
62+
new NetEvent(ENetEvent.Start, requestInfo.Body)
63+
);
64+
}
65+
}
66+
67+
public class CMD_LOG : CommandBase<AppSession, StringRequestInfo>
68+
{
69+
public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
70+
{
71+
NetEvent evt = new NetEvent(ENetEvent.Log, requestInfo.Body);
72+
evt.data = requestInfo.Body;
73+
try
74+
{
75+
LogItem log = Newtonsoft.Json.JsonConvert.DeserializeObject<LogItem>(requestInfo.Body);
76+
if (log != null)
77+
log.ConvertBase64();
78+
evt.log = log;
79+
}
80+
catch (System.Exception ex)
81+
{
82+
}
83+
84+
MainForm.NetEventQueue.Enqueue(evt);
85+
}
86+
}
87+
88+
}

URLogWin/MainForm.Designer.cs

Lines changed: 340 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

URLogWin/MainForm.cs

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
using System.Text;
2+
using System.Drawing;
3+
using SuperSocket.SocketBase;
4+
using System.Windows.Forms;
5+
using System.Collections.Generic;
6+
using System.Collections.Concurrent;
7+
8+
namespace URLogWin
9+
{
10+
/// <summary>
11+
/// 主窗体
12+
/// </summary>
13+
public partial class MainForm : Form
14+
{
15+
public static ConcurrentQueue<NetEvent> NetEventQueue = new ConcurrentQueue<NetEvent>();
16+
17+
bool m_showLog;
18+
bool m_showWarning;
19+
bool m_showError;
20+
List<LogItem> m_logList = new List<LogItem>();
21+
22+
public MainForm()
23+
{
24+
InitializeComponent();
25+
26+
//--
27+
m_showLog = true;
28+
m_showWarning = true;
29+
m_showError = true;
30+
this.splitContainer.Visible = false;
31+
}
32+
33+
/// <summary>
34+
/// Unity客户端连接
35+
/// </summary>
36+
public void appServerNewSessionConnected(AppSession session)
37+
{
38+
NetEventQueue.Enqueue(
39+
new NetEvent(ENetEvent.Connected, "")
40+
);
41+
}
42+
43+
44+
/// <summary>
45+
/// Unity客户端连接断开
46+
/// </summary>
47+
public void appServerSessionClosed(AppSession session, SuperSocket.SocketBase.CloseReason value)
48+
{
49+
NetEventQueue.Enqueue(
50+
new NetEvent(ENetEvent.Disconnected, "")
51+
);
52+
}
53+
54+
/// <summary>
55+
/// 主线程事件驱动Timer相应
56+
/// </summary>
57+
private void eventTickTimer_Tick(object sender, System.EventArgs e)
58+
{
59+
NetEvent evt = null;
60+
while (!NetEventQueue.IsEmpty && NetEventQueue.TryDequeue(out evt))
61+
{
62+
switch (evt.evt)
63+
{
64+
case ENetEvent.Connected:
65+
this.pictureBoxLog.Visible = false;
66+
this.labelTips.Visible = false;
67+
this.splitContainer.Visible = true;
68+
this.lbStatus.Text = "Connected";
69+
break;
70+
case ENetEvent.Disconnected:
71+
this.lbStatus.Text = "Disonnected";
72+
break;
73+
case ENetEvent.Start:
74+
this.lbStatus.Text = "App Start";
75+
this.pictureBoxLog.Visible = false;
76+
this.labelTips.Visible = false;
77+
this.splitContainer.Visible = true;
78+
break;
79+
case ENetEvent.Log:
80+
this.lbStatus.Text = "Log";
81+
if (evt.log != null)
82+
{
83+
ShowLog(evt.log);
84+
m_logList.Add(evt.log);
85+
}
86+
else
87+
{
88+
ListViewItem view = this.listViewLog.Items.Add("", 0);
89+
view.SubItems.Add(evt.data);
90+
}
91+
this.pictureBoxLog.Visible = false;
92+
this.labelTips.Visible = false;
93+
this.splitContainer.Visible = true;
94+
break;
95+
default:
96+
this.lbStatus.Text = "Unknown Net Event";
97+
break;
98+
}// end of switch
99+
}// end of while
100+
}
101+
102+
/// <summary>
103+
/// 在ListView插入一项Log
104+
/// </summary>
105+
void ShowLog(LogItem log)
106+
{
107+
if (!FilterLog(log))
108+
return;
109+
int imgIndex = 0;
110+
Color clr = Color.Black;
111+
switch (log.type)
112+
{
113+
case LogType.Error:
114+
case LogType.Exception:
115+
case LogType.Assert:
116+
imgIndex = 2;
117+
clr = Color.Red;
118+
break;
119+
case LogType.Warning:
120+
imgIndex = 1;
121+
clr = Color.Yellow;
122+
break;
123+
case LogType.Log:
124+
imgIndex = 0;
125+
clr = Color.Black;
126+
break;
127+
}
128+
129+
ListViewItem view = this.listViewLog.Items.Insert(0, string.Empty, imgIndex);
130+
view.SubItems.Add(log.log);
131+
view.ForeColor = clr;
132+
view.Tag = log;
133+
}
134+
135+
136+
/// <summary>
137+
/// 工具栏“清空”按钮相应
138+
/// </summary>
139+
private void btnClear_Click(object sender, System.EventArgs e)
140+
{
141+
this.listViewLog.Items.Clear();
142+
this.m_logList.Clear();
143+
this.textBoxDetail.Text = string.Empty;
144+
}
145+
146+
private void checkBtnInfo_CheckedChanged(object sender, System.EventArgs e)
147+
{
148+
m_showLog = this.checkBtnInfo.Checked;
149+
this.RefreshLogList();
150+
}
151+
152+
private void checkBtnWarning_CheckedChanged(object sender, System.EventArgs e)
153+
{
154+
m_showWarning = this.checkBtnWarning.Checked;
155+
this.RefreshLogList();
156+
}
157+
158+
private void checkBtnError_CheckedChanged(object sender, System.EventArgs e)
159+
{
160+
m_showError = this.checkBtnError.Checked;
161+
this.RefreshLogList();
162+
}
163+
164+
private void MainForm_SizeChanged(object sender, System.EventArgs e)
165+
{
166+
this.columnHeader1.Width = 24;
167+
this.columnHeader2.Width = this.ClientSize.Width - 24 - 32;
168+
}
169+
170+
/// <summary>
171+
/// 选中一项Log之后,显示详细信息
172+
/// </summary>
173+
private void listViewLog_SelectedIndexChanged(object sender, System.EventArgs e)
174+
{
175+
var selItems = this.listViewLog.SelectedItems;
176+
if (selItems.Count >= 1)
177+
{
178+
ListViewItem item = selItems[0];
179+
LogItem log = item.Tag as LogItem;
180+
if (log != null)
181+
{
182+
StringBuilder sb = new StringBuilder();
183+
if (log.type != LogType.Exception)
184+
sb.AppendFormat("{0}: {1}", log.type, log.log);
185+
else
186+
sb.Append(log.log);
187+
sb.AppendLine();
188+
sb.AppendLine(log.stack);
189+
this.textBoxDetail.Text = sb.ToString();
190+
}
191+
}
192+
}
193+
194+
/// <summary>
195+
/// 使用过滤器,刷新Log列表内容
196+
/// </summary>
197+
void RefreshLogList()
198+
{
199+
this.listViewLog.BeginUpdate();
200+
this.listViewLog.Items.Clear();
201+
foreach (LogItem log in m_logList)
202+
{
203+
ShowLog(log);
204+
}
205+
this.listViewLog.EndUpdate();
206+
}
207+
208+
/// <summary>
209+
/// 过滤:列表项是否可见
210+
/// </summary>
211+
bool FilterLog(LogItem log)
212+
{
213+
bool viz = true;
214+
switch (log.type)
215+
{
216+
case LogType.Error:
217+
case LogType.Assert:
218+
case LogType.Exception:
219+
viz = m_showError;
220+
break;
221+
case LogType.Warning:
222+
viz = m_showWarning;
223+
break;
224+
case LogType.Log:
225+
viz = m_showLog;
226+
break;
227+
}
228+
return viz;
229+
}
230+
231+
}
232+
}

0 commit comments

Comments
 (0)