Exemplo n.º 1
0
        private void ValidateUploadWorking()
        {
            // Ten seconds after we start uploading we check that the events are being received by the server
            if (DateTime.Now.Subtract(_uploadStartTime).TotalSeconds < 10)
            {
                return;
            }

            if (CommanderWatcher.CommanderIsTracking(_commanderName))
            {
                _uploadValidated = true;
                CommanderWatcher.Stop();
                return;
            }

            // We don't appear to be listed on the server
            if (DateTime.Now.Subtract(_uploadStartTime).TotalSeconds > 15)
            {
                // More than 15 seconds has passed, so we disable upload and warn
                CommanderWatcher.Stop();
                Action action = new Action(() => {
                    checkBoxUpload.Checked = false;
                    MessageBox.Show(this, "Upload has been disabled as server is not receiving your events.\r\nTypical causes are firewall or security software.\r\nPlease resolve issue and try again.", "Upload Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                });
                if (checkBoxUpload.InvokeRequired)
                {
                    checkBoxUpload.Invoke(action);
                }
                else
                {
                    action();
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateAvailableCommanders()
        {
            // Show the list of online commanders (those available for tracking)

            string info   = "No commanders found";
            Action action = new Action(() => {
                listBoxCommanders.Items.Clear();
                listBoxCommanders.Items.Add(info);
            });

            if (String.IsNullOrEmpty(ServerAddress))
            {
                info = "Invalid server address";
            }
            else
            {
                if (CommanderWatcher.OnlineCommanderCount > 0)
                {
                    action = new Action(() =>
                    {
                        listBoxCommanders.BeginUpdate();
                        int selectedIndex = listBoxCommanders.SelectedIndex;
                        listBoxCommanders.Items.Clear();
                        foreach (string commander in CommanderWatcher.GetCommanders())
                        {
                            listBoxCommanders.Items.Add(commander);
                        }
                        if (selectedIndex >= 0 && selectedIndex < listBoxCommanders.Items.Count)
                        {
                            listBoxCommanders.SelectedIndex = selectedIndex;
                        }
                        listBoxCommanders.EndUpdate();
                    });
                }
            }

            if (listBoxCommanders.InvokeRequired)
            {
                listBoxCommanders.Invoke(action);
            }
            else
            {
                action();
            }
        }
Exemplo n.º 3
0
 private void buttonPlayers_Click(object sender, EventArgs e)
 {
     if (this.Width == _commanderListHiddenWidth)
     {
         this.Width            = _normalView.Width;
         _commanderListShowing = true;
         CommanderWatcher.Start($"http://{ServerAddress}:11938/DataCollator");
         UpdateAvailableCommanders();;
         CommanderWatcher.OnlineCountChanged += CommanderWatcher_OnlineCountChanged;
     }
     else
     {
         CommanderWatcher.Stop();
         this.Width            = _commanderListHiddenWidth;
         _commanderListShowing = false;
         CommanderWatcher.OnlineCountChanged -= CommanderWatcher_OnlineCountChanged;
     }
 }
Exemplo n.º 4
0
 private bool CreateUdpClient()
 {
     // Create the UDP client for sending tracking data
     CommanderWatcher.Start($"http://{ServerUrl()}:11938/DataCollator");  // Needed to check that the upload is working
     try
     {
         _uploadValidated = false;
         _uploadStartTime = DateTime.Now;
         _udpClient       = new UdpClient(ServerUrl(), (int)numericUpDownUdpUploadPort.Value);
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, $"Failed to create UDP upload client.\r\nTypical causes are firewall or security software.\r\nPlease resolve issue and try again.\r\n\r\nError:{ex.Message}", "Upload Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
         checkBoxUpload.Checked = false;
     }
     return(false);
 }
Exemplo n.º 5
0
        private void UpdateTrackingTarget(string target)
        {
            Action action;

            TrackingTarget = target;

            if (_targetPosition == null)
            {
                EDEvent commanderEvent = CommanderWatcher.GetCommanderMostRecentEvent(target);
                if (commanderEvent != null)
                {
                    _targetPosition = commanderEvent.Location();
                }
            }

            locatorHUD1.SetTarget(target);
            string bearingInfo = $"Bearing (tracking {target})";

            if (String.IsNullOrEmpty(target))
            {
                bearingInfo = "Bearing (target not set)";
            }

            if (String.IsNullOrEmpty(TrackingTarget))
            {
                if (buttonTrackCommander.Text.Equals("Stop"))
                {
                    action = new Action(() => { buttonTrackCommander.Text = "Track"; });
                    if (buttonTrackCommander.InvokeRequired)
                    {
                        buttonTrackCommander.Invoke(action);
                    }
                    else
                    {
                        action();
                    }
                }
            }
        }