Пример #1
0
 /// <summary>
 /// Wipes all user data cached locally, including dataset metadata, and all records,
 /// and optionally identity id and session credentials. Any data that hasn't been
 /// synced will be lost. This method is usually used when customer logs out.
 /// <param name="wipeCredentialsAndID">Wipe Credentials and IdentityId.</param>
 /// </summary>
 public void WipeData(bool wipeCredentialsAndID)
 {
     Local.WipeData();
     _logger.InfoFormat("All data has been wiped");
     if (wipeCredentialsAndID)
     {
         CognitoCredentials.Clear();
         _logger.InfoFormat("All datasets and records have been wiped");
     }
     else
     {
         _logger.InfoFormat("All data has been wiped");
     }
 }
Пример #2
0
        /// <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();
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <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));
            }
        }