async Task LoadToCollection(IEnumerable <AvatarItem> avatars) { await AvatarsSemaphore.WaitAsync().ConfigureAwait(false); using (Avatars.UpdatesBlock()) { Avatars.Clear(); Avatars.AddRange(avatars); TryAddCustomAvatar(); } AvatarsSemaphore.Release(); }
public async Task ExecuteSaveProfileCommand() { if (IsBusy) { return; } LoadingMessage = "Saving Profile..."; using (BusyContext()) { using (App.Logger.TrackTimeContext("SaveProfile")) { try { if (string.IsNullOrWhiteSpace(nickName)) { RaiseNotification("Please fill in your nick name."); return; } if (!await RefreshToken()) { return; } var userManager = new UserManager(Settings.AccessToken); if (Settings.NickName != nickName) { var success = await userManager.ChangeNickname(nickName); if (!success) { RaiseNotification("Unable to save profile, please try again."); return; } } Settings.NickName = nickName; await AvatarsSemaphore.WaitAsync(); var selectedAvatar = Avatars.FirstOrDefault(a => a.Location == avatar); AvatarsSemaphore.Release(); if (selectedAvatar != null && Settings.Avatar != avatar) { var ava = await userManager.SetAvatarFromList(selectedAvatar.AvatarId); if (ava == null) { RaiseNotification("Unable to save profile, please try again."); return; } } Settings.Avatar = avatar; RaiseNotification("Profile Saved!"); App.Logger.Track("SaveProfile", new Dictionary <string, string> { { "nickname", Settings.NickName }, { "avatar", Settings.Avatar } }); } catch (Exception ex) { App.Logger.Report(ex); RaiseError("Avatar upload failed. Please try again."); } } } }