public void OnDiscoveryFailed(DiscoveryManager manager, ServiceCommandError error)
 {
     throw new NotImplementedException();
 }
 public void OnServiceDiscoveryFailed(IDiscoveryProvider provider, ServiceCommandError error)
 {
     Logger.Current.AddMessage(string.Format("Service discovery failed. {0}", error.GetPayload()));
 }
 public void OnConnectionFailed(ConnectableDevice device, ServiceCommandError error)
 {
     throw new NotImplementedException();
 }
 public void OnRegistrationFailed(ServiceCommandError error)
 {
     service.Disconnect();
     if (listener != null)
         listener.OnConnectionFailure(service, new Exception(error.GetCode().ToString()));
 }
 public void OnConnectionFailed(ConnectableDevice device, ServiceCommandError error)
 {
 }
        private void HandleConnectionLost(bool cleanDisconnect, Exception ex)
        {
            ServiceCommandError error = null;

            if (ex != null || !cleanDisconnect)
                error = new ServiceCommandError(0, ex);

            if (Listener != null)
                Listener.OnCloseWithError(error);

            foreach (var serviceCommand in Requests)
            {
                var request = serviceCommand.Value;
                if (request != null)
                    Util.PostError(request.ResponseListenerValue, new ServiceCommandError(0, "connection lost"));

            }

            Requests.Clear();
        }
 public void OnFailWithError(ServiceCommandError error)
 {
     if (listener != null)
         listener.OnConnectionFailure(service, new Exception(error.GetCode().ToString()));
 }
 public static void PostError(ResponseListener listener, ServiceCommandError error)
 {
     if (listener == null)
         return;
     listener.OnError(error);
 }
 public void DisconnectWithError(ServiceCommandError error)
 {
     State = State.Initial;
     
     if (Listener != null)
         Listener.OnCloseWithError(error);
 }
 public void OnRegistrationFailed(ServiceCommandError error)
 {
 }
            public void OnFailWithError(ServiceCommandError error)
            {
                webOsWebAppSession.Connected = false;
                webOsWebAppSession.AppToAppSubscription = null;

                if (webOsWebAppSession.MConnectionListener != null)
                {
                    if (error == null)
                        error = new ServiceCommandError(0, null);

                    webOsWebAppSession.MConnectionListener.OnError(error);
                }

                webOsWebAppSession.MConnectionListener = null;
            }
            public void OnCloseWithError(ServiceCommandError error)
            {
                webOsWebAppSession.Connected = false;
                webOsWebAppSession.AppToAppSubscription = null;

                if (webOsWebAppSession.MConnectionListener != null)
                {
                    if (error != null)
                        webOsWebAppSession.MConnectionListener.OnError(error);
                    else
                    {
                        if (webOsWebAppSession.WebAppSessionListener != null)
                            webOsWebAppSession.WebAppSessionListener.OnWebAppSessionDisconnect(webOsWebAppSession);
                    }
                }

                webOsWebAppSession.MConnectionListener = null;
            }
        private void Connect(bool joinOnly, ResponseListener connectionListener)
        {
            if (Socket != null && Socket.State == State.Connecting)
            {
                if (connectionListener != null)
                    connectionListener.OnError(new ServiceCommandError(0,
                        "You have a connection request pending,  please wait until it has finished"));
                return;
            }

            if (IsConnected())
            {
                if (connectionListener != null)
                    connectionListener.OnSuccess(null);
                return;
            }

            MConnectionListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var finalConnectionListener = new ResponseListener
                    (
                        loadEventArg2 =>
                        {
                            Connected = true;

                            if (connectionListener != null)
                                connectionListener.OnSuccess(loadEventArg2);
                        },
                        serviceCommandError =>
                        {
                            DisconnectFromWebApp();

                            if (connectionListener != null)
                                connectionListener.OnError(serviceCommandError);
                        }
                    );

                    Service.ConnectToWebApp(this, joinOnly, finalConnectionListener);
                },
                serviceCommandError =>
                {
                    if (Socket != null)
                        DisconnectFromWebApp();

                    if (connectionListener != null)
                    {
                        if (serviceCommandError == null)
                            serviceCommandError = new ServiceCommandError(0, "Unknown error connecting to web app");

                        connectionListener.OnError(serviceCommandError);
                    }
                }
            );

            if (Socket != null)
            {
                if (Socket.IsConnected())
                    MConnectionListener.OnSuccess(null);
                else
                    Socket.Connect();
            }
            else
            {
                //var uri = WebOstvServiceSocketClient.GetUri(Service);
                //Socket = new WebOstvServiceSocketClient(Service, uri);
                //Socket.Listener = mSocketListener;
                //Socket.Connect();

                var uri = WebOstvServiceSocketClient.GetUri(Service);
                if (WebOstvServiceSocketClient.SocketCache.ContainsKey(uri.ToString()))
                {
                    Socket = WebOstvServiceSocketClient.SocketCache[uri.ToString()];
                    if (mSocketListener != null)
                    {
                        Socket.Listener = mSocketListener;
                    }
                    if (Socket.IsConnected())
                        MConnectionListener.OnSuccess(null);
                    else
                    {
                        Socket.Connect();
                    }
                    //MConnectionListener.OnSuccess(null);
                }
                else
                {
                    Socket = new WebOstvServiceSocketClient(Service, uri)
                    {
                        Listener = mSocketListener
                    };
                    Socket.Connect();
                    WebOstvServiceSocketClient.SocketCache.Add(uri.ToString(), Socket);
                }
            }
        }
 public void OnError(ServiceCommandError obj)
 {
     if (onErrorFunc != null)
         onErrorFunc(obj);
 }