Пример #1
0
 public override void OnActivated(UIApplication application)
 {
     // Restart any tasks that were paused (or not yet started) while the application was inactive.
     // If the application was previously in the background, optionally refresh the user interface.
     LogUtility.LogMessage("OnActivated called, App is active.");
     ServiceContainer.InvalidateCache(); // invalidate cache after backgrounding app
     NotificationUtility.PostNotification(NotificationType.Activated);
 }
Пример #2
0
            /// <summary>
            /// Takes appropriate actions up on failed reconnect
            /// </summary>
            private static void OnFailure()
            {
                Stop();

                //if auth failure timeout, redirect to login screen
                if (IsAuthFailure)
                {
                    NotificationUtility.PostNotification(NotificationType.AuthFailure);
                }
            }
Пример #3
0
 /// <summary>
 /// Internally sets the instance connection state
 /// </summary>
 /// <param name="state">The state value to set</param>
 /// <param name="message">Optional message to display on banner</param>
 private static void SetState(ConnectionState state, string message = null)
 {
     state.Message = message;
     if (_state != state)
     {
         LogUtility.LogMessage(String.Format("Connection state set to {0}", state.ToString()));
         _state = state;
         NotificationUtility.PostNotification(NotificationType.ConnectionStateChanged);
     }
 }
Пример #4
0
 /// <summary>
 /// Sets the active alert count.
 /// </summary>
 /// <param name="count">The value to set</param>
 public static void SetActiveAlertsCount(int?count)
 {
     if (count.HasValue)
     {
         if (_activeAlertsCount != count.Value)
         {
             _activeAlertsCount = count.Value;
             NotificationUtility.PostNotification(NotificationType.AlertsCountChanged, null);
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Handles a failed websocket request
        /// </summary>
        /// <param name="client">The websocket client which sent the request</param>
        /// <param name="args">Arguments associated with failure</param>
        private static void HandleFailedRequest(IWebSocketsClient client, RequestFailureEventArgs args)
        {
            LogUtility.LogMessage(String.Format("Request Failure (reason: {0})", Enum.GetName(typeof(RequestFailureReason), args.FailureReason)));

            bool   tryReconnect = false;
            string message      = null;

            switch (args.FailureReason)
            {
            case RequestFailureReason.Auth:
                tryReconnect = false;
                message      = "authentication problem";
                NotificationUtility.PostNotification(NotificationType.AuthFailure);
                break;

            case RequestFailureReason.Timeout:
                tryReconnect = ReconnectIsAllowed();
                message      = "timeout";
                break;

            case RequestFailureReason.ServerDown:
                tryReconnect = ReconnectIsAllowed();
                message      = "server down";
                break;

            case RequestFailureReason.Network:
                tryReconnect = ReconnectIsAllowed();
                message      = "network issue";
                break;

            case RequestFailureReason.ServerRequestedReconnect:
                tryReconnect = ReconnectIsAllowed();
                message      = "server requested reconnect";
                break;

            case RequestFailureReason.Error:
                break;
            }

            if (tryReconnect)
            {
                SetState(ConnectionState.Disconnected, message);
                ReconnectProcess.Begin(args.ForegroundAction, args.OnResume, args.Request, args.FailureReason);
            }
        }
Пример #6
0
        /// <summary>
        /// Does the work of sending a call to the server, and waiting for the response.
        /// </summary>
        /// <param name="jsonRequest">The request to send</param>
        /// <returns>A Task result with the response</returns>
        private Task <TResponse> Send <TResponse>(IApiRequest jsonRequest, string channel, bool silentMode = false) where TResponse : IApiResponse, new()
        {
            TResponse output = default(TResponse);

            return(Task.Run(() =>
            {
                ExceptionUtility.Try(() =>
                {
                    string jsonRequestString = JsonUtility.Serialize(jsonRequest);
                    string jsonRequestStringForLogging = jsonRequestString.Replace(User.Current.Password, "********");
                    LogUtility.LogMessage(String.Format("{2}: Sending Request to {0}: {1}", this.Url, FormatJsonForLogging(jsonRequestStringForLogging), this._instanceId.ToString()));
                    var waitHandle = new AutoResetEvent(false);
                    bool gotResponse = false;

                    Action <IApiResponse> receivedResponse = (r) =>
                    {
                        gotResponse = true;

                        if (r is Lib.Domain.Responses.ConnectionResponse && ((ConnectionResponse)r).IsSuccessful)
                        {
                            NotificationUtility.PostNotification(NotificationType.Reconnected);
                        }

                        if (r is Lib.Domain.Responses.ErrorResponse)
                        {
                            output = ResponseFactory.ParseResponse <TResponse>(r.RawResponse);
                        }
                        else
                        {
                            try
                            {
                                output = (TResponse)r;
                            }
                            catch (System.InvalidCastException ice)
                            {
                                LogUtility.LogException(ice, String.Format("The server returned a type of response that was not expected. The type of response expected was {0}", (typeof(TResponse)).Name), LogSeverity.Warn);
                                output = default(TResponse);
                            }
                        }

                        if (r.IsAuthFailure)
                        {
                            output = ResponseFactory.FabricateLoginFailureResponse <TResponse>(jsonRequest);
                        }

                        gotResponse = true;
                        waitHandle.Set();
                    };

                    RegisterWaitingForResponse(channel, receivedResponse);

                    if (_client != null)
                    {
                        _client.Send(new NSString(jsonRequestString));

                        waitHandle.WaitOne(DefaultSendTimeoutMs);
                        UnregisterWaitingForResponse(channel);
                    }

                    //here we will fabricate an error response for case of timeout
                    if (output == null && !gotResponse)
                    {
                        output = ResponseFactory.FabricateRequestTimeoutResponse <TResponse>(jsonRequest);
                        this.FireRequestFailureEvent(jsonRequest, null, RequestFailureReason.Timeout, foregroundAction: (!silentMode));
                    }
                });

                return output;
            }));
        }
Пример #7
0
 /// <summary>
 /// Hide the reconnecting banner
 /// </summary>
 private static void HideReconBanner()
 {
     _showingReconBar = false;
     NotificationUtility.PostNotification(NotificationType.HideReconnecting);
 }
Пример #8
0
 /// <summary>
 /// Display the reconnecting banner
 /// </summary>
 private static void ShowReconBanner()
 {
     _showingReconBar = true;
     NotificationUtility.PostNotification(NotificationType.ShowReconnecting);
 }