예제 #1
0
        private void picRefresh_MouseDown(object sender, MouseEventArgs e)
        {
            picRefresh.Hide();
            var ipadd = txtIP.Text;

            Task.Run(() => {
                var res = InternetTools.GetConnectableAliases(ipadd).Result;
                if (res == null || res.Count == 0)
                {
                    picRefresh.Show();
                    return;
                }
                var ips = res.Where(ip => ip.AddressFamily == AddressFamily.InterNetwork).Select(ip => ip.ToString()).ToArray();
                Invoke(new MethodInvoker(() => {
                    txtIP.Text = "";
                    txtIP.Items.Clear();
                    txtIP.Items.AddRange(ips);
                    if (txtIP.Items.Count > 0)
                    {
                        txtIP.SelectedIndex = 0;
                    }
                    picRefresh.Show();
                }));
            });
        }
        private async Task <Bitmap> Get()
        {
            var sw = Stopwatch.StartNew();

            await InternetTools.WaitForInternetConnection(TimeSpan.FromSeconds(1));

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://loremflickr.com/800/800");

            webRequest.Timeout = 5000;

            using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
            {
                logger.LogDebug($"Redirected to {webResponse.ResponseUri}.");
                System.IO.Stream responseStream = webResponse.GetResponseStream();
                logger.LogDebug($"Got image in: {sw.ElapsedMilliseconds}ms.");
                return(new Bitmap(responseStream));
            }
        }
예제 #3
0
        private void btnComplete_Click(object sender, EventArgs e)
        {
            if (txtIP.Enabled == false && txtPort.Enabled == false)
            {
                goto _successful;
            }

            if (string.IsNullOrEmpty(txtIP.Text) || string.IsNullOrEmpty(txtPort.Text))
            {
                SystemSounds.Beep.Play();
                return;
            }
            bool conn_test = false;

            try {
                conn_test = InternetTools.TestHostConnection(IPAddress.Parse(txtIP.Text), 1);
            } catch (Exception) {
                MessageBoxy.Show("לא היה ניתן לאתר את הכתובת שהוזנה, נסה ללחוץ על כפתור הריענון ובחר את אחת מההצעות.\nאם אין כלל, סימן שהכתובת לא קיימת או לא זמינה.", "שגיאה",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error, true);
                return;
            }

            if (conn_test == false)
            {
                if (ForceTesting == false)
                {
                    if (MessageBoxy.Show("לא היה ניתן לאתר את הכתובת שהוזנה, האם ברצונך בכל זאת להמשיך?", "תוצאות הבדיקה", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, true) == DialogResult.No)
                    {
                        return;
                    }
                }
                else
                {
                    MessageBoxy.Show("לא היה ניתן לאתר את הכתובת שהוזנה, אנא נסה שנית או מאוחר יותר", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, true);
                }
            }

_successful:
            _ip            = txtIP.Text;
            _port          = txtPort.Text.ToInt32();
            PlannedClosing = true;
            Hide();
            Close();
        }