Example #1
0
 private void UpdateUserInterfacePingCancelled()
 {
     Outputfield.AppendText("cancelling...\n");
 }
Example #2
0
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //===============================Functions that are under control======================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================
        //        ==============================



        private int ParseInput()
        {
            string storepattern = "([0-9]+)";
            Match  storenumbermatch;

            storenumbermatch = Regex.Match(addressinputvar, storepattern, RegexOptions.IgnoreCase | RegexOptions.Compiled, TimeSpan.FromSeconds(5));
            //MessageBox.Show("in ws " + addressinputvar);
            progressbar.Dispatcher.BeginInvoke(DispatcherPriority.Send, new ThreadDelegate(new Action(() => UpdateProgressbar(10))));
            AnimateprogressbarAsync();
            isValidIp = IPAddress.TryParse(addressinputvar, out addr);
            //MessageBox.Show("1"+storenumbermatch.Groups[0].Value);

            if (devicetype != "")
            {
                if (storenumbermatch.Success == false)
                {
                    MessageBox.Show("F" + storenumbermatch.Groups[0].Value);
                    cancelrequested = true;
                    CancelButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(DisableCancelButton));
                    PingButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(EnablePingButton));
                    Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(UpdateOutputFailed));
                    //Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(UpdateUserInterfacePingComplete));
                    progressbar.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => UpdateProgressbar(0))));
                    return(1);
                }
            }
            if (addressinputvar != Convert.ToString(addr))
            {
                //MessageBox.Show("S" + storenumbermatch.Groups[0].Value);
                if (devicetype != "")
                {
                    storenumber = storenumbermatch.Groups[0].Value;
                    storenumber = storenumber.PadLeft(5, '0');
                    storenumber = devicetype + storenumber;
                }
                else
                {
                    storenumber = addressinputvar;
                }

                Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Send, new ThreadDelegate(new Action(() => ResolvingHostUpdate(storenumber))));
                try
                {
                    hostEntry = Dns.GetHostEntry(storenumber);
                }
                catch (System.Net.Sockets.SocketException)
                {
                    cancelrequested = true;
                    Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => Outputfield.AppendText("Store number " + storenumber + " could not be resolved.\n"))));
                    CancelButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(DisableCancelButton));
                    PingButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(EnablePingButton));
                    Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(UpdateOutputFailed));
                    //Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(UpdateUserInterfacePingComplete));
                    progressbar.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => UpdateProgressbar(0))));
                    return(1);
                }
                addr = hostEntry.AddressList[0];

                progressbar.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => UpdateProgressbar(50))));
            }
            else
            {
                try {
                    addr = IPAddress.Parse(addressinputvar);
                }
                catch
                {
                    MessageBox.Show("IP Address was invalid and could not be used");
                }
            }
            progressbar.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => UpdateProgressbar(0))));
            Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(clearoutbox));
            Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => Outputfield.AppendText("Sending pings to " + storenumber + "(" + addr + "):\n"))));
            window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => UpdateLogBox("Sending pings to " + storenumber + "(" + addr + "):\n"))));
            window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(window2.LogBox2.ScrollToEnd));
            return(1);
        }
Example #3
0
 private void UpdateUserInterfacePingComplete()
 {
     Outputfield.AppendText("Ping complete\n");
     Outputfield.ScrollToEnd();
 }
Example #4
0
        //.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => )));
        private void UpdateUserInterface(int bitesize, int ttl, long rtt)
        {
            try
            {
                ri1rttmax     = rtts.Max();
                ri1rttmin     = rtts.Min();
                ri1rttaverage = Convert.ToInt16(rtts.Average());
            }
            catch (Exception e)
            {
            }
            Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(Outputfield.ScrollToEnd));
            //MessageBox.Show("status in update is " + Convert.ToString(status));
            if (cancelrequested == true)
            {
                return;
            }
            if (status == IPStatus.Success)
            {
                Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => Outputfield.AppendText(senttotal + " Reply from " + addr + ": bytes=" + bitesize + " time=" +
                                                                                                                                         rtt + "ms TTL=" + ttl + "\n"))));
                window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => window2.LogBox2.AppendText(senttotal + " Reply from " + addr + ": bytes=" + bitesize + " time=" +
                                                                                                                                                 rtt + "ms TTL=" + ttl + "\n"))));
                if (storenumber == "")
                {
                    StatisticsBox.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => box1 = StatisticsBox.Text = "Ping statistics for " + addr + ":\n    Packets: Sent = " + senttotal + ", Received = " + receivedtotal +
                                                                                                                                                    ", Lost = " + losttotal + "(" + (Convert.ToInt16(((Convert.ToDouble(losttotal) / (Convert.ToDouble(senttotal)) * 100.0)))) + "% loss),\n"
                                                                                                                                                    + "Approximate round trip times in milli-seconds:\n"
                                                                                                                                                    + "    Minimum = " + ri1rttmin + "ms, Maximum = " + ri1rttmax + "ms, Average = " + ri1rttaverage + "ms\n")));

                    window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(window2.LogBox2.ScrollToEnd));
                }
                if (storenumber != "")
                {
                    StatisticsBox.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => box1 = StatisticsBox.Text = "Ping statistics for " + addr + "(" + storenumber + "):\n    Packets: Sent = " + senttotal + ", Received = " + receivedtotal +
                                                                                                                                                    ", Lost = " + losttotal + "(" + (Convert.ToInt16(((Convert.ToDouble(losttotal) / (Convert.ToDouble(senttotal)) * 100.0)))) + "% loss),\n"
                                                                                                                                                    + "Approximate round trip times in milli-seconds:\n"
                                                                                                                                                    + "    Minimum = " + ri1rttmin + "ms, Maximum = " + ri1rttmax + "ms, Average = " + ri1rttaverage + "ms\n")));
                    window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(window2.LogBox2.ScrollToEnd));
                }
            }
            else
            {
                switch (status)
                {
                case IPStatus.TimedOut:
                    outs = (senttotal + " Request timed out.\n");
                    break;

                case IPStatus.BadDestination:
                    outs = (senttotal + " Bad destination\n");
                    break;

                case IPStatus.DestinationHostUnreachable:
                    outs = (senttotal + " Destination host unreachable.\n");
                    break;

                case IPStatus.DestinationNetworkUnreachable:
                    outs = (senttotal + " Destination network unreachable.\n");
                    break;

                case IPStatus.DestinationUnreachable:
                    outs = (senttotal + " Destination unreachable.\n");
                    break;

                case IPStatus.HardwareError:
                    outs = (senttotal + " Hardware failure.\n");
                    break;

                case IPStatus.NoResources:
                    outs = (senttotal + " Insufficient resources to complete request.\n");
                    break;

                case IPStatus.PacketTooBig:
                    outs = (senttotal + " Packet sent was too big.\n");
                    break;

                case IPStatus.ParameterProblem:
                    outs = (senttotal + " Parameters are invalid.\n");
                    break;

                case IPStatus.SourceQuench:
                    outs = (senttotal + " Reported source quench.\n");
                    break;

                case IPStatus.TimeExceeded:
                    outs = (senttotal + " TTL expired in transit.\n");
                    break;

                case IPStatus.TtlExpired:
                    outs = (senttotal + " TTL expired in transit.\n");
                    break;

                case IPStatus.TtlReassemblyTimeExceeded:
                    outs = (senttotal + " TTL expired in transit.\n");
                    break;

                case IPStatus.Unknown:
                    outs = (senttotal + " Unknown Failure.\n");
                    break;

                case IPStatus.UnrecognizedNextHeader:
                    outs = (senttotal + " Unrecognized next header.\n");
                    break;
                }
                Outputfield.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => Outputfield.AppendText(outs))));
                window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => window2.LogBox2.AppendText(outs))));
                window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(window2.LogBox2.ScrollToEnd));
                if (storenumber == "")
                {
                    StatisticsBox.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => box1 = StatisticsBox.Text = "Ping statistics for " + addr + ":\n    Packets: Sent = " + senttotal + ", Received = " + receivedtotal +
                                                                                                                                                    ", Lost = " + losttotal + "(" + (Convert.ToInt16(((Convert.ToDouble(losttotal) / (Convert.ToDouble(senttotal)) * 100.0)))) + "% loss),\n"
                                                                                                                                                    + "Approximate round trip times in milli-seconds:\n"
                                                                                                                                                    + "    Minimum = " + ri1rttmin + "ms, Maximum = " + ri1rttmax + "ms, Average = " + ri1rttaverage + "ms\n")));

                    window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(window2.LogBox2.ScrollToEnd));
                }
                if (storenumber != "")
                {
                    StatisticsBox.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(new Action(() => box1 = StatisticsBox.Text = "Ping statistics for " + addr + "(" + storenumber + "):\n    Packets: Sent = " + senttotal + ", Received = " + receivedtotal +
                                                                                                                                                    ", Lost = " + losttotal + "(" + (Convert.ToInt16(((Convert.ToDouble(losttotal) / (Convert.ToDouble(senttotal)) * 100.0)))) + "% loss),\n"
                                                                                                                                                    + "Approximate round trip times in milli-seconds:\n"
                                                                                                                                                    + "    Minimum = " + ri1rttmin + "ms, Maximum = " + ri1rttmax + "ms, Average = " + ri1rttaverage + "ms\n")));
                    window2.LogBox2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadDelegate(window2.LogBox2.ScrollToEnd));
                }
            }
        }