public HTransportManager(HTransport tranpsport) 
        {
            this.Transport = tranpsport;
            this.Transport.onData += Transport_onData;
            this.Transport.onStatus += Transport_onStatus;
            ConnectionProfile internetConnectProfile = NetworkInformation.GetInternetConnectionProfile();
            if (internetConnectProfile == null)
                this.hasNetwork = false;
            else
            {
                switch (internetConnectProfile.GetNetworkConnectivityLevel())
                { 
                    case NetworkConnectivityLevel.None:
                        this.hasNetwork = false;
                        break;
                    case NetworkConnectivityLevel.LocalAccess:
                    case NetworkConnectivityLevel.InternetAccess:
                    case NetworkConnectivityLevel.ConstrainedInternetAccess:
                        this.hasNetwork = true;
                        break;
                }
            }
            networkStatusChangedCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChanged);
            if (!registeredNetworkStatusNotif)
            {
                NetworkInformation.NetworkStatusChanged += networkStatusChangedCallback;
                registeredNetworkStatusNotif = true;
            }

        }
Ejemplo n.º 2
0
        public HTransportManager(HTransport tranpsport)
        {
            this.Transport           = tranpsport;
            this.Transport.onData   += Transport_onData;
            this.Transport.onStatus += Transport_onStatus;
            ConnectionProfile internetConnectProfile = NetworkInformation.GetInternetConnectionProfile();

            if (internetConnectProfile == null)
            {
                this.hasNetwork = false;
            }
            else
            {
                switch (internetConnectProfile.GetNetworkConnectivityLevel())
                {
                case NetworkConnectivityLevel.None:
                    this.hasNetwork = false;
                    break;

                case NetworkConnectivityLevel.LocalAccess:
                case NetworkConnectivityLevel.InternetAccess:
                case NetworkConnectivityLevel.ConstrainedInternetAccess:
                    this.hasNetwork = true;
                    break;
                }
            }
            networkStatusChangedCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChanged);
            if (!registeredNetworkStatusNotif)
            {
                NetworkInformation.NetworkStatusChanged += networkStatusChangedCallback;
                registeredNetworkStatusNotif             = true;
            }
        }
        public HTransportManager(HTransport tranpsport)
        {
            this.Transport = tranpsport;
            this.Transport.onData += Transport_onData;
            this.Transport.onStatus += Transport_onStatus;

            if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None)
                this.hasNetwork = false;
            else
                this.hasNetwork = true;

            networkStatusChangedCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChanged);
            if (!registeredNetworkStatusNotif)
            {
                NetworkInformation.NetworkStatusChanged += networkStatusChangedCallback;
                registeredNetworkStatusNotif = true;
            }

        }
Ejemplo n.º 4
0
        /// <summary>
        /// Connect to server
        /// </summary>
        /// <param name="login">user jid i.e.(my_user@domain/resource)</param>
        /// <param name="password"></param>
        /// <param name="options"></param>
        /// <param name="context"></param>
        public void Connect(string login, string password, HOptions options, JObject context)
        {
            bool shouldConnect = false;
            bool connInprogress = false;
            bool disconnInprogress = false;
            this.options = new HOptions(options);

            if (this.connectionStatus == ConnectionStatus.DISCONNECTED)
            {
                shouldConnect = true;
                connectionStatus = ConnectionStatus.CONNECTING;
            }
            if (this.connectionStatus == ConnectionStatus.CONNECTING)
                connInprogress = true;
            if (this.connectionStatus == ConnectionStatus.DISCONNECTING)
                disconnInprogress = true;

            if (shouldConnect)
            {

                fillTransportOptions(login, password, options, context);

                if (options.GetTransport() == "socketio")
                {
                    if (transport == null || !(transport is HTransportSocketIO))
                    {
                        this.transport = new HTransportSocketIO();
                    }
                    if (transportManager == null)
                        this.transportManager = new HTransportManager(this.transport);
                    if (!isEventHandlerAdded)
                    {
                        this.transportManager.onStatus = transport_onStatus;
                        this.transportManager.onData = transport_onData;
                        isEventHandlerAdded = true;
                    }
                    notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.NO_ERROR, null);
                    this.transportManager.Connect(this.transportOptions);
                }
            }
            else
            {
                if (connInprogress)
                    notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.CONN_PROGRESS, null);
                else if (disconnInprogress)
                    notifyStatus(ConnectionStatus.DISCONNECTING, ConnectionErrors.ALREADY_CONNECTED, null);
                else
                    notifyStatus(ConnectionStatus.CONNECTED, ConnectionErrors.ALREADY_CONNECTED, null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Connect to server
        /// </summary>
        /// <param name="login">user jid i.e.(my_user@domain/resource)</param>
        /// <param name="password"></param>
        /// <param name="options"></param>
        /// <param name="context"></param>
        public void Connect(string login, string password, HOptions options, JObject context)
        {
            bool shouldConnect     = false;
            bool connInprogress    = false;
            bool disconnInprogress = false;

            this.options = new HOptions(options);

            if (this.connectionStatus == ConnectionStatus.DISCONNECTED)
            {
                shouldConnect    = true;
                connectionStatus = ConnectionStatus.CONNECTING;
            }
            if (this.connectionStatus == ConnectionStatus.CONNECTING)
            {
                connInprogress = true;
            }
            if (this.connectionStatus == ConnectionStatus.DISCONNECTING)
            {
                disconnInprogress = true;
            }

            if (shouldConnect)
            {
                fillTransportOptions(login, password, options, context);

                if (options.GetTransport() == "socketio")
                {
                    if (transport == null || !(transport is HTransportSocketIO))
                    {
                        this.transport = new HTransportSocketIO();
                    }
                    if (transportManager == null)
                    {
                        this.transportManager = new HTransportManager(this.transport);
                    }
                    if (!isEventHandlerAdded)
                    {
                        this.transportManager.onStatus = transport_onStatus;
                        this.transportManager.onData   = transport_onData;
                        isEventHandlerAdded            = true;
                    }
                    notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.NO_ERROR, null);
                    this.transportManager.Connect(this.transportOptions);
                }
            }
            else
            {
                if (connInprogress)
                {
                    notifyStatus(ConnectionStatus.CONNECTING, ConnectionErrors.CONN_PROGRESS, null);
                }
                else if (disconnInprogress)
                {
                    notifyStatus(ConnectionStatus.DISCONNECTING, ConnectionErrors.ALREADY_CONNECTED, null);
                }
                else
                {
                    notifyStatus(ConnectionStatus.CONNECTED, ConnectionErrors.ALREADY_CONNECTED, null);
                }
            }
        }