/// <summary> /// Handles the Click event of the btnSingleSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnSingleSave_Click(object sender, EventArgs e) { PanelSession.Enabled = false; string groupCode = string.Empty; if (comboBoxEx2.SelectedItem != null) { groupCode = comboBoxEx2.SelectedItem.GetType().GetProperty("Value").GetValue(comboBoxEx2.SelectedItem, null).ToString(); } TSessionSetup Setup = new TSessionSetup() { Description = txtDescription.Text, IsOpen = chkIsOpen.Checked, SessionCode = txtSessionName.Text, GroupCode = groupCode, SessionExpire = txtExpire.Value, SessionPass = txtPassword.Text, FlowRate = float.Parse(this.txtFlow.Value.ToString()), AllowDuplicate = chkAllowRepeat.Checked, SpecialIntervalList = string.Empty }; Setup.Traffics = (PanelSession.Tag as TSessionSetup).Traffics; foreach (TSessionSetup item in this.listBox1.Items) { Setup.SpecialIntervalList += string.Format(@"^{0}|{1},", item.SessionCode, item.GroupCode); } this.listBox1.Items.Clear(); foreach (string Cmd in this.lstCmd.Items) { Setup.TSessionForbidCmd.Add(Cmd); } if (!AsyncStackNet.Instance.ASyncSetup.SessionCollection.Contains(Setup)) { AsyncStackNet.Instance.ASyncSetup.SessionCollection.Add(Setup); } else { int indexOf = AsyncStackNet.Instance.ASyncSetup.SessionCollection.IndexOf(this.PanelSession.Tag as TSessionSetup); AsyncStackNet.Instance.ASyncSetup.SessionCollection[indexOf] = Setup; } btnSave_Click(null, EventArgs.Empty); this.OnLoad(EventArgs.Empty); }
/// <summary> /// Handles the Click event of the btnClearTraffic control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnClearTraffic_Click(object sender, EventArgs e) { TSessionSetup Setup = lstSession.SelectedItems[0].Tag as TSessionSetup; if (this.comboTree1.SelectedValue.ToString() == DateTime.Now.ToString(@"yyyyMM")) { MessageBox.Show(@"当月流量统计不允许清除!", @"操作错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List <SocketTraffic> Traffics = AsyncStackNet.Instance.ASyncSetup.SessionCollection[ AsyncStackNet.Instance.ASyncSetup.SessionCollection.IndexOf(new TSessionSetup(Setup.SessionCode))].Traffics; Traffics.RemoveAt(Traffics.IndexOf(new SocketTraffic() { MonthString = this.comboTree1.SelectedValue.ToString() })); AsyncStackNet.Instance.BeginRateUpdate(new AsyncCallback(delegate(IAsyncResult iar) { AsyncStackNet.Instance.EndRateUpdate(iar); btnSessionEdit_Click(null, EventArgs.Empty); })); }
/// <summary> /// Handles the Click event of the btnDeleteSpecial control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> //private void btnDeleteSpecial_Click(object sender, EventArgs e) //{ // this.comboBoxEx3.Items.RemoveAt(this.comboBoxEx3.SelectedIndex); //} /* * /// <summary> * /// Handles the Click event of the btnUpdateSpecial control. * /// </summary> * /// <param name="sender">The source of the event.</param> * /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> * private void btnUpdateSpecial_Click(object sender, EventArgs e) { * if (!Regex.IsMatch(this.comboBoxEx3.Text, @"^([A-Z0-9]+)\|(\d+)", RegexOptions.Multiline | RegexOptions.IgnoreCase)) { * MessageBox.Show(@"输入格式不正确,正确格式为:SS|25", @"格式错误", MessageBoxButtons.OK, MessageBoxIcon.Error); * return; * } * Match m = Regex.Match(this.comboBoxEx3.Text, @"^([A-Z0-9]+)\|(\d+)", RegexOptions.Multiline | RegexOptions.IgnoreCase); * this.comboBoxEx3.Items[this.comboBoxEx3.SelectedIndex] = new { Interval = m.Groups[2].Value, Command = string.Format(@"{1} {0}", m.Groups[2].Value, m.Groups[1].Value) }; * } */ /// <summary> /// Handles the Click event of the btnNewSpecial control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> //private void btnNewSpecial_Click(object sender, EventArgs e) { // TSessionSetup setup = PanelSession.Tag as TSessionSetup; // if (!Regex.IsMatch(this.comboBoxEx3.Text, @"^([A-Z0-9]+)\|(\d+)", RegexOptions.Multiline | RegexOptions.IgnoreCase)) { // MessageBox.Show(@"输入格式不正确,正确格式为:SS|25", @"格式错误", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; // } // Match m = Regex.Match(this.comboBoxEx3.Text, @"^([A-Z0-9]+)\|(\d+)", RegexOptions.Multiline | RegexOptions.IgnoreCase); // this.comboBoxEx3.Items.Add(new TSessionSetup() { SessionCode = m.Groups[1].Value, Description = string.Format(@"{1} {0}", m.Groups[2].Value, m.Groups[1].Value), SessionPass = m.Groups[2].Value }); //} /// <summary> /// Handles the SelectedTabChanged event of the tabControl1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DevComponents.DotNetBar.TabStripTabChangedEventArgs"/> instance containing the event data.</param> private void tabControl1_SelectedTabChanged(object sender, DevComponents.DotNetBar.TabStripTabChangedEventArgs e) { if (PanelSession.Tag == null) { return; } TSessionSetup Setup = PanelSession.Tag as TSessionSetup; this.comboTree1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; this.comboTree1.ValueMember = @"MonthString"; this.comboTree1.DisplayMembers = @"MonthString,Traffic,UpdateDate"; if (string.IsNullOrEmpty(Setup.SessionCode) || AsyncStackNet.Instance.ASyncSetup.SessionCollection == null || AsyncStackNet.Instance.ASyncSetup.SessionCollection.Count == 0) { return; } if (AsyncStackNet.Instance.ASyncSetup.SessionCollection[ AsyncStackNet.Instance.ASyncSetup.SessionCollection.IndexOf(new TSessionSetup(Setup.SessionCode))].Traffics == null) { return; } this.comboTree1.DataSource = AsyncStackNet.Instance.ASyncSetup.SessionCollection[ AsyncStackNet.Instance.ASyncSetup.SessionCollection.IndexOf(new TSessionSetup(Setup.SessionCode))].Traffics; }
/// <summary> /// Handles the Click event of the btnSingleSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnSingleSave_Click(object sender, EventArgs e) { PanelSession.Enabled = false; string groupCode = string.Empty; if (comboBoxEx2.SelectedItem != null) groupCode = comboBoxEx2.SelectedItem.GetType().GetProperty("Value").GetValue(comboBoxEx2.SelectedItem, null).ToString(); TSessionSetup Setup = new TSessionSetup() { Description=txtDescription.Text, IsOpen =chkIsOpen.Checked, SessionCode=txtSessionName.Text, GroupCode = groupCode, SessionExpire=txtExpire.Value, SessionPass=txtPassword.Text, FlowRate=float.Parse(this.txtFlow.Value.ToString()), AllowDuplicate=chkAllowRepeat.Checked, SpecialIntervalList =string.Empty }; Setup.Traffics = (PanelSession.Tag as TSessionSetup).Traffics; foreach (TSessionSetup item in this.listBox1.Items) { Setup.SpecialIntervalList += string.Format(@"^{0}|{1},", item.SessionCode,item.GroupCode); } this.listBox1.Items.Clear(); foreach (string Cmd in this.lstCmd.Items) { Setup.TSessionForbidCmd.Add(Cmd); } if (!AsyncStackNet.Instance.ASyncSetup.SessionCollection.Contains(Setup)) AsyncStackNet.Instance.ASyncSetup.SessionCollection.Add(Setup); else{ int indexOf = AsyncStackNet.Instance.ASyncSetup.SessionCollection.IndexOf(this.PanelSession.Tag as TSessionSetup); AsyncStackNet.Instance.ASyncSetup.SessionCollection[indexOf] = Setup; } btnSave_Click(null, EventArgs.Empty); this.OnLoad(EventArgs.Empty); }
/// <summary> /// Handles the Click event of the btnSessionEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnSessionEdit_Click(object sender, EventArgs e) { foreach (ListViewItem item in this.lstSession.Items) { if (!item.Selected) { continue; } TSessionSetup Setup = item.Tag as TSessionSetup; PanelSession.Tag = Setup; txtDescription.Text = Setup.Description; txtExpire.Value = Setup.SessionExpire; txtPassword.Text = Setup.SessionPass; txtSessionName.Text = Setup.SessionCode; chkIsOpen.Checked = Setup.IsOpen; txtFlow.Value = int.Parse(Setup.FlowRate.ToString()); PanelSession.Tag = Setup; listBox1.Items.Clear(); lstCmd.Items.Clear(); chkAllowRepeat.Checked = Setup.AllowDuplicate ?? false; listBox1.ValueMember = "SessionCode"; listBox1.DisplayMember = "Description"; foreach (string Cmd in Setup.TSessionForbidCmd) { this.lstCmd.Items.Add(Cmd); } comboBoxEx2.Items.Clear(); if (AsyncStackNet.Instance.ASyncSetup.GroupCollection == null) { return; } foreach (SDKGroup group in AsyncStackNet.Instance.ASyncSetup.GroupCollection) { comboBoxEx2.Items.Add(new { Text = group.groupName, Value = group.groupCode }); } if (!string.IsNullOrEmpty(Setup.SpecialIntervalList)) { foreach (Match m in Regex.Matches(Setup.SpecialIntervalList, @"\^([A-Z0-9]+)\|(\d+)\,", RegexOptions.IgnoreCase | RegexOptions.Multiline)) { listBox1.Items.Add(new TSessionSetup() { SessionCode = m.Groups[1].Value, GroupCode = m.Groups[2].Value, Description = string.Format(@"{0} {1}", m.Groups[1].Value, m.Groups[2].Value) }); } } if (!string.IsNullOrEmpty(Setup.GroupCode)) { foreach (object group in this.comboBoxEx2.Items) { string GValue = group.GetType().GetProperty("Value").GetValue(group, null).ToString(); //string GText = group.GetType().GetProperty("Text").GetValue(group, null).ToString(); if (GValue == Setup.GroupCode) { comboBoxEx2.SelectedItem = group; } } } PanelSession.Enabled = true; if (!AsyncStackNet.Instance.ASyncSetup.SessionCollection.Contains(new TSessionSetup(Setup.SessionCode))) { return; } this.comboTree1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; this.comboTree1.ValueMember = @"MonthString"; this.comboTree1.DisplayMembers = @"MonthString,Traffic,UpdateDate"; this.comboTree1.DataSource = AsyncStackNet.Instance.ASyncSetup.SessionCollection[ AsyncStackNet.Instance.ASyncSetup.SessionCollection.IndexOf(new TSessionSetup(Setup.SessionCode))].Traffics; //PanelSession.act tabControl1.SelectedTab = tabItem2; break; } }
static void Main(string[] args) { /* * SystemSetup setup = new SystemSetup().DeserializeObject(@"SETUP.BIN", TEACrypter.GetDefaultKey); * setup.AsynCollection.RemoveAt(0); * setup.AsynCollection[0].IsOpen = true; * setup.SessionCollection[0].TSessionForbidCmd = new List<string>() { "TEST"}; * setup.XmlSerialize(TEACrypter.GetDefaultKey, @"C:\Setup.Bin"); */ /**/ string Cpu = GetCpuSN(); TEACrypter Crypter = new TEACrypter(); byte[] keys = TEACrypter.MD5(Encoding.Default.GetBytes(Cpu)); byte[] Result = Crypter.Encrypt(Encoding.Default.GetBytes(Cpu), keys); AsyncLicenceKey Key = new AsyncLicenceKey() { Company = "开发机授权", ExpireDate = DateTime.Now.AddMonths(1), Key = Result, MaxAsync = 100, MaxTSession = 500, AllowDatabase = true, MaxCommandPerMonth = 20000, connectionString = @"Data Source=(local);Initial Catalog=Async;User ID=sa;Password=Password01!", providerName = @"System.Data.SqlClient", AllowAfterValidate = true, AllowIntercept = true, RemainingMinutes = ((TimeSpan)(DateTime.Now.AddMonths(1) - DateTime.Now)).TotalMinutes }; byte[] Buffer = Key.XmlSerialize(keys, @"C:\Key.Bin"); Key = Key.DeXmlSerialize(keys, Buffer); AsyncStackNet.Instance.ASyncSetupFile = @"SETUP.BIN"; AsyncStackNet.Instance.AfterIntercept = new InterceptCallback(delegate(AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> e) { e.Session.SendPacket(__eTerm443Packet.BuildSessionPacket(e.Session.SID, e.Session.RID, "指令被禁止")); }); /* * AsyncStackNet.Instance.AfterPacket =new AfterPacketCallback(delegate(AsyncEventArgs<eTerm443Packet,eTerm443Packet,eTerm443Async> Args,PlugInSetup PlugIn) * { * Console.WriteLine(@"开始后续插件执行{0}", PlugIn.PlugInName); * PlugIn.PlugInstance.BeginExecute(new AsyncCallback(delegate(IAsyncResult iar) * { * Console.WriteLine(@"后续插件{0}执行完成!", PlugIn.PlugInName); * }), Args.Session, Args.InPacket, Args.OutPacket); * }); */ AsyncStackNet.Instance.StackNetPoint = new IPEndPoint(IPAddress.Any, 3500); AsyncStackNet.Instance.RID = 0x51; AsyncStackNet.Instance.SID = 0x27; AsyncStackNet.Instance.OnAsyncDisconnect += new EventHandler <AsyncEventArgs <eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Async> e) { Console.WriteLine(string.Format(@"OnAsyncDisconnect {0} On {1}........", e.Session, DateTime.Now)); } ); AsyncStackNet.Instance.OnTSessionPacketSent += new EventHandler <AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> e) { Console.WriteLine("OnTSessionPacketSent {0} {1}", e.Session.AsyncSocket.RemoteEndPoint.ToString(), DateTime.Now); } ); AsyncStackNet.Instance.OnAsyncReadPacket += new EventHandler <AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> e) { Console.WriteLine( string.Format(@"OnAsyncReadPacket:{0} InPacket:{1} OutPacket:{2}" , e.Session.AsyncSocket.RemoteEndPoint.ToString() , Encoding.GetEncoding("gb2312").GetString(e.Session.UnInPakcet(e.OutPacket)) , Encoding.GetEncoding("gb2312").GetString(e.Session.UnOutPakcet(e.InPacket)).Replace("\0", string.Empty) )); if (e.Session.TSession == null) { return; } } ); AsyncStackNet.Instance.OnAsyncValidated += new EventHandler <AsyncEventArgs <eTerm443Packet, eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Packet, eTerm443Async> e) { Console.WriteLine("{0} OnValidated With {1}", e.Session, e.Session.AsyncSocket.RemoteEndPoint); } ); AsyncStackNet.Instance.TSessionValidate = new AsyncBaseServer <eTerm363Session, eTerm363Packet> .ValidateCallback(delegate(eTerm363Session s, eTerm363Packet p) { s.UnpakcetSession(p); TSessionSetup TSession = AsyncStackNet.Instance.ASyncSetup.SessionCollection.Single <TSessionSetup>(Fun => Fun.SessionPass == s.userPass && Fun.SessionCode == s.userName); if (TSession == null) { return(false); } s.TSessionInterval = TSession.SessionExpire; s.UnallowableReg = TSession.ForbidCmdReg; return(true); }); //AsyncStackNet.Instance.TSessionReconnectValidate = new AsyncBase<eTerm443Async, eTerm443Packet>.ValidateTSessionCallback( // delegate(eTerm443Packet Packet, eTerm443Async Async) // { // return Async.ReconnectCount <= 5; // }); AsyncStackNet.Instance.OnTSessionAssign += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { Console.WriteLine("Session {2} Assign To {0} On {1}", e.Session, DateTime.Now, e.Session.Async443); } ); AsyncStackNet.Instance.OnTSessionAccept += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { Console.WriteLine("OnTSessionAccept {0}", e.Session); } ); AsyncStackNet.Instance.OnTSessionClosed += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { Console.WriteLine("OnTSessionClosed {0}", e.Session); } ); AsyncStackNet.Instance.OnAsyncTimeout += new EventHandler <AsyncEventArgs <eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Async> e) { Console.WriteLine("OnAsyncTimeout {0}", e.Session); } ); AsyncStackNet.Instance.OnTSessionRelease += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { Console.WriteLine("Session {0} Release {2} On {1}", e.Session, DateTime.Now, e.Session.Async443); } ); AsyncStackNet.Instance.OnTSessionReadPacket += new EventHandler <AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> e) { Console.WriteLine("OnReadPacket From {0} Packet Sequence:{1} Total Bytes:{2:f2} KBytes ", e.Session.AsyncSocket.RemoteEndPoint, e.InPacket.Sequence, e.Session.TotalBytes); } ); LicenceManager.Instance.BeginValidate(new AsyncCallback( delegate(IAsyncResult iar) { try { if (!LicenceManager.Instance.EndValidate(iar)) { Console.WriteLine("Validate Error"); } else { //ContextInstance.Instance.providerName = LicenceManager.Instance.LicenceBody.providerName; //ContextInstance.Instance.connectionString = LicenceManager.Instance.LicenceBody.connectionString; //激活配置 AsyncStackNet.Instance.BeginAsync(); AsyncStackNet.Instance.BeginReflectorPlugIn(new AsyncCallback(delegate(IAsyncResult iar1) { AsyncStackNet.Instance.EndReflectorPlugIn(iar1); })); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(); Console.WriteLine(ex.StackTrace); } }), @"Key.bin"); Console.ReadKey(); }
/// <summary> /// Starts the service. /// </summary> private void StartService() { //stateAsync.Visible = true; //stateAsync.Image = AsyncResource.Circle_Green; //byte[] Buffer = new AsyncLicenceKey().XmlSerialize(keys, @"C:\XIAOFANG.Bin"); //Key = Key.DeXmlSerialize(keys, Buffer); AsyncStackNet.Instance.ASyncSetupFile = new FileInfo(@"SETUP.BIN").FullName; AsyncStackNet.Instance.AfterIntercept = new InterceptCallback(delegate(AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> e) { AppendSessionLog(listView1, e.Session.userName, "AfterIntercept", Encoding.GetEncoding("gb2312").GetString(e.Session.UnOutPakcet(e.InPacket)), "SUCCESS"); e.Session.SendPacket(__eTerm443Packet.BuildSessionPacket(e.Session.SID, e.Session.RID, "指令被禁止")); }); /* * AsyncStackNet.Instance.AfterPacket = new AfterPacketCallback(delegate(AsyncEventArgs<eTerm443Packet, eTerm443Packet, eTerm443Async> Args, PlugInSetup PlugIn) * { * PlugIn.PlugInstance.BeginExecute(new AsyncCallback(delegate(IAsyncResult iar) * { * PlugIn.PlugInstance.EndExecute(iar); * }), Args.Session, Args.InPacket, Args.OutPacket); * }); */ AsyncStackNet.Instance.StackNetPoint = new IPEndPoint(IPAddress.Any, 360); AsyncStackNet.Instance.RID = 0x51; AsyncStackNet.Instance.SID = 0x27; AsyncStackNet.Instance.OnExecuteException += new EventHandler <ErrorEventArgs>( delegate(object sender, ErrorEventArgs e) { AppendSessionLog(listView1, (sender as eTerm363Session).userName, "ExecuteException", e.GetException().Message, "ERROR"); } ); AsyncStackNet.Instance.OnAsyncDisconnect += new EventHandler <AsyncEventArgs <eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Async> e) { AppendSessionLog(listView2, e.Session.userName, "AsyncDisconnect", string.Empty, "SUCCESS"); //AsyncStackNet.Instance.ReconnectAsync(e.Session); UpdateListByThread(lstAsync, "Circle_Green.png", e.Session.SessionId.ToString(), 0f, string.Empty); //AsyncStackNet.Instance.ReconnectAsync(e.Session); //SetToolbarImg(toolStripSplitPlugIn, AsyncResource.Circle_Red, string.Format(@"{0} 断开于 {1}", sender, DateTime.Now)); } ); AsyncStackNet.Instance.OnTSessionPacketSent += new EventHandler <AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> e) { UpdateListByThread(lstSession, "Circle_Green.png", e.Session.SessionId.ToString(), e.Session.TotalBytes, e.Session.TotalCount.ToString()); } ); AsyncStackNet.Instance.OnAsyncPacketSent += new EventHandler <AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> e) { UpdateListByThread(lstAsync, "Circle_Red.png", e.Session.SessionId.ToString(), e.Session.TotalBytes, e.Session.TotalCount.ToString()); } ); AsyncStackNet.Instance.OnAsyncReadPacket += new EventHandler <AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> e) { UpdateListByThread(lstAsync, "Circle_Green.png", e.Session.SessionId.ToString(), e.Session.TotalBytes, e.Session.TotalCount.ToString()); AppendSessionLog(listView2, e.Session.userName, "AsyncReadPacket", Encoding.GetEncoding("gb2312").GetString(e.Session.UnInPakcet(e.OutPacket)), "SUCCESS"); if (e.Session.TSession == null) { return; } } ); AsyncStackNet.Instance.OnAsyncValidated += new EventHandler <AsyncEventArgs <eTerm443Packet, eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Packet, eTerm443Async> e) { ListViewItem ViewItem = new ListViewItem(new string[] { e.Session.AsyncSocket.RemoteEndPoint.ToString(), e.Session.userName, e.Session.TotalBytes.ToString("f2"), e.Session.ReconnectCount.ToString(), e.Session.TotalBytes.ToString("f2") }); ViewItem.Name = e.Session.SessionId.ToString(); ViewItem.ImageKey = "Circle_Green.png"; e.Session.OnReadPacket += new EventHandler <AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> >( delegate(object Session, AsyncEventArgs <eTerm443Packet, eTerm443Packet, eTerm443Async> SessionArg) { UpdateListByThread(lstAsync, "Circle_Green.png", SessionArg.Session.SessionId.ToString(), SessionArg.Session.TotalBytes, SessionArg.Session.TotalCount.ToString()); } ); ViewItem.Tag = e.Session; AppendListByThread(lstAsync, ViewItem); AppendSessionLog(listView2, e.Session.userName, "AsyncValidated", "", "SUCCESS"); } ); AsyncStackNet.Instance.TSessionValidate = new AsyncBaseServer <eTerm363Session, eTerm363Packet> .ValidateCallback(delegate(eTerm363Session s, eTerm363Packet p, out string ValidateMessage) { s.UnpakcetSession(p); ValidateMessage = string.Empty; TSessionSetup TSession = AsyncStackNet.Instance.ASyncSetup.SessionCollection.Single <TSessionSetup>(Fun => Fun.SessionPass == s.userPass && Fun.SessionCode == s.userName && Fun.IsOpen == true); if (TSession == null) { return(false); } s.TSessionInterval = TSession.SessionExpire; s.UnallowableReg = TSession.ForbidCmdReg; s.SpecialIntervalList = TSession.SpecialIntervalList; s.userGroup = TSession.GroupCode; ListViewItem ViewItem = new ListViewItem(new string[] { s.AsyncSocket.RemoteEndPoint.ToString(), s.userName, s.TotalBytes.ToString("f2"), s.ReconnectCount.ToString() }); ViewItem.Name = s.SessionId.ToString(); ViewItem.ImageKey = "Circle_Green.png"; s.OnReadPacket += new EventHandler <AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> >( delegate(object Session, AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> SessionArg) { UpdateListByThread(lstSession, "Circle_Red.png", SessionArg.Session.SessionId.ToString(), SessionArg.Session.TotalBytes, SessionArg.Session.TotalCount.ToString()); } ); ViewItem.Tag = s; AppendListByThread(lstSession, ViewItem); return(true); }); //AsyncStackNet.Instance.TSessionReconnectValidate = new AsyncBase<eTerm443Async, eTerm443Packet>.ValidateTSessionCallback( // delegate(eTerm443Packet Packet, eTerm443Async Async) // { // UpdateListByThread(lstSession, "Circle_Grey.png", Async.SessionId.ToString(), Async.TotalBytes, Async.TotalCount.ToString()); // return Async.ReconnectCount <= 15; // }); AsyncStackNet.Instance.OnTSessionAssign += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { UpdateListByThread(lstSession, "Circle_Yellow.png", e.Session.SessionId.ToString(), e.Session.TotalBytes, e.Session.TotalCount.ToString()); UpdateListByThread(lstAsync, "Circle_Yellow.png", e.Session.Async443.SessionId.ToString(), e.Session.Async443.TotalBytes, e.Session.Async443.TotalCount.ToString()); } ); AsyncStackNet.Instance.OnTSessionAccept += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { AppendSessionLog(listView1, e.Session.SessionId.ToString(), "TSessionAccept", "", "SUCCESS"); } ); AsyncStackNet.Instance.OnTSessionClosed += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { UpdateListByThread(lstSession, "Circle_Red.png", e.Session.SessionId.ToString(), 0f, e.Session.TotalBytes.ToString("f2")); AppendSessionLog(listView1, e.Session.userName, "TSessionClosed", "", "SUCCESS"); } ); AsyncStackNet.Instance.OnAsyncTimeout += new EventHandler <AsyncEventArgs <eTerm443Async> >( delegate(object sender, AsyncEventArgs <eTerm443Async> e) { //stateAsync.Image = AsyncResource.Circle_Orange; //SetToolbarImg(stateAsync, AsyncResource.Circle_Orange,string.Empty); //Console.WriteLine("OnAsyncTimeout {0}", e.Session); } ); AsyncStackNet.Instance.OnTSessionRelease += new EventHandler <AsyncEventArgs <eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Session> e) { AppendSessionLog(listView1, e.Session.userName, "TSessionRelease", "", "SUCCESS"); //UpdateListByThread(lstSession, "Circle_Green.png", e.Session.SessionId.ToString(), e.Session.TotalBytes,e.Session.TotalBytes.ToString("f2")); //UpdateListByThread(lstAsync, "Circle_Green.png", e.Session.Async443.SessionId.ToString(), e.Session.Async443.TotalBytes, e.Session.Async443.TotalCount.ToString()); if (e.Session.Async443 != null && !e.Session.IsCompleted) { e.Session.SendPacket(__eTerm443Packet.BuildSessionPacket(e.Session.SID, e.Session.RID, "无数据返回或读取超时")); } //Console.WriteLine("Session {0} Release {2} On {1}", e.Session, DateTime.Now, e.Session.Async443); } ); AsyncStackNet.Instance.OnTSessionReadPacket += new EventHandler <AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> >( delegate(object sender, AsyncEventArgs <eTerm363Packet, eTerm363Packet, eTerm363Session> e) { //stateAsync.Image = AsyncResource.Circle_Yellow; //SetToolbarImg(stateAsync, AsyncResource.Circle_Yellow,string.Empty); try { UpdateListByThread(lstSession, "Circle_Red.png", e.Session.SessionId.ToString(), e.Session.TotalBytes, e.Session.TotalCount.ToString()); AppendSessionLog(listView1, e.Session.userName, "ReadPacket", Encoding.GetEncoding("gb2312").GetString(e.Session.UnOutPakcet(e.InPacket)), "SUCCESS"); } catch (Exception Ex) { AppendSessionLog(listView1, e.Session.userName, "ReadPacket", Ex.Message, "ERROR"); } //Console.WriteLine("OnReadPacket From {0} Packet Sequence:{1} Total Bytes:{2:f2} KBytes ", e.Session.AsyncSocket.RemoteEndPoint, e.InPacket.Sequence, e.Session.TotalBytes); } ); LicenceManager.Instance.BeginValidate(new AsyncCallback( delegate(IAsyncResult iar) { try { if (!LicenceManager.Instance.EndValidate(iar)) { //Console.WriteLine("Validate Error"); } else { //激活配置 AsyncStackNet.Instance.BeginAsync(); //loadAddIn(AsyncStackNet.Instance.ASyncSetup.PlugInPath); AsyncStackNet.Instance.BeginReflectorPlugIn(new AsyncCallback(delegate(IAsyncResult iar1) { AsyncStackNet.Instance.EndReflectorPlugIn(iar1); })); } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }), new FileInfo(@"Key.Bin").FullName); loadAddIn(@".\"); //按钮控制 this.btnStart.Enabled = false; this.btnStop.Enabled = true; this.btnReset.Enabled = true; }