/// <summary> /// Get a user's backgrounds. /// </summary> /// <param name="onlyNew">Whether to return only new background metadatas or all.</param> /// <returns>If onlyNew is set to true, returns only background metadatas not found in the local cache. Otherwise, all retrieved.</returns> public static async Task <List <Background> > GetUserBackgrounds(bool onlyNew = true) { var url = SettingsManager.UserDefined.ServiceAddress + string.Format(SettingsManager.ApiEndpoints.UserBackgroundsEndpoint, SettingsManager.UserDefined.UserId); using (var client = new HttpClient()) { using (var response = await client.GetAsync(url)) { response.EnsureSuccessStatusCode(); var jsonResponse = await response.Content.ReadAsStringAsync(); var backgrounds = JsonArray.Parse(jsonResponse) .Select(o => DeserializeBackground(o.GetObject())) .ToList(); var addedBackgrounds = SettingsManager.Internal.AddToBackgroundCache(backgrounds); TelemetryManager.TrackEvent("Downloaded background metadata from server", new Dictionary <string, string>() { { "downloadedBackgrounds", backgrounds.Count().ToString() }, { "addedBackgrounds", addedBackgrounds.Count().ToString() } }); return(onlyNew ? addedBackgrounds : backgrounds); } } }
/// <summary> /// Change the wallpaper to the one specified in the provided metadata. /// </summary> /// <param name="background">The background metadata to use.</param> public static async Task ChangeWallpaper(Background background, bool manuallyTriggered = false) { TelemetryManager.TrackEvent("Updating wallpaper...", new Dictionary <string, string>() { { "backgroundId", background.Id }, { "manuallyTriggered", manuallyTriggered.ToString() } }); var backgroundFile = await FileManager.GetBackgroundFromLocalFolder(background); if (backgroundFile != null) { await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(backgroundFile); } else { TelemetryManager.TrackEvent("Background could not be found in file cache!", new Dictionary <string, string>() { { "backgroundId", background.Id } }); } SettingsManager.Internal.CurrentWallpaper = background; }
private void TrackTelemetryData(TelemetryType type) { switch (type) { case TelemetryType.Event: Dictionary <string, string> properties = new Dictionary <string, string> (); properties.Add("Xamarin Key", "Custom Property Value"); TelemetryManager.TrackEvent("My custom event", properties); break; case TelemetryType.Metric: TelemetryManager.TrackMetric("My custom metric", 2.2); break; case TelemetryType.Message: TelemetryManager.TrackTrace("My custom message"); break; case TelemetryType.PageView: TelemetryManager.TrackPageView("My custom page view", 100); break; case TelemetryType.Session: ApplicationInsights.RenewSessionWithId(new DateTime().Date.ToString()); break; default: break; } }
private void TrackTelemetryData(TelemetryType type) { switch (type) { case TelemetryType.Event: Dictionary <string, string> properties = new Dictionary <string, string> (); properties.Add("Xamarin Key", "Custom Property Value"); TelemetryManager.TrackEvent("My custom event", properties); break; case TelemetryType.Metric: TelemetryManager.TrackMetric("My custom metric", 2.2); break; case TelemetryType.Message: TelemetryManager.TrackTrace("My custom message"); break; case TelemetryType.PageView: TelemetryManager.TrackPageView("My custom page view"); break; case TelemetryType.Session: ApplicationInsights.RenewSessionWithId(new DateTime().Date.ToString()); break; case TelemetryType.HandledException: try { throw(new NullReferenceException()); }catch (Exception e) { // App shouldn't crash because of that } break; case TelemetryType.UnhandledException: int value = 1 / int.Parse("0"); break; case TelemetryType.UnmanagedSignal: #if __IOS__ DummyLibrary.TriggerSignalCrash(); #endif break; case TelemetryType.UnmanagedException: DummyLibrary.TriggerExceptionCrash(); break; default: break; } }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); //Initialize Telemetry TelemetryManager.InitializeBackgroundTelemetry(); TelemetryManager.TrackEvent("Starting Background Downloader task..."); await Downloader.Execute(); TelemetryManager.TrackEvent("Starting Background Changer task..."); await Changer.Execute(); TelemetryManager.TrackEvent("Background tasks finished!"); deferral.Complete(); }
/// <summary> /// Run a single iteration of the downloading cycle: /// - Contact the service to retrieve the latest background metadata /// - Add any new background metadata to the local cache /// - For any newly-added metadata, download the image and save it /// </summary> public static async Task Execute(bool onlyNew = true) { try { var userBackgrounds = await ServiceClient.GetUserBackgrounds(onlyNew); foreach (var background in userBackgrounds) { var stream = await ServiceClient.GetBackgroundImageStream(background.Id); await FileManager.SaveBackgroundToLocalFolder(background, stream); } SettingsManager.Internal.LastRetrievedDate = DateTime.Now; } catch { TelemetryManager.TrackEvent("Could not download metadata cache!"); } }