• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 124,  comments - 29,  trackbacks - 0

            在MonitorWnd.cs類中:
            事件處理函數:
            //tabControl1是Form窗體中創建的控件,也就是UI線程中創建的控件

            //要在事件處理函數中動態的創建TabPage,這個事件處理函數是被另一個read線程調用的

              private void MonitorWnd_Load(object sender, EventArgs e)
                    {
                        monAge = new MonitorAgency(curNet);
                        monAge.parser.UserAction += new UserActionHandler(parser_UserAction);
                        monAge.Connect();

                    }
              void parser_UserAction(object sender, UserActionEventArgs args)
                    {

                        #region
                        if (tabControl1.InvokeRequired)
                        {
                            tabControl1.Invoke(new MethodInvoker(delegate { AddPageToTabControl(tabControl1, args); }));
                        }

                        else
                        {
                            AddPageToTabControl(tabControl1, args);
                        }
                        #endregion
                    }


             void AddPageToTabControl(TabControl ctrl, UserActionEventArgs args)
                    {
                        //TODO:取得一個用戶行為信息的時候引發這個事件
                        //動態創建tab頁
                        string tabTitle = args.UserName + " " + args.ProcID;
                        string addTxt = args.Time + "\r\n" + args.IP + "\r\n" + args.Remark;


                        bool isFind = false;

                        foreach (TabPage tpUser in this.tabControl1.Controls)
                        {
                            if (tpUser.Text == tabTitle)
                            {
                                isFind = true;
                                string strtxt = ((TextBox)tpUser.Controls[0]).Text;
                                ((TextBox)tpUser.Controls[0]).Text = strtxt + "\r\n" + addTxt;
                                ctrl.SelectedTab = tpUser;
                                break;
                            }
                        }
                        if (isFind == false)
                        {
                            TabPage newTpUser = new TabPage();
                            newTpUser.Text = tabTitle;
                            TextBox tb = new TextBox();
                            tb.Dock = DockStyle.Fill;
                            tb.Multiline = true;
                            tb.ScrollBars = ScrollBars.Both;
                            tb.Text = addTxt;
                            newTpUser.Controls.Add(tb);
                            newTpUser.Select();
                            ctrl.TabPages.Add(newTpUser);
                            ctrl.SelectedTab = newTpUser;
                        }

                    }

            MonitorAgency.cs中:
              1using System;
              2using System.Collections.Generic;
              3using System.Text;
              4using System.Net;
              5using System.Net.Sockets;
              6using System.Diagnostics;
              7using System.Windows.Forms;
              8using System.IO;
              9using System.Xml;
             10using System.Threading;
             11
             12namespace BurEmluator
             13{
             14    public class MonitorAgency
             15    {
             16        memberVar
             39
             40        property
             48        construct
             61        public bool Connect()
             62        {
             63               
             64                   
             65                    try
             66                    {
             67                        //連接互助SOCK
             68                        ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
             69
             70                        ClientSocket.Connect(EPServer);
             71                        //連接互助SOCK
             72                        client.Connect(IPAddress.Parse(m_proxyIP), Convert.ToInt32(m_proxyPort));
             73
             74                        //發送TELNET IP PORT
             75                        //sendMsg = string.Format("telnet %s %s\r\n",m_proxyIP, m_proxyPort);
             76                        //DispatchMessage(sendMsg);
             77                        readThread = new Thread(new ThreadStart(Read));
             78                        readThread.IsBackground = true;
             79                        readThread.Start();
             80
             81                        return true;
             82                    }

             83                    catch (Exception ex)
             84                    {
             85                        MessageBox.Show(ex.Message);
             86                        return false;
             87                    }

             88               
             89            }

             90        private void Close()
             91        {
             92            if (ClientSocket.Connected)
             93            {
             94                ClientSocket.Close();
             95            }

             96        }
             
             97        protected void Read()
             98        {
             99            while (true)
            100            {
            101                try
            102                {
            103                    Byte[] Rec = new byte[1024];
            104                    NetworkStream netstream = new NetworkStream(ClientSocket);
            105                    int iRev = netstream.Read(Rec, 0, Rec.Length);//讀取客戶發送來的信息。
            106                    string strRev = System.Text.Encoding.GetEncoding("gb2312").GetString(Rec, 0, iRev);
            107                    //輸入需要監控的網元
            108                    if (strRev.Length >= 0)
            109                    {
            110                        if (strRev.IndexOf("請輸入命令"!= -1)
            111                        {
            112                            sendMsg = "track " + m_curNet + "\r\n";
            113
            114                            DispatchMessage(sendMsg);
            115                        }

            116
            117                        else
            118                        {
            119                            int idxend = strRev.LastIndexOf("END");
            120                            int idxj = strRev.LastIndexOf("<");
            121                            int idxn = strRev.LastIndexOf("\n");
            122
            123                            if (idxn == strRev.Length-1 || idxend != -1 || idxj != -1)
            124                            {
            125                                StrMonInfo = StrMonInfo + strRev;
            126                                parser.ProcessResult(StrMonInfo);
            127                                StrMonInfo = "";
            128                            }

            129                            else
            130                            {
            131                                StrMonInfo = StrMonInfo + strRev;
            132                            }

            133                        }

            134                    }

            135                   
            136
            137                }

            138                catch (Exception ex)
            139                {
            140                    MessageBox.Show(ex.Message + ":" + ex.StackTrace.ToString());
            141                }

            142                Thread.Sleep(100);
            143            }

            144        }

            145        public void CloseConnect(bool p)
            146        {
            147            if (client != null)
            148            {
            149                client.Close();
            150            }

            151            if (readThread.IsAlive == true)
            152            {
            153                readThread.Abort();
            154            }

            155        }

            156        private void ReadMonitorXML()
            157        {
            158            string strFilePath = Application.StartupPath + "\\" + "MonitorConfig.xml";
            159            XmlDocument xmlDoc = new XmlDocument();
            160            xmlDoc.Load(strFilePath);
            161            XmlNode xn = xmlDoc.SelectSingleNode("Monitor");
            162            foreach (XmlNode cxn in xn.ChildNodes)
            163            {
            164                if (cxn.Name.Equals("IP"))
            165                {
            166                    m_proxyIP = cxn.InnerText;
            167                }

            168                else if (cxn.Name.Equals("Port"))
            169                {
            170                    m_proxyPort = Convert.ToInt32(cxn.InnerText);
            171                }

            172            }

            173        }

            174        private void DispatchMessage(string sendMsg)
            175        {
            176            NetworkStream netstream = new NetworkStream(ClientSocket);
            177            try
            178            {
            179                Byte[] sendbyte = new Byte[1024];
            180
            181                sendbyte = System.Text.Encoding.GetEncoding("gb2312").GetBytes(sendMsg.ToCharArray());
            182                netstream.Write(sendbyte, 0, sendbyte.Length);//向socket服務器發送信息。
            183                netstream.Flush();
            184            }

            185            catch
            186            {
            187                System.Windows.Forms.MessageBox.Show("發送失敗");
            188                Close();
            189            }

            190        }
               
            191    }

            192     
            193    public class UserActionEventArgs : EventArgs
            194    {
            195        public string Time;
            196        public string ProcID;
            197        public string UserName;
            198        public string IP;
            199        public string Remark;
            200    }

            201
            202    public delegate void UserActionHandler(object sender, UserActionEventArgs args);
            203    public class MonitorResultParser
            204    {
            205        string result;
            206
            207        public event UserActionHandler UserAction;
            208
            209        public void ProcessResult(string strResult)
            210        {
            211            result = strResult;
            212            string strUserAction = "";
            213            int idxBegin = 0, idxEnd = 0;
            214            while ((idxBegin = result.IndexOf("時間:")) >= 0)
            215            {
            216                Debug.Write(result.Length + "\r\n");
            217                idxEnd = result.IndexOf("時間:", idxBegin + 3);
            218                if (idxEnd > idxBegin)
            219                {
            220                    strUserAction = result.Substring(idxBegin, idxEnd - idxBegin);
            221                    Debug.Write(result.Length);
            222                    result = result.Substring(idxEnd);
            223                    Debug.Write(result.Length + "\r\n");
            224                }

            225                else if (idxEnd == -1)
            226                {
            227                    Debug.Write(result.Length);
            228                    strUserAction = result.Substring(idxBegin);
            229                    result = "";
            230                }

            231                Debug.Write(strUserAction.Length + "\r\n");
            232                UserActionEventArgs arg = ParseResult(strUserAction);
            233                UserAction.Invoke(this, arg);
            234            }

            235        }

            236
            237        protected UserActionEventArgs ParseResult(string strUserAction)
            238        {
            239            UserActionEventArgs arg = new UserActionEventArgs();
            240            //解析strUserAction
            241            int itime = strUserAction.IndexOf("時間:");
            242            int ipid = strUserAction.IndexOf("進程號:");
            243            int iuser = strUserAction.IndexOf("用戶:");
            244            int iip = strUserAction.IndexOf("IP:");
            245
            246            int iremark1 = strUserAction.IndexOf("命令:");
            247            int iremark2 = strUserAction.IndexOf("返回信息:");
            248            int iremark3 = strUserAction.IndexOf("提示信息:");
            249            if (itime >= 0 && ipid >= 0)
            250            {
            251                arg.Time = strUserAction.Substring(itime, ipid - itime);
            252            }

            253            if (iuser >= 0)
            254            {
            255                arg.ProcID = strUserAction.Substring(ipid,iuser - ipid);
            256            }

            257            if (iip >= 0)
            258            {
            259                arg.UserName = strUserAction.Substring(iuser,iip - iuser);
            260            }

            261
            262            int iremark = 0;
            263            if(iremark1!=-1)
            264            {
            265                iremark = iremark1;
            266            }

            267            else if(iremark2 != -1)
            268            {
            269                iremark = iremark2;
            270            }

            271            else if(iremark3 != -1)
            272            {
            273                iremark = iremark3;
            274            }

            275            arg.IP = strUserAction.Substring(iip,iremark - iip);
            276            arg.Remark = strUserAction.Substring(iremark);
            277            
            278             return arg;
            279        }

            280
            281    }

            282
            283  
            284    
            285}

            286
            posted on 2008-11-19 09:25 天書 閱讀(2127) 評論(0)  編輯 收藏 引用

            <2008年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            好友的Bolg

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久国产亚洲AV麻豆| 亚洲精品无码久久久久| 久久综合视频网站| 天天躁日日躁狠狠久久| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久久久久狠狠丁香| 久久久久综合中文字幕| 久久精品亚洲一区二区三区浴池| 国产激情久久久久影院| 一本一本久久aa综合精品| 国产精品免费看久久久香蕉| 亚洲第一极品精品无码久久| 久久久久久亚洲精品无码| 久久精品中文无码资源站| 久久婷婷午色综合夜啪| 99久久国产免费福利| 国产精品99久久免费观看| 久久受www免费人成_看片中文 | 无码人妻久久一区二区三区蜜桃| 精品国产乱码久久久久久郑州公司| 久久久艹| segui久久国产精品| 99久久99久久| 久久久久久九九99精品| 亚洲综合伊人久久大杳蕉| 亚洲国产成人精品无码久久久久久综合| 性欧美大战久久久久久久久| 久久综合色老色| 午夜福利91久久福利| 久久免费99精品国产自在现线| 伊人久久综合热线大杳蕉下载| 久久久久亚洲AV成人片| 性欧美丰满熟妇XXXX性久久久| 久久人与动人物a级毛片| 久久久久亚洲国产| 中文字幕无码av激情不卡久久| 美女久久久久久| 中文字幕精品无码久久久久久3D日动漫 | 久久久久久久免费视频| 亚洲午夜精品久久久久久app| 久久伊人色|