/// <summary> /// Add an event to the store. /// </summary> /// <returns><c>true</c>, if event was put, <c>false</c> otherwise.</returns> public void PutEvent(string eventString, string appId) { bool proceedToInsert = false; long currentDatabaseSize = DatabaseSize; if (string.IsNullOrEmpty(appId)) { throw new ArgumentNullException("AppId"); } if (currentDatabaseSize >= _maConfig.MaxDBSize) { proceedToInsert = false; InvalidOperationException e = new InvalidOperationException(); _logger.Error(e, "The database size has exceeded the threshold limit. Unable to insert any new events"); } else if ((double)currentDatabaseSize / (double)_maConfig.MaxDBSize >= _maConfig.DBWarningThreshold) { proceedToInsert = true; _logger.InfoFormat("The database size is almost full"); } else { proceedToInsert = true; } //keep the lock as short as possible if (proceedToInsert) { lock (_lock) { try { if (!keepOnlyOneConnection || connection == null) { connection = new FileConnection("URI=file:" + this.DBfileFullPath); connection.Open(); } var eventRow = connection.Tables[TABLE_NAME].NewRow(); eventRow[EVENT_COLUMN_NAME] = eventString; eventRow[EVENT_ID_COLUMN_NAME] = Guid.NewGuid().ToString(); eventRow[MA_APP_ID_COLUMN_NAME] = appId; connection.Tables[TABLE_NAME].Rows.Add(eventRow); connection.Sql.AcceptChanges(); } finally { if (!keepOnlyOneConnection && connection != null) { connection.Save(); connection.Dispose(); } } } } }
/// <summary> /// Sends Mobile Analytics events to server on coroutine. /// </summary> private IEnumerator 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); } } } } catch (System.Exception e) { _logger.Error(e, "An exception occurred in Mobile Analytics Manager."); } yield return(new WaitForSeconds(BackgroundSubmissionWaitTime)); } }
public static void SafeExecute(Action action) { try { action(); } catch (Exception exception) { // Catch any unhandled exceptions from the user callback // and log it. _logger.Error(exception, "An unhandled exception was thrown from the callback method {0}.", action.Method.Name); } }