Esempio n. 1
0
        /// <summary>
        /// Connects the dashboard to the robot with the given address.
        /// </summary>
        /// <param name="connectAddress">The address to try connecting to.</param>
        /// <param name="functionToExecuteOnConnect">The function to call IMMEDIATELY when the robot is connected.
        /// Faster than waiting for the event to run.</param>
        public async void Connect(string connectAddress, Action <bool> functionToExecuteOnConnect = null)
        {
            IsConnecting = true;

            // Make it a string and trim so this works properly
            ConnectedAddress = connectAddress.ToString();
            ConnectedAddress = ConnectedAddress.Trim();


            CancellationTokenSource cts = new CancellationTokenSource();
            bool connected = await Task.Run <bool>(() => ConnectAsync(cts.Token));

            // Call the action that was requested to be executed on connect, if it's not null
            functionToExecuteOnConnect?.Invoke(connected);

            IsConnecting = false;

            ConnectionEvent?.Invoke(this, IsConnected);

            // Populate the Tables dictionary
            if (connected)
            {
                await Task.Run(PopulateTablesAsync);

                // Call changed events
                CallChangedMethodsForAll();
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object getOption(int optID) throws SocketException
        public override Object GetOption(int optID)
        {
            if (Closed)
            {
                throw new SocketException("Socket Closed");
            }

            if (optID == SocketOptions_Fields.SO_BINDADDR)
            {
                if ((Fd != null && Fd1 != null) && !Connected)
                {
                    return(AnyLocalBoundAddr);
                }
                int family = ConnectedAddress == null ? -1 : ConnectedAddress.Holder().Family;
                return(socketLocalAddress(family));
            }
            else if (optID == SocketOptions_Fields.SO_REUSEADDR && ReuseAddressEmulated)
            {
                return(IsReuseAddress);
            }
            else
            {
                return(base.GetOption(optID));
            }
        }