コード例 #1
0
        private void PingTestThreadError(PingTest ping, String msg)
        {
            VPNSERVERITEM item = (VPNSERVERITEM)ping.UserData;

            Invoke((MethodInvoker) delegate
            {
                ListViewItem lvItem = listView1.FindItemWithText(item.raw_ip);
                if (lvItem != null)
                {
                    lvItem.SubItems[4].Text = msg;
                }
            });
        }
コード例 #2
0
        private void PingTestThreadStart(PingTest ping)
        {
            VPNSERVERITEM item = (VPNSERVERITEM)ping.UserData;

            Invoke((MethodInvoker) delegate
            {
                ListViewItem lvItem = listView1.FindItemWithText(item.raw_ip);
                if (lvItem != null)
                {
                    lvItem.SubItems[4].Text = "PING START";
                }
            });
        }
コード例 #3
0
        private void PingTestThreadFinish(PingTest ping, int pingSpeed)
        {
            VPNSERVERITEM item = (VPNSERVERITEM)ping.UserData;

            Invoke((MethodInvoker) delegate
            {
                ListViewItem lvItem = listView1.FindItemWithText(item.raw_ip);
                if (lvItem != null)
                {
                    listView1.TopItem       = lvItem;
                    lvItem.SubItems[4].Text = "PING FIN";
                    lvItem.SubItems[3].Text = String.Format("{0}ms", pingSpeed);
                }
            });
        }
コード例 #4
0
        private void UpdateVpnServerList(IntPtr wndListView)
        {
            ListView             listView      = new ListView(wndListView);
            int                  count         = listView.ItemCount;
            List <VPNSERVERITEM> vpnServerList = new List <VPNSERVERITEM>();

            Log(String.Format("[UpdateVpnServerList] ItemCount={0}", count));

            for (int i = 0; i < count; i++)
            {
                VPNSERVERITEM item = new VPNSERVERITEM();

                item.raw_ip      = listView.GetItem(i, 1);
                item.raw_country = listView.GetItem(i, 2);
                item.raw_speed   = listView.GetItem(i, 5);

                item.nItemIndex = i;
                item.qual_ip    = item.raw_ip;
                int idx = item.qual_ip.IndexOf("(");
                if (idx >= 0)
                {
                    item.qual_ip = item.raw_ip.Substring(0, idx);
                    item.qual_ip.Trim();
                }

                vpnServerList.Add(item);
            }

            if (vpnServerList.Count == 0)
            {
                Log(String.Format("Retrieved server list ItemCount={0}", count));
                return;
            }

            vpnServerList.Select(x => x.raw_ip).Distinct();

            List <String> FilterCountry = new List <string>();

            if (checkBox1.Checked)
            {
                // 필터 적용할 국가 선택
                foreach (var item in vpnServerList)
                {
                    if (FilterCountry.FindIndex(x => x.Equals(item.raw_country)) == -1)
                    {
                        FilterCountry.Add(item.raw_country);
                    }
                }

                // 필터 국가를 FilterCountry에서 제거.
                foreach (String item in listBox1.Items)
                {
                    int idx = FilterCountry.FindIndex(x => x.Equals(item));
                    if (idx >= 0)
                    {
                        FilterCountry.RemoveAt(idx);
                    }
                }
            }
            else
            {
                FilterCountry.Clear();
            }


            // 남은 국가의 아이템을 모두 삭제
            foreach (String item in FilterCountry)
            {
                while (true)
                {
                    int idx = vpnServerList.FindIndex(x => x.raw_country.Equals(item));
                    if (idx < 0)
                    {
                        break;
                    }

                    vpnServerList.RemoveAt(idx);
                }
            }

            m_vpnServerList = vpnServerList;

            List <String> oldServerIP = new List <string>();

            foreach (ListViewItem item in listView1.Items)
            {
                oldServerIP.Add(item.Text);
            }

            foreach (var item in vpnServerList)
            {
                int index = oldServerIP.FindIndex(x => x.Equals(item.raw_ip));
                if (index == -1)
                {
                    ListViewItem lvItem = new ListViewItem();
                    lvItem.Text = item.raw_ip;
                    lvItem.SubItems.Add(item.raw_country);
                    lvItem.SubItems.Add(item.raw_speed);
                    lvItem.SubItems.Add("");
                    lvItem.SubItems.Add("");
                    listView1.Items.Add(lvItem);
                }
                else
                {
                    oldServerIP.RemoveAt(index);
                }
            }

            if (oldServerIP.Count > 0)
            {
                foreach (var item in oldServerIP)
                {
                    ListViewItem lvItem = listView1.FindItemWithText(item);
                    if (lvItem != null)
                    {
                        listView1.Items.Remove(lvItem);
                    }
                }
            }
        }
コード例 #5
0
        private bool checkVpnServerPingTest()
        {
            Log("[checkVpnServerPingTest]");

            int threadCount = 0;

            foreach (var item in m_vpnServerList)
            {
                if (item.pingTest != null && !item.pingTest.JobFinish)
                {
                    threadCount++;
                }
            }

            Log(String.Format("Check Current PingTest = {0}", threadCount));

            if (threadCount >= 10)
            {
                timer1.Interval = 300;
                return(true);
            }

            for (int i = 0; i < m_vpnServerList.Count; i++)
            {
                VPNSERVERITEM item = m_vpnServerList[i];

                if (item.pingTest == null)
                {
                    item.pingTest                       = new PingTest(item.qual_ip);
                    item.pingTest.UserData              = item;
                    item.pingTest.PingThreadStartEvent += PingTestThreadStart;
                    item.pingTest.PingThreadErrorEvent += PingTestThreadError;
                    item.pingTest.PingThreadFinshEvent += PingTestThreadFinish;
                    item.pingTest.Start(true);
                    threadCount++;
                    m_vpnServerList[i] = item;

                    if (threadCount >= 10)
                    {
                        break;
                    }
                }
            }
            Log(String.Format("Adjusted Current PingTest = {0}", threadCount));

            if (threadCount > 0)
            {
                timer1.Interval = 300;
                return(true);
            }

            List <String> itemsToRemove = new List <string>();

            // 이제 PING Test가 완료 됨.
            for (int i = m_vpnServerList.Count - 1; i >= 0; i--)
            {
                VPNSERVERITEM item = m_vpnServerList[i];

                if (item.pingTest == null)
                {
                    itemsToRemove.Add(item.raw_ip);
                    m_vpnServerList.RemoveAt(i);
                    continue;
                }

                if (item.pingTest.JobFinish && !item.pingTest.ResultOK)
                {
                    itemsToRemove.Add(item.raw_ip);
                    m_vpnServerList.RemoveAt(i);
                }
            }

            // 이제 List View에서도 삭제 한다.
            foreach (String item in itemsToRemove)
            {
                ListViewItem lvItem = listView1.FindItemWithText(item);
                if (lvItem != null)
                {
                    listView1.Items.Remove(lvItem);
                }
            }

            for (int i = listView1.Items.Count - 1; i >= 0; i--)
            {
                ListViewItem item = listView1.Items[i];
                if (item.SubItems[3].Text.Length == 0 && item.SubItems[4].Text.Length == 0)
                {
                    listView1.Items.RemoveAt(i);
                }
            }
            Log(String.Format("Ultimate VPN Server Count = {0}", m_vpnServerList.Count));

//            m_vpnServerList.OrderByDescending(p => p.pingTest.PingSpeed);


            m_vpnServerList.Sort(
                delegate(VPNSERVERITEM p1, VPNSERVERITEM p2)
            {
                int compareDate = 1;

                if (p1.pingTest.PingSpeed < p2.pingTest.PingSpeed)
                {
                    compareDate = -1;
                }

                return(compareDate);
            }
                );


            timer1.Interval = 10;
            m_procSequence  = connectTryVPNServerItem;

            return(true);
        }