Exemplo n.º 1
0
        private async void LoadTask(IPAddress ip, ICollection <NetworkHost> list)
        {
            Ping      ping = new Ping();
            PingReply res  = await ping.SendPingAsync(ip, 100);

            if (res.Status == IPStatus.Success)
            {
                string hostname = "";
                try
                {
                    IPHostEntry entry = await Dns.GetHostEntryAsync(ip);

                    hostname = entry.HostName;
                }
                catch (Exception)
                {
                    hostname = "";
                }

                HttpWebResponse pingResponse = new HttpSender(string.Format("http://{0}:9000/api/Sync/GetPing", ip.ToString()), 500)
                                               .Send(null)
                                               .Receive();
                if (pingResponse != null && pingResponse.StatusCode == HttpStatusCode.OK)
                {
                    Application.Current.Dispatcher.Invoke(() => list.Add(new NetworkHost()
                    {
                        IP        = ip.ToString(),
                        HostName  = hostname,
                        SyncState = "-",
                    }));
                }
            }
            Application.Current.Dispatcher.Invoke(() => progressBar.Value++);


            Application.Current.Dispatcher.Invoke(() =>
            {
                if (progressBar.Value >= progressBar.Maximum)
                {
                    Application.Current.Dispatcher.Invoke(() => progressBar.Value = 0);
                    finishedHandler?.Invoke(list);
                }
            });
        }
Exemplo n.º 2
0
        private void SyncFromButton_Click(object sender, RoutedEventArgs e)
        {
            NetworkHost host = EvaluateButtonClickNetworkHost(sender);

            if (host == null)
            {
                return;
            }

            HttpWebResponse syncToResponse = new HttpSender(string.Format("http://{0}:9000/api/Sync/RequestSyncFrom", host.IP.ToString()), 10000)
                                             .Send(new SyncRequestData()
            {
                Sender = Dns.GetHostName()
            })
                                             .Receive();

            if (syncToResponse != null && syncToResponse.StatusCode == HttpStatusCode.OK)
            {
                // TODO: disable other buttons and start timout timer for request
            }
        }