• <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年11月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            好友的Bolg

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            欧美熟妇另类久久久久久不卡| 精品久久久久久综合日本| 国产A三级久久精品| 国产精品久久久久久久久鸭| 久久婷婷五月综合色99啪ak| 欧洲成人午夜精品无码区久久 | 久久久久夜夜夜精品国产| 国产成人综合久久精品尤物| 久久精品国产亚洲AV不卡| 51久久夜色精品国产| 久久精品国产免费观看| 9191精品国产免费久久| 伊人久久综合精品无码AV专区| 狠狠综合久久综合中文88| 亚洲va久久久噜噜噜久久狠狠| 99久久精品久久久久久清纯| 久久亚洲精品人成综合网| 久久久久亚洲av毛片大| 99999久久久久久亚洲| 2021国内久久精品| 久久久久国色AV免费观看| 久久精品免费一区二区三区| 国产精品久久婷婷六月丁香| 久久精品国产亚洲5555| 7777久久亚洲中文字幕| 人妻无码αv中文字幕久久琪琪布| 久久久噜噜噜久久| 亚洲伊人久久大香线蕉苏妲己| 久久99热只有频精品8| 无码国产69精品久久久久网站| 久久99九九国产免费看小说| 久久久久九九精品影院| 99久久精品免费国产大片| 久久―日本道色综合久久| 热re99久久6国产精品免费| 亚洲国产精品18久久久久久| 久久无码AV中文出轨人妻| 思思久久精品在热线热| 欧美性大战久久久久久| 亚洲综合久久久| 精品国产日韩久久亚洲|