示例#1
0
        /// <summary>
        /// Removes the tunnel from the server and closes all connections.
        /// </summary>
        /// <param name="tunnel">The tunnel to be removed.</param>
        /// <param name="notifyServer">if set to <c>true</c> then notify the server of the closure.</param>
        protected virtual async Task RemoveTunnelAsync(ClientTunnel tunnel, bool notifyServer)
        {
            if (Tunnels.TryRemove(tunnel.Id, out var _))
            {
                if (notifyServer)
                {
                    var message = new Message
                    {
                        Type = MessageType.Notification,
                        Code = MessageCode.CloseTunnelMessage
                    };

                    message.Values["tunnel_id"] = tunnel.Id;

                    await SendMessageAsync(message, CancellationToken.None);
                }

                var connections = Connections.Values.Where(a => a.TunnelId == tunnel.Id).ToList();

                foreach (var connection in connections)
                {
                    await RemoveConnectionAsync(connection, false);
                }

                await tunnel.CloseLocalAsync();
            }
        }
示例#2
0
        public void initializeClients()
        {
            int clientsConnected = 0;

            for (int i = 0; i < tunnelSystem.Length; i++)
            {
                if (tunnelSystem[i] == null)
                {
                    tunnelSystem[i] = new ClientTunnel(_serverIp, _serverSocket);
                    if (tunnelSystem[i].isConnected())
                    {
                        clientsConnected++;
                    }
                }
            }
            if (clientsConnected == tunnelSystem.Length)
            {
                MessageBox.Show("all connected");
                initializeBackgroundComs();
            }
            else
            {
                for (int i = 0; i < tunnelSystem.Length; i++)
                {
                    tunnelSystem[i] = null;
                }
            }
        }
示例#3
0
        private void readCurrentPos()
        {
            ClientTunnel tempClient = getNextClient();

            CurrentPos          = new E6Pos(tempClient.readVariable("$POS_ACT"));
            tempClient.IsActive = false;
            CurrentPos.updateCurrentE6Pos(ref _globalCoordinates);
        }
示例#4
0
        private void readCurrentAxis()
        {
            ClientTunnel tempClient = getNextClient();

            CurrentAxis         = new E6Axis(tempClient.readVariable("$AXIS_ACT_MEAS"));
            tempClient.IsActive = false;
            CurrentAxis.updateCurrentE6Axis();
        }
示例#5
0
 public OpenArms(string serverIP, int serverSocket, ref SharedMemorySpace globalCoordinates)
 {
     tunnelSystem = new ClientTunnel[10];
     //initializeClients(serverIP, serverSocket);
     _globalCoordinates = globalCoordinates;
     _serverIp          = serverIP;
     _serverSocket      = serverSocket;
     CurrentAxis        = new E6Axis();
     CurrentPos         = new E6Pos();
 }
示例#6
0
        private void writerAssistant_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            writerAssistTimer.Restart();
            BackgroundWorker worker = (BackgroundWorker)sender;
            E6Pos            tempE6 = new OpenArms.E6Pos();

            tempE6.updateE6Pos(calculateDelta());
            ClientTunnel tempClient = getNextClient();

            tempClient.writeVariable("MYPOS", tempE6.currentValue);
            tempClient.IsActive   = false;
            WriterBackgroundTimer = writerAssistTimer.Elapsed.TotalMilliseconds;
        }
示例#7
0
 /// <summary>
 /// Removes the tunnel from the server and closes all connections.
 /// </summary>
 /// <param name="tunnel">The tunnel to be removed.</param>
 public virtual Task RemoveTunnelAsync(ClientTunnel tunnel)
 {
     return(RemoveTunnelAsync(tunnel, true));
 }
示例#8
0
 /// <summary>
 /// Adds the tunnel.
 /// </summary>
 /// <param name="tunnel">The tunnel.</param>
 public virtual void AddTunnel(ClientTunnel tunnel)
 {
     Tunnels.TryAdd(tunnel.Id, tunnel);
 }