Exemple #1
0
        private void EnqueueEventsHelper(Amazon.MobileAnalytics.Model.Event eventObject)
        {
            string eventString = null;

            try
            {
                eventString = JsonMapper.ToJson(eventObject);
            }
            catch (Exception e)
            {
                _logger.Error(e, "An exception occurred when converting low level client event to json string.");
                List <Amazon.MobileAnalytics.Model.Event> eventList = new List <Amazon.MobileAnalytics.Model.Event>();
                eventList.Add(eventObject);
                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when converting low level client event to json string.", e, eventList);
                _maManager.OnRaiseErrorEvent(eventArgs);
            }

            if (null != eventString)
            {
                try
                {
                    _eventStore.PutEvent(eventString, _appID);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Event {0} was not stored.", eventObject.EventType);
                    MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when storing event into event store.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                    _maManager.OnRaiseErrorEvent(eventArgs);
                }
                _logger.DebugFormat("Event {0} is queued for delivery", eventObject.EventType);
            }
        }
Exemple #2
0
        private void DoWork()
        {
            while (!ShouldStop)
            {
                try
                {
                    _logger.InfoFormat("Mobile Analytics Manager is trying to deliver events in background thread.");

                    IDictionary <string, MobileAnalyticsManager> instanceDictionary = MobileAnalyticsManager.CopyOfInstanceDictionary;
                    foreach (string appId in instanceDictionary.Keys)
                    {
                        MobileAnalyticsManager manager = null;
                        try
                        {
                            manager = MobileAnalyticsManager.GetInstance(appId);
                            manager.BackgroundDeliveryClient.AttemptDelivery();
                        }
                        catch (System.Exception e)
                        {
                            _logger.Error(e, "An exception occurred in Mobile Analytics Delivery Client.");
                            if (null != manager)
                            {
                                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when deliverying events to Amazon Mobile Analytics.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                                manager.OnRaiseErrorEvent(eventArgs);
                            }
                        }
                    }
                    Thread.Sleep(BackgroundSubmissionWaitTime * 1000);
                }
                catch (System.Exception e)
                {
                    _logger.Error(e, "An exception occurred in Mobile Analytics Manager.");
                }
            }
        }
        private void errorHandler(object sender, MobileAnalyticsErrorEventArgs args)
        {
            Console.WriteLine(args);
            bool catchExpectedError = false;

            lock (_lock)
            {
                if (args.ClassName != null && args.ErrorMessage != null && args.Exception is AmazonServiceException && args.UndeliveredEvents != null)
                {
                    if (args.UndeliveredEvents.Count == 0)
                    {
                        catchExpectedError = true;
                    }
                    else
                    {
                        catchExpectedError = false;
                        Console.WriteLine("The caught low level client events are : ");
                        foreach (Amazon.MobileAnalytics.Model.Event eventObject in args.UndeliveredEvents)
                        {
                            Console.WriteLine("Event type is {0}; Event session ID is {1}.", eventObject.EventType, eventObject.Session.Id);
                        }
                    }
                }
                else
                {
                    catchExpectedError = false;
                }
                resultList.Add(catchExpectedError);
            }
        }
        private void DoWork()
        {
            while (true)
            {
                try
                {
                    _logger.InfoFormat("Mobile Analytics Manager is trying to deliver events in background thread.");

                    IDictionary<string, MobileAnalyticsManager> instanceDictionary = MobileAnalyticsManager.CopyOfInstanceDictionary;
                    foreach (string appId in instanceDictionary.Keys)
                    {
                        MobileAnalyticsManager manager = null;
                        try
                        {
                            manager = MobileAnalyticsManager.GetInstance(appId);
                            manager.BackgroundDeliveryClient.AttemptDelivery();
                        }
                        catch (System.Exception e)
                        {
                            _logger.Error(e, "An exception occurred in Mobile Analytics Delivery Client.");
                            if (null != manager)
                            {
                                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when deliverying events to Amazon Mobile Analytics.", e, new List<Amazon.MobileAnalytics.Model.Event>());
                                manager.OnRaiseErrorEvent(eventArgs);
                            }
                        }
                    }
                    Thread.Sleep(BackgroundSubmissionWaitTime * 1000);
                }
                catch (System.Exception e)
                {
                    _logger.Error(e, "An exception occurred in Mobile Analytics Manager.");
                }
            }
        }
        /// <summary>
        /// Sends Mobile Analytics events to server on background thread.
        /// </summary>
        private void DoWork()
        {
            while (!_shouldStop)
            {
                try
                {
                    _logger.InfoFormat("Mobile Analytics Manager is trying to deliver events in background thread.");

                    IDictionary <string, MobileAnalyticsManager> instanceDictionary = MobileAnalyticsManager.CopyOfInstanceDictionary;
                    foreach (string appId in instanceDictionary.Keys)
                    {
                        MobileAnalyticsManager manager = null;
                        try
                        {
                            manager = MobileAnalyticsManager.GetInstance(appId);
                            manager.BackgroundDeliveryClient.AttemptDelivery();
                        }
                        catch (System.Exception e)
                        {
                            _logger.Error(e, "An exception occurred in Mobile Analytics Delivery Client : {0}", e.ToString());

                            if (null != manager)
                            {
                                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when deliverying events to Amazon Mobile Analytics.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                                manager.OnRaiseErrorEvent(eventArgs);
                            }
                        }
                    }
                    Thread.Sleep(BackgroundSubmissionWaitTime * 1000);
                }
                catch (ThreadAbortException tae)
                {
                    _logger.DebugFormat("Mobile Analytics Manager thread aborted");
                }
                catch (System.Exception e)
                {
                    _logger.Error(e, "An exception occurred in Mobile Analytics Manager.");
                }

                UnityRequestQueue.Instance.ExecuteOnMainThread(() =>
                {
                    if (Application.isEditor && !Application.isPlaying)
                    {
                        AbortBackgroundThread();
                    }
                });
            }
        }
        private async Task DoWorkAsync(int millisecondsDelay)
        {
            while (!ShouldStop)
            {
                await Task.Delay(millisecondsDelay).ConfigureAwait(false);

                if (ShouldStop)
                {
                    break;
                }

                try
                {
                    _logger.InfoFormat("Mobile Analytics Manager is trying to deliver events in background thread.");

                    IDictionary <string, MobileAnalyticsManager> instanceDictionary = MobileAnalyticsManager.CopyOfInstanceDictionary;
                    foreach (string appId in instanceDictionary.Keys)
                    {
                        MobileAnalyticsManager manager = null;
                        try
                        {
                            manager = MobileAnalyticsManager.GetInstance(appId);
                            await manager.BackgroundDeliveryClient.AttemptDeliveryAsync().ConfigureAwait(false);
                        }
                        catch (System.Exception e)
                        {
                            _logger.Error(e, "An exception occurred in Mobile Analytics Delivery Client : {0}", e.ToString());

                            if (null != manager)
                            {
                                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when deliverying events to Amazon Mobile Analytics.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                                manager.OnRaiseErrorEvent(eventArgs);
                            }
                        }
                    }
                }
                catch (System.Exception e)
                {
                    _logger.Error(e, "An exception occurred in Mobile Analytics Manager : {0}", e.ToString());
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Enqueues the events for delivery. The event is stored in an instance of <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.IEventStore"/>.
        /// </summary>
        /// <param name="eventObject">Event object.<see cref="Amazon.MobileAnalytics.Model.Event"/></param>
        public void EnqueueEventsForDelivery(Amazon.MobileAnalytics.Model.Event eventObject)
        {
#if BCL35
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
            {
#elif PCL || BCL45
            Task.Run(() =>
            {
#endif
                string eventString = null;
                try
                {
                    eventString = JsonMapper.ToJson(eventObject);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "An exception occurred when converting low level client event to json string.");
                    List <Amazon.MobileAnalytics.Model.Event> eventList = new List <Amazon.MobileAnalytics.Model.Event>();
                    eventList.Add(eventObject);
                    MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when converting low level client event to json string.", e, eventList);
                    _maManager.OnRaiseErrorEvent(eventArgs);
                }

                if (null != eventString)
                {
                    try
                    {
                        _eventStore.PutEvent(eventString, _appID);
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, "Event {0} was not stored.", eventObject.EventType);
                        MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when storing event into event store.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                        _maManager.OnRaiseErrorEvent(eventArgs);
                    }
                    _logger.DebugFormat("Event {0} is queued for delivery", eventObject.EventType);
                }
#if BCL35
            }));
#elif PCL || BCL45
            });
        private async Task DoWorkAsync(int millisecondsDelay)
        {
            while (!_shouldStop)
            {
                await Task.Delay(millisecondsDelay).ConfigureAwait(false);

                if (_shouldStop) break;
                
                try
                {
                    _logger.InfoFormat("Mobile Analytics Manager is trying to deliver events in background thread.");

                    IDictionary<string, MobileAnalyticsManager> instanceDictionary = MobileAnalyticsManager.CopyOfInstanceDictionary;
                    foreach (string appId in instanceDictionary.Keys)
                    {
                        MobileAnalyticsManager manager = null;
                        try
                        {
                            manager = MobileAnalyticsManager.GetInstance(appId);
                            await manager.BackgroundDeliveryClient.AttemptDeliveryAsync().ConfigureAwait(false);
                        }
                        catch (System.Exception e)
                        {
                            _logger.Error(e, "An exception occurred in Mobile Analytics Delivery Client : {0}", e.ToString());

                            if (null != manager)
                            {
                                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when deliverying events to Amazon Mobile Analytics.", e, new List<Amazon.MobileAnalytics.Model.Event>());
                                manager.OnRaiseErrorEvent(eventArgs);
                            }
                        }
                    }
                }
                catch (System.Exception e)
                {
                    _logger.Error(e, "An exception occurred in Mobile Analytics Manager : {0}", e.ToString());
                }
            }
        }
Exemple #9
0
        private async Task SubmitEvents(List <string> rowIds, List <Amazon.MobileAnalytics.Model.Event> eventList)
#endif
        {
            PutEventsRequest putRequest = new PutEventsRequest();

            putRequest.Events        = eventList;
            putRequest.ClientContext = Convert.ToBase64String(
                System.Text.Encoding.UTF8.GetBytes(_clientContext.ToJsonString()));
            putRequest.ClientContextEncoding = "base64";
            _logger.DebugFormat("Client Context is : {0}", _clientContext.ToJsonString());

            PutEventsResponse resp = null;

            try
            {
                resp = await _mobileAnalyticsLowLevelClient.PutEventsAsync(putRequest).ConfigureAwait(false);
            }
            catch (AmazonMobileAnalyticsException e)
            {
                _logger.Error(e, "An AmazonMobileAnalyticsException occurred while sending Amazon Mobile Analytics request: error code is {0} ; error type is {1} ; request id is {2} ; status code is {3} ; error message is {4}", e.ErrorCode, e.ErrorType, e.RequestId, e.StatusCode, e.Message);
                // Delete events in any of the three error codes.
                if (e.StatusCode == HttpStatusCode.BadRequest &&
                    (e.ErrorCode.Equals("ValidationException", StringComparison.CurrentCultureIgnoreCase) ||
                     e.ErrorCode.Equals("SerializationException", StringComparison.CurrentCultureIgnoreCase) ||
                     e.ErrorCode.Equals("BadRequestException", StringComparison.CurrentCultureIgnoreCase)))
                {
                    MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "Amazon Mobile Analytics Service returned an error.", e, eventList);
                    _maManager.OnRaiseErrorEvent(eventArgs);

                    _logger.InfoFormat("The error code is not retriable. Delete {0} events from local storage.", rowIds.Count);
                    _eventStore.DeleteEvent(rowIds);
                }
                else
                {
                    MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "Amazon Mobile Analytics Service returned an error.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                    _maManager.OnRaiseErrorEvent(eventArgs);
                }
            }
            catch (AmazonServiceException e)
            {
                _logger.Error(e, "An AmazonServiceException occurred while sending Amazon Mobile Analytics request:  error code is {0} ; error type is {1} ; request id is {2} ; status code is {3} ; error message is {4} ", e.ErrorCode, e.ErrorType, e.RequestId, e.StatusCode, e.Message);
                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "Amazon Web Service returned an error.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                _maManager.OnRaiseErrorEvent(eventArgs);
            }
            catch (Exception e)
            {
                _logger.Error(e, "An exception occurred while sending Amazon Mobile Analytics request.");
                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when sending request to Amazon Mobile Analytics.", e, new List <Amazon.MobileAnalytics.Model.Event>());
                _maManager.OnRaiseErrorEvent(eventArgs);
            }
            finally
            {
                if (resp != null && resp.HttpStatusCode == HttpStatusCode.Accepted)
                {
                    _logger.InfoFormat("Mobile Analytics client successfully delivered {0} events to service. Delete those events from local storage.", rowIds.Count);
                    _eventStore.DeleteEvent(rowIds);
                }
                lock (_deliveryLock)
                {
                    _deliveryInProgress = false;
                }
            }
        }
        /// <summary>
        /// Sends Mobile Analytics events to server on background thread.
        /// </summary>
        private void DoWork()
        {
            while (!_shouldStop)
            {
                try
                {
                    _logger.InfoFormat("Mobile Analytics Manager is trying to deliver events in background thread.");

                    IDictionary<string, MobileAnalyticsManager> instanceDictionary = MobileAnalyticsManager.CopyOfInstanceDictionary;
                    foreach (string appId in instanceDictionary.Keys)
                    {
                        MobileAnalyticsManager manager = null;
                        try
                        {
                            manager = MobileAnalyticsManager.GetInstance(appId);
                            manager.BackgroundDeliveryClient.AttemptDelivery();
                        }
                        catch (System.Exception e)
                        {
                            _logger.Error(e, "An exception occurred in Mobile Analytics Delivery Client : {0}", e.ToString());

                            if (null != manager)
                            {
                                MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when deliverying events to Amazon Mobile Analytics.", e, new List<Amazon.MobileAnalytics.Model.Event>());
                                manager.OnRaiseErrorEvent(eventArgs);
                            }
                        }
                    }
                    Thread.Sleep(BackgroundSubmissionWaitTime * 1000);
                }
                catch (System.Exception e)
                {
                    _logger.Error(e, "An exception occurred in Mobile Analytics Manager.");
                }

                UnityRequestQueue.Instance.ExecuteOnMainThread(() =>
                {
                    if (Application.isEditor && !Application.isPlaying)
                    {
                        AbortBackgroundThread();
                    }
                });

            }
        }