private async void btnSyncActivities_Click(object sender, RoutedEventArgs e) { //tbStatus.Text = "In progress..."; try { var bungie = new BungieService(SharedData.BungieApiKey); int platform = 1; string accountName = "BlackDragon1999"; var destinyPlayer = (await bungie.GetDestinyPlayers(platform, accountName)).First(); var accountId = destinyPlayer.MembershipId; var destinyProfile = await bungie.GetDestinyProfile(platform, accountId); int mode = 5; await bungie.DownloadDestinyManifest(); foreach (var characterId in destinyProfile.Data.CharacterIds) { var history = await bungie.GetActivityHistory(platform, accountId, characterId, mode); await Task.WhenAll(from pgcr in history select Task.Run(async() => { var getActivityDefinition = bungie.GetActivityDefinitionAsync(pgcr.ActivityDetails.ReferenceId); var getModeDefinition = bungie.GetActivityModeDefinitionAsync(pgcr.ActivityDetails.Mode); var activity = new DestinyUserActivity(pgcr, await getActivityDefinition, await getModeDefinition, characterId); var msGraph = new MsGraphService(SharedData.MsGraphClientId); await msGraph.CreateOrReplaceActivityAsync(activity.Activity); })); } //tbStatus.Text = "Done"; } catch (Exception ex) { //tbStatus.Text = $"Failed: {ex.ToString()}"; } }
public async Task SyncToTimeline() { if (PlayerData != null) { IsSyncIdle = false; var bungie = new BungieService(Shared.SharedData.BungieApiKey); for (int i = 0; i < PlayerData.ActivityHistoryLists.Count; i++) { await Task.WhenAll(from pgcr in PlayerData.ActivityHistoryLists[i] select Task.Run(async() => { var getActivityDefinition = bungie.GetActivityDefinitionAsync(pgcr.Pgcr.ActivityDetails.ReferenceId); var getModeDefinition = bungie.GetActivityModeDefinitionAsync(pgcr.Pgcr.ActivityDetails.Mode); var activity = new DestinyUserActivity(pgcr.Pgcr, await getActivityDefinition, await getModeDefinition, PlayerData.CharacterIDs[i]); var msGraph = new MsGraphService(Shared.SharedData.MsGraphClientId); await msGraph.CreateOrReplaceActivityAsync(activity.Activity); })); } IsSyncIdle = true; } }
public UserController(MsGraphService msGraphService, IMapper mapper) { _msGraphService = msGraphService; _mapper = mapper; }
public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); try { var connectionCost = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost(); if (NetworkInterface.GetIsNetworkAvailable() && (connectionCost.NetworkCostType == NetworkCostType.Unknown || connectionCost.NetworkCostType == NetworkCostType.Unrestricted)) { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; var player = JsonConvert.DeserializeObject <DestinyPlayerInformation>((string)localSettings.Values["player"]); int platform = player.MembershipType; string accountId = player.MembershipID; int mode = 5; var bungie = new BungieService(SharedData.BungieApiKey); await bungie.DownloadDestinyManifest(); foreach (var characterId in player.CharacterIDs) { var history = await bungie.GetActivityHistory(platform, accountId, characterId, mode); await Task.WhenAll(from pgcr in history select Task.Run(async() => { var getActivityDefinition = bungie.GetActivityDefinitionAsync(pgcr.ActivityDetails.ReferenceId); var getModeDefinition = bungie.GetActivityModeDefinitionAsync(pgcr.ActivityDetails.Mode); var activity = new DestinyUserActivity(pgcr, await getActivityDefinition, await getModeDefinition, characterId); var msGraph = new MsGraphService(SharedData.MsGraphClientId); await msGraph.CreateOrReplaceActivityAsync(activity.Activity); })); } } } catch (Exception ex) { ToastContent toastContent = new ToastContent() { Launch = "refresh-activity", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText { Text = "An error occured while refreshing Destiny 2 activity history" } } } } }; var toast = new ToastNotification(toastContent.GetXml()); toast.ExpirationTime = DateTime.Now.AddDays(2); ToastNotificationManager.CreateToastNotifier().Show(toast); } deferral.Complete(); }