Ejemplo n.º 1
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="client"></param>
            public SocketDelegate(WebSocketsClientIos client)
            {
                if (client == null)
                {
                    throw new NullReferenceException("SocketDelegate's parent client reference cannot be null.");
                }

                _client = client;
            }
Ejemplo n.º 2
0
            public override void ReceivedMessage(WebSocket webSocket, NSObject message)
            {
                ExceptionUtility.Try(() =>
                {
                    this.ResetMissedPongs();
                    string msg = (message != null ? message.ToString() : String.Empty);
                    LogUtility.LogMessage(String.Format("{2}:Websocket Message Rcvd (from {0}: {1}", this._client.Url, WebSocketsClientIos.FormatJsonForLogging(msg), this._client._instanceId.ToString()));

                    var waitingForResponse = _client._waitingForResponse.ToList();

                    //deserialize object (or attempt to)
                    var response = ResponseFactory.ParseResponse(msg);

                    //call our callbacks
                    if (response != null && response.Header != null)
                    {
                        foreach (var item in waitingForResponse)
                        {
                            if (item.Value != null)
                            {
                                if ((response.Header.Channel != null && response.Header.Channel == item.Key) || response.IsGlobalResponse)
                                {
                                    _client.UnregisterWaitingForResponse(item.Key);

                                    item.Value(response);
                                }
                            }
                        }
                    }

                    //handle clients waiting for updates
                    var progressResponse = response as ProgressResponse;
                    if (progressResponse != null)
                    {
                        Action <ProgressResponse> callback;
                        if (_client._waitingForUpdates.TryGetValue(progressResponse.CommandId, out callback))
                        {
                            callback(progressResponse);
                            if (response.IsFinal)
                            {
                                _client.UnregisterFromProgressUpdates(progressResponse.CommandId);
                            }

                            if (progressResponse?.Body?.Devices != null)
                            {
                                DataCache.CacheDevicesResponse((response as ProgressResponse)?.Body?.Devices.Items);
                            }
                        }
                    }

                    //handle ad hoc device updates
                    var devicesResponse = response as DevicesResponse;
                    if (devicesResponse != null)
                    {
                        DataCache.CacheDevicesResponse(devicesResponse);
                    }

                    //handle ad hoc alerts updates
                    var alertsResponse = response as AlertsResponse;
                    if (alertsResponse != null)
                    {
                        DataCache.HandleAlertsResponse(alertsResponse);
                    }

                    //handle ad hoc device briefs updates
                    var deviceBriefsResponse = response as DeviceBriefsResponse;
                    if (deviceBriefsResponse != null)
                    {
                        DataCache.CacheDevicesResponse(deviceBriefsResponse?.Body?.Devices.Items);
                    }

                    //handle ad hoc reconnect responses
                    var errorResponse = response as ErrorResponse;
                    if (errorResponse != null)
                    {
                        if (errorResponse.IsReconnectResponse)
                        {
                            LogUtility.LogMessage("Received an ad hoc Reconnect response from server; will reconnect");
                            _client.FireReconnectEvent();
                        }
                    }
                });
            }
Ejemplo n.º 3
0
 public void DisposeEx()
 {
     _client = null;
 }