private static MobileAnalyticsManager GetOrCreateInstanceHelper(string appID, AWSCredentials credentials, RegionEndpoint regionEndpoint, MobileAnalyticsManagerConfig maConfig) { #if BCL ValidateParameters(); #endif MobileAnalyticsManager managerInstance = null; bool isNewInstance = false; lock (_lock) { if (_instanceDictionary.TryGetValue(appID, out managerInstance)) { return(managerInstance); } else { managerInstance = new MobileAnalyticsManager(appID, credentials, regionEndpoint, maConfig); _instanceDictionary[appID] = managerInstance; isNewInstance = true; } } if (isNewInstance) { managerInstance.Session.Start(); } _backgroundRunner.StartWork(); return(managerInstance); }
/// <summary> /// Gets the or create instance. /// </summary> /// <returns>The or create instance.</returns> /// <param name="clientContextConfig">Client context config.</param> /// <param name="regionEndpoint">Region endpoint.</param> /// <param name="credentials">Credentials.</param> private static MobileAnalyticsManager GetOrCreateInstanceHelper(string appId, AWSCredentials credential, RegionEndpoint regionEndpoint ) { MobileAnalyticsManager managerInstance = null; bool isNewInstance = false; lock (_lock) { if (_instanceDictionary.ContainsKey(appId)) { managerInstance = _instanceDictionary[appId]; } else { managerInstance = new MobileAnalyticsManager(appId, credential, regionEndpoint); _instanceDictionary[appId] = managerInstance; isNewInstance = true; } } if (isNewInstance) { managerInstance.Session.Start(); } BackgroundRunner.StartWork(); return(managerInstance); }
private static MobileAnalyticsManager GetOrCreateInstanceHelper(string appID, AWSCredentials credentials, RegionEndpoint regionEndpoint, MobileAnalyticsManagerConfig maConfig) { #if BCL ValidateParameters(); #endif MobileAnalyticsManager managerInstance = null; bool isNewInstance = false; lock (_lock) { if (_instanceDictionary.TryGetValue(appID, out managerInstance)) { return(managerInstance); } else { managerInstance = new MobileAnalyticsManager(appID, credentials, regionEndpoint, maConfig); _instanceDictionary[appID] = managerInstance; isNewInstance = true; } } if (isNewInstance) { managerInstance.Session.Start(); } #if UNITY if (UnityEngine.Application.platform == UnityEngine.RuntimePlatform.WebGLPlayer) { _coroutineRunner.StartWork(); } else { _backgroundRunner.StartWork(); } #else _backgroundRunner.StartWork(); #endif return(managerInstance); }
public void TestRecordEvent() { // Need to make sure that background runner does not attempt to deliver events during // test (and consequently delete them from local storage). Restart Background runner // and sleep until after it checks for events to send. BackgroundRunner.AbortBackgroundThread(); System.Reflection.FieldInfo fieldInfo = typeof(MobileAnalyticsManager).GetField("_backgroundRunner", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); BackgroundRunner backgroundRunner = fieldInfo.GetValue(null) as BackgroundRunner; backgroundRunner.StartWork(); Thread.Sleep(1000); string appID = Guid.NewGuid().ToString(); MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, TestRunner.Credentials, RegionEndpoint.USEast1); SQLiteEventStore eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig()); try { CustomEvent customEvent = new CustomEvent("TestRecordEvent"); customEvent.AddAttribute("LevelName", "Level5"); customEvent.AddAttribute("Successful", "True"); customEvent.AddMetric("Score", 12345); customEvent.AddMetric("TimeInLevel", 64); manager.RecordEvent(customEvent); MonetizationEvent monetizationEvent = new MonetizationEvent(); monetizationEvent.Quantity = 10.0; monetizationEvent.ItemPrice = 2.00; monetizationEvent.ProductId = "ProductId123"; monetizationEvent.ItemPriceFormatted = "$2.00"; monetizationEvent.Store = "Amazon"; monetizationEvent.TransactionId = "TransactionId123"; monetizationEvent.Currency = "USD"; manager.RecordEvent(monetizationEvent); } catch (Exception e) { Console.WriteLine("Catch exception: " + e.ToString()); Assert.Fail(); } // sleep a while to make sure event is stored Thread.Sleep(TimeSpan.FromSeconds(1)); // Event store should have one custom event, one monetization event and one session start event. Assert.AreEqual(3, eventStore.NumberOfEvents(appID)); eventStore.Dispose(); }
static MobileAnalyticsManager() { _backgroundRunner.StartWork(); }