Ejemplo n.º 1
0
        public void Connect()
        {
            TvDirectSocket = new Windows.Networking.Sockets.StreamSocket();
            TvDirectSocket.ConnectAsync(ConnectedHostName, ConnectedPort.ToString()).Completed += newConnected;
            ConnectionState = TvConnectionState.Connecting;

            Connecting?.Invoke();
        }
Ejemplo n.º 2
0
        private async void HandleRegistrationResponse(byte[] regResponse)
        {
            bool bDisconnect            = true;
            bool bUpdateConnectionState = true;

            if (AreArraysEqual(regResponse, ALLOWED_BYTES))
            {
                System.Diagnostics.Debug.WriteLine("ALLOWED");
                bDisconnect = false;
                RegistrationAccepted?.Invoke();
            }
            else if (AreArraysEqual(regResponse, DENIED_BYTES))
            {
                System.Diagnostics.Debug.WriteLine("DENIED");
                RegistrationDenied?.Invoke();
            }
            else if (AreArraysEqual(regResponse, TIMEOUT_BYTES))
            {
                System.Diagnostics.Debug.WriteLine("TIMEOUT");
                RegistrationTimedOut?.Invoke();
            }
            else if (ArrayStartsWith(AWAITING_APPROVAL_PREFIX, regResponse, AWAITING_APPROVAL_TOTAL))
            {
                System.Diagnostics.Debug.WriteLine("AWAITING");
                RegistrationWaiting?.Invoke();
                bDisconnect            = false;
                bUpdateConnectionState = false;
            }
            else
            {
                //RegistrationDenied?.Invoke();
                System.Diagnostics.Debug.WriteLine("UNKNOWN");
                bDisconnect            = false;
                bUpdateConnectionState = false;
            }

            if (bDisconnect)
            {
                System.Diagnostics.Debug.WriteLine("[reg] disconnecting (bdisconnect)");
                Cleanup();
                NotifyDisconnected();
            }
            else
            {
                if (bUpdateConnectionState)
                {
                    ConnectionState = TvConnectionState.Connected;
                }
                else
                {
                    await ListenForRegistrationResponse();
                }
            }
        }
Ejemplo n.º 3
0
 private async void newRegistrationSent(IAsyncOperation <uint> info, AsyncStatus status)
 {
     if (status == AsyncStatus.Completed)
     {
         Registering?.Invoke();
         await ListenForRegistrationResponse();
     }
     else
     {
         RegistrationFailed?.Invoke();
         ConnectionState = TvConnectionState.Disconnected;
     }
 }
Ejemplo n.º 4
0
        private void newConnected(IAsyncAction info, AsyncStatus status)
        {
            if (status == AsyncStatus.Completed)
            {
                ConnectionState = TvConnectionState.AwaitingAuthorization;
                Reader          = new DataReader(TvDirectSocket.InputStream);
                Writer          = new DataWriter(TvDirectSocket.OutputStream);

                Connected?.Invoke();

                var reg = GetRegistration();
                SendBytes(reg, newRegistrationSent);
            }
            else
            {
                NotifyDisconnected();
            }
        }
Ejemplo n.º 5
0
 protected void NotifyDisconnected()
 {
     ConnectionState = TvConnectionState.Disconnected;
     Disconnected?.Invoke();
 }
Ejemplo n.º 6
0
        private void newConnected(IAsyncAction info, AsyncStatus status)
        {
            if (status == AsyncStatus.Completed)
            {
                ConnectionState = TvConnectionState.AwaitingAuthorization;
                Reader = new DataReader(TvDirectSocket.InputStream);
                Writer = new DataWriter(TvDirectSocket.OutputStream);

                if (Connected != null)
                {
                    Connected();
                }

                var reg = GetRegistration();
                SendBytes(reg, newRegistrationSent);
            }
            else
            {
                NotifyDisconnected();
            }
        }
Ejemplo n.º 7
0
 protected void NotifyDisconnected()
 {
     ConnectionState = TvConnectionState.Disconnected;
     if (Disconnected != null)
     {
         Disconnected();
     }
 }
Ejemplo n.º 8
0
        public void Connect()
        {
            TvDirectSocket = new Windows.Networking.Sockets.StreamSocket();
            TvDirectSocket.ConnectAsync(ConnectedHostName, ConnectedPort.ToString()).Completed += newConnected;
            ConnectionState = TvConnectionState.Connecting;

            if (Connecting != null)
            {
                Connecting();
            }
        }
Ejemplo n.º 9
0
        private async void HandleRegistrationResponse(byte[] regResponse)
        {
            bool bDisconnect = true;
            bool bUpdateConnectionState = true;

            if (AreArraysEqual(regResponse, ALLOWED_BYTES))
            {
                System.Diagnostics.Debug.WriteLine("ALLOWED");
                bDisconnect = false;
                if (RegistrationAccepted != null)
                {
                    RegistrationAccepted();
                }
            }
            else if (AreArraysEqual(regResponse, DENIED_BYTES))
            {
                System.Diagnostics.Debug.WriteLine("DENIED");
                if (RegistrationDenied != null)
                {
                    RegistrationDenied();
                }
            }
            else if (AreArraysEqual(regResponse, TIMEOUT_BYTES))
            {
                System.Diagnostics.Debug.WriteLine("TIMEOUT");
                if (RegistrationTimedOut != null)
                {
                    RegistrationTimedOut();
                }
            }
            else if (ArrayStartsWith(AWAITING_APPROVAL_PREFIX, regResponse, AWAITING_APPROVAL_TOTAL))
            {
                System.Diagnostics.Debug.WriteLine("AWAITING");
                if (RegistrationWaiting != null)
                {
                    RegistrationWaiting();
                }
                bDisconnect = false;
                bUpdateConnectionState = false;
            }
            else
            {
                //if (RegistrationDenied != null)
                //{
                //    RegistrationDenied();
                //}
                System.Diagnostics.Debug.WriteLine("UNKNOWN");
                bDisconnect = false;
                bUpdateConnectionState = false;
            }

            if (bDisconnect)
            {
                System.Diagnostics.Debug.WriteLine("[reg] disconnecting (bdisconnect)");
                Cleanup();
                NotifyDisconnected();
            }
            else
            {
                if (bUpdateConnectionState)
                {
                    ConnectionState = TvConnectionState.Connected;
                }
                else
                {
                    await ListenForRegistrationResponse();
                }
            }
        }
Ejemplo n.º 10
0
        private async void newRegistrationSent(IAsyncOperation<uint> info, AsyncStatus status)
        {
            if (status == AsyncStatus.Completed)
            {
                if (Registering != null)
                {
                    Registering();
                }

                await ListenForRegistrationResponse();
            }
            else
            {
                if (RegistrationFailed != null)
                {
                    RegistrationFailed();
                }

                ConnectionState = TvConnectionState.Disconnected;
            }
        }