Exemplo n.º 1
0
        /// <summary>
        /// This function is used to adjust the tunnel and cell coordinates.
        /// </summary>
        private void AdjustNegativePoint()
        {
            // First, we need to shift the cells and tunnels to get rid of
            // any negative coordinates.
            Point lowestNegative = GetLowestPoint();

            // Invert them and add 2, and then add them back to the cells and tunnels.
            // Only add the ones that are in a negative.
            if (lowestNegative.X < 0)
            {
                lowestNegative.X *= -1;
                lowestNegative.X += 2;
                Cells.ForEach(obj => obj.Location.X += lowestNegative.X);
                Tunnels.ForEach(obj => obj.AnglePoint.ForEach(obj2 => obj2.X += lowestNegative.X));
            }
            if (lowestNegative.Y < 0)
            {
                lowestNegative.Y *= -1;
                lowestNegative.Y += 2;
                Cells.ForEach(obj => obj.Location.Y += lowestNegative.Y);
                Tunnels.ForEach(obj => obj.AnglePoint.ForEach(obj2 => obj2.Y += lowestNegative.Y));
            }
        }
Exemplo n.º 2
0
        private void HandleRefreshedTunnels(List <CnCNetTunnel> tunnels)
        {
            if (tunnels.Count > 0)
            {
                Tunnels = tunnels;
            }

            TunnelsRefreshed?.Invoke(this, EventArgs.Empty);

            Task[] pingTasks = new Task[Tunnels.Count];

            for (int i = 0; i < Tunnels.Count; i++)
            {
                if (UserINISettings.Instance.PingUnofficialCnCNetTunnels || Tunnels[i].Official || Tunnels[i].Recommended)
                {
                    pingTasks[i] = PingListTunnelAsync(i);
                }
            }

            if (CurrentTunnel != null)
            {
                var updatedTunnel = Tunnels.Find(t => t.Address == CurrentTunnel.Address && t.Port == CurrentTunnel.Port);
                if (updatedTunnel != null)
                {
                    // don't re-ping if the tunnel still exists in list, just update the tunnel instance and
                    // fire the event handler (the tunnel was already pinged when traversing the tunnel list)
                    CurrentTunnel = updatedTunnel;
                    DoCurrentTunnelPinged();
                }
                else
                {
                    // tunnel is not in the list anymore so it's not updated with a list instance and pinged
                    PingCurrentTunnelAsync();
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds the tunnel.
 /// </summary>
 /// <param name="tunnel">The tunnel.</param>
 public virtual void AddTunnel(Tunnel tunnel)
 {
     Tunnels.TryAdd(tunnel.Id, tunnel);
 }