public async Task <DestinyPlayerData> GetPlayerDataAsync(DestinyPlayer player) { var bungie = new BungieService(Shared.SharedData.BungieApiKey); int platform = player.MembershipType; var accountId = player.MembershipId; var destinyProfile = await bungie.GetDestinyProfile(platform, accountId); int mode = 5; await bungie.DownloadDestinyManifest(); var nameplates = new List <CharacterNameplateViewModel>(); var activityHistoryLists = new List <List <PgcrCardViewModel> >(); var characterIds = destinyProfile.Data.CharacterIds; for (int i = 0; i < characterIds.Count; i++) { var characterId = destinyProfile.Data.CharacterIds[i]; var history = await bungie.GetActivityHistory(platform, accountId, characterId, mode); var character = await bungie.GetDestinyCharacter(platform, accountId, characterId); var nameplate = new CharacterNameplateViewModel { ElementVisibility = Visibility.Visible, ClassName = (await bungie.GetDestinyClassDefinitionAsync(character.Data.ClassHash)).DisplayProperties.Name, Race = (await bungie.GetDestinyRaceDefinitionAsync(character.Data.RaceHash)).DisplayProperties.Name, Gender = (await bungie.GetDestinyGenderDefinitionAsync(character.Data.GenderHash)).DisplayProperties.Name, Level = character.Data.BaseCharacterLevel, Power = character.Data.Light }; var emblemBrush = new ImageBrush(); emblemBrush.ImageSource = await bungie.GetDestinyImage(character.Data.EmblemBackgroundPath); nameplate.Emblem = emblemBrush; var historyList = new List <PgcrCardViewModel>(); foreach (var pgcr in history) { historyList.Add(new PgcrCardViewModel { Pgcr = pgcr, CharacterId = characterId }); } nameplates.Add(nameplate); activityHistoryLists.Add(historyList); } return(new DestinyPlayerData { CharacterNameplates = nameplates, ActivityHistoryLists = activityHistoryLists, CharacterIDs = characterIds, MembershipID = player.MembershipId, MembershipType = player.MembershipType }); }
public async void SearchAsync() { SearchResults.Clear(); if (!string.IsNullOrEmpty(Username)) { var bungie = new BungieService(Shared.SharedData.BungieApiKey); var destinyPlayers = await bungie.GetDestinyPlayers(-1, Username); foreach (var player in destinyPlayers) { SearchResults.Add(new PlayerSearchResultViewModel(player)); } } }
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; } }
private async void LayoutRoot_Loaded(object sender, RoutedEventArgs e) { var bungie = new BungieService(Shared.SharedData.BungieApiKey); var adaptiveCardRenderer = new AdaptiveCardRenderer { HostConfig = new AdaptiveHostConfig { FontFamily = "Segoe UI", FontSizes = new AdaptiveFontSizesConfig { Small = 12, Default = 14, Large = 20, ExtraLarge = 24 }, FontWeights = new AdaptiveFontWeightsConfig { Lighter = 200, Default = 400, Bolder = 700 }, ContainerStyles = new AdaptiveContainerStylesDefinition { Default = new AdaptiveContainerStyleDefinition { BackgroundColor = Color.FromArgb(255, 83, 84, 84), ForegroundColors = new AdaptiveColorsConfig { Default = new AdaptiveColorConfig { Default = Color.FromArgb(255, 255, 255, 255), Subtle = Color.FromArgb(255, 156, 158, 159) }, Attention = new AdaptiveColorConfig { Default = Color.FromArgb(255, 255, 0, 0), Subtle = Color.FromArgb(221, 255, 0, 0) }, Good = new AdaptiveColorConfig { Default = Color.FromArgb(255, 0, 255, 0), Subtle = Color.FromArgb(221, 0, 255, 0) } } } }, ImageSizes = new AdaptiveImageSizesConfig { Small = 40, Medium = 80, Large = 120 }, ImageSet = new AdaptiveImageSetConfig { ImageSize = ImageSize.Medium, MaxImageHeight = 100 } } }; 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 renderedCard = adaptiveCardRenderer.RenderAdaptiveCardFromJsonString(activity.Activity.VisualElements.Content.ToJson()); if (renderedCard.FrameworkElement != null) { Grid uiCard = renderedCard.FrameworkElement as Grid; uiCard.Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)); var background = uiCard.Children.OfType <Image>().FirstOrDefault(); if (background != null) { background.Opacity = 0.5; } uiCard.Width = 316; uiCard.Height = 174; uiCard.Margin = new Thickness(0, 0, 0, 24); LayoutRoot.Child = uiCard; } }
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(); }