public static async Task <HttpResponseMessage> PostAsync( Uri uri, Stream stream) { try { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("user-agent", ServiceData.UserAgent); StreamContent streamContent = new StreamContent(stream); streamContent.Headers.ContentEncoding.Add("gzip"); using (HttpResponseMessage response = await httpClient.PostAsync(uri, (HttpContent)streamContent, CancellationToken.None)) { if (response.IsSuccessStatusCode) { return(response); } if (await response.Content.ReadAsStringAsync() == "Incorrect uuid") { Critical.SetUuid((string)null); } return(response); } } catch (Exception) { return((HttpResponseMessage)null); } }
public static async Task CompleteMigration() { if (Memory.ActiveBox.Check <LegacyManager.MigrationData>((string)null)) { LegacyManager.Data = Memory.ActiveBox.Revive <LegacyManager.MigrationData>((string)null); } else { try { Config config = await new IsolatedStreamStorage <Config>((IStreamSerializer <Config>) new ConfigProtoSerializer()).ReadAsync("Yandex.Metrica.Config"); Guid guid = new Guid(config.ApiKey); if (!Yandex.Metrica.Models.Config.Global.KnownKeys.Contains(guid)) { Yandex.Metrica.Models.Config.Global.KnownKeys.Add(guid); } Critical.SetUuid(config.UUID); Memory.ActiveBox.Keep <Yandex.Metrica.Models.Config>(Yandex.Metrica.Models.Config.Global, (string)null); Yandex.Metrica.Models.Config.Global.CrashTracking = config.ReportCrashesEnabled; Yandex.Metrica.Models.Config.Global.LocationTracking = config.TrackLocationEnabled; Yandex.Metrica.Models.Config.Global.CustomAppVersion = new Version(config.CustomAppVersion); } catch (Exception) { } Memory memory = new Memory((IStorage) new KeyFileStorage(), "{0}", true, " "); bool flag = ((IEnumerable <string>)LegacyManager.LegacyKeys).Any <string>((Func <string, bool>)(k => memory.Check <object>(k))); LegacyManager.Data = new LegacyManager.MigrationData() { MigratedFromVersion2 = flag, IsCleaned = !flag }; Memory.ActiveBox.Keep <LegacyManager.MigrationData>(LegacyManager.Data, (string)null); } if (LegacyManager.Data.IsCleaned) { return; } LegacyManager.Data.IsCleaned = LegacyManager.Clean(); if (!LegacyManager.Data.IsCleaned) { return; } Memory.ActiveBox.Keep <LegacyManager.MigrationData>(LegacyManager.Data, (string)null); }
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; }
public static async Task <bool> RefreshStartupAsync() { StartupResponse startupAsync = await LiteClient.GetStartupAsync(); if (startupAsync == null) { return(Config.Global.ReportUrl != null); } if (startupAsync.DeviceId != null) { Critical.SetDeviceId(startupAsync.DeviceId); } if (startupAsync.Uuid != null) { Critical.SetUuid(startupAsync.Uuid); } Config.Global.ReportUrl = startupAsync.ReportUrl; return(true); }