private static void ActivateInternal(Guid apiKey) { try { LegacyManager.CompleteMigration().RunSynchronously(); } catch (Exception) { } YandexMetrica.MigrateApiKeys(); LiteMetricaService liteMetricaService = Store.Get <LiteMetricaService>(); if (((IEnumerable <Guid>)Critical.GetApiKeys()).Contains <Guid>(apiKey)) { liteMetricaService.Wake(false, true); } else { Critical.AddApiKey(apiKey); liteMetricaService.Wake(true, true); Critical.Submit(); } lock (YandexMetrica.CacheLock) { liteMetricaService.Report(YandexMetrica.Cache.ToArray()); YandexMetrica.Cache.Clear(); YandexMetrica._liteMetricaService = liteMetricaService; } liteMetricaService.ForceSend = true; }
static YandexMetrica() { string current = YandexMetricaFolder.Current; if (current == null) { throw new Exception("You should specify valid 'YandexMetricaFolder.Current' before."); } Memory.ActiveBox = new Memory((IStorage) new KeyFileStorage(), Path.Combine(current, "Yandex.Metrica.{0}.json"), true, " "); Lifecycler lifecycler = Store.Get <Lifecycler>(); lifecycler.UnhandledException += (EventHandler)((sender, args) => { if (!Adapter.IsInternalException((object)args)) { return; } Adapter.TryHandleException((object)args); Memory.ActiveBox.Destroy <LiteMetricaService>((string)null); Memory.ActiveBox.Destroy <Yandex.Metrica.Models.Config>((string)null); Store.Container.Remove(typeof(LiteMetricaService)); Store.Container.Remove(typeof(Yandex.Metrica.Models.Config)); YandexMetrica._liteMetricaService = Store.Get <LiteMetricaService>(); }); if (!lifecycler.IsBackgroundTask) { return; } Memory.ActiveBox = new Memory((IStorage) new KeyFileStorage(), Path.Combine(current, "Yandex.Metrica.{0}.b.json"), true, " "); }
internal static void Reset() { string customStartupUrl = Yandex.Metrica.Models.Config.Global.CustomStartupUrl; Guid apiKey = Yandex.Metrica.Models.Config.Global.ApiKey; Memory.ActiveBox.Destroy <Yandex.Metrica.Models.Config>((string)null); Memory.ActiveBox.Destroy <Critical.CriticalConfig>((string)null); Memory.ActiveBox.Destroy <LiteMetricaService>((string)null); Critical.SetUuid((string)null); Store.Container.Remove(typeof(LiteMetricaService)); Store.Container.Remove(typeof(Yandex.Metrica.Models.Config)); Yandex.Metrica.Models.Config config = Store.Get <Yandex.Metrica.Models.Config>(); config.ApiKey = apiKey; config.CustomStartupUrl = customStartupUrl; config.Snapshot(); Yandex.Metrica.Models.Config.Global = config; YandexMetrica._liteMetricaService = (LiteMetricaService)null; }
private async void Postman() { LiteMetricaService liteMetricaService = this; int fails = 0; while (true) { await ServiceData.WaitExposeAsync(); try { liteMetricaService._tokenSource = new CancellationTokenSource(); lock (liteMetricaService.PauseLock) { if (!liteMetricaService.IsPaused) { liteMetricaService.ActiveSession.LastUpdateTimestamp = new ulong?(DateTime.UtcNow.ToUnixTime()); } } int num; if (!liteMetricaService.ForceSend && liteMetricaService.ReportedEventsCount < Config.Global.FlushThresholdEventsCounts && liteMetricaService.LastFlushTime.HasValue) { DateTime utcNow = DateTime.UtcNow; DateTime?lastFlushTime = liteMetricaService.LastFlushTime; TimeSpan?nullable = lastFlushTime.HasValue ? new TimeSpan?(utcNow - lastFlushTime.GetValueOrDefault()) : new TimeSpan?(); TimeSpan thresholdTimeout = Config.Global.FlushThresholdTimeout; num = nullable.HasValue ? (nullable.GetValueOrDefault() > thresholdTimeout ? 1 : 0) : 0; } else { num = 1; } if (num != 0) { bool?nullable1 = await liteMetricaService.Refresh(); bool?nullable2 = liteMetricaService.Flush(); if (nullable2.HasValue && nullable2.Value) { liteMetricaService.LastFlushTime = new DateTime?(DateTime.UtcNow); liteMetricaService.ReportedEventsCount = 0; liteMetricaService.ForceSend = false; fails = 0; } if (nullable2.HasValue) { liteMetricaService.Snapshot(); } if (nullable2.HasValue && !nullable2.Value) { ++fails; } if (fails > 6) { fails = 6; } if (fails > 0) { await liteMetricaService.Wait(TimeSpan.FromSeconds(Math.Pow(2.0, (double)fails))); } } await liteMetricaService.Wait(Config.Global.DispatchPeriod); } catch (Exception) { } } }