public async Task DownloadImageAsync(MessageGroupItem item) { IsLoading = true; var saved = true; try { var imageBytes = await _messageManager.GetMessageContent(SelectedMessageGroup.MessageGroupId, item.Message.SentMessageId, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await FileAccessCommands.SaveStreamToCameraRoll(imageBytes, item.Message.SentMessageId + ".png"); } catch (Exception ex) { //Insights.Report(ex); saved = false; } var loader = new ResourceLoader(); if (!saved) { await ResultChecker.SendMessageDialogAsync(loader.GetString("ErrorSaveImage/Text"), false); } else { await ResultChecker.SendMessageDialogAsync(loader.GetString("ImageSaved/Text"), true); } IsLoading = false; }
public async Task SendFriendLinkViaSms() { IsLoading = true; var result = await ChatMessageManager.GetTransportsAsync(); if (!result.Any()) { IsLoading = false; await ResultChecker.SendMessageDialogAsync(_loader.GetString("NoSMS/Text"), false); return; } var link = await CreateFriendLink(); if (!string.IsNullOrEmpty(link)) { var chat = new ChatMessage { Subject = _loader.GetString("FriendRequestBody/Text"), Body = string.Format("{0} {1}", _loader.GetString("FriendRequestBody/Text"), link) }; await ChatMessageManager.ShowComposeSmsMessageAsync(chat); } IsLoading = false; }
public async Task SendMessage() { string error; try { if (AttachedImage != null && IsImageAttached) { await SendMessageWithMedia(); } else { if (!string.IsNullOrEmpty(Message)) { await SendMessageWithoutMedia(); } } Message = string.Empty; return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
private async void AttachImage(object sender, RoutedEventArgs e) { string error; try { var openPicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary }; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".gif"); var file = await openPicker.PickSingleFileAsync(); if (file == null) { return; } var stream = await file.OpenAsync(FileAccessMode.Read); ViewModel.AttachedImage = stream; ViewModel.IsImageAttached = true; ViewModel.ImagePath = file.Path; return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state) { string error; try { if (TrophyScrollingCollection == null || !TrophyScrollingCollection.Any()) { if (!string.IsNullOrEmpty(parameter as string)) { Username = parameter as string; } else { Username = Shell.Instance.ViewModel.CurrentUser.Username; } SetTrophyList(); } return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
public async Task Refresh() { IsLoading = true; string error = ""; try { var bookmarkResult = await _threadManager.GetAllBookmarks(); BookmarkedThreads = new ObservableCollection <Thread>(); foreach (var bookmark in bookmarkResult) { BookmarkedThreads.Add(bookmark); } await ApplicationData.Current.LocalSettings.SaveAsync(RefreshKey, DateTime.UtcNow); await ForumsDatabase.RefreshBookmarkedThreads(BookmarkedThreads.ToList()); } catch (Exception ex) { error = ex.Message; } if (!string.IsNullOrEmpty(error)) { await ResultChecker.SendMessageDialogAsync($"Failed to get Bookmarks (Refresh): {error}", false); } IsLoading = false; }
public async Task LoadInitialList() { IsLoading = true; string error = ""; try { var bookmarks = await ForumsDatabase.GetBookmarkedThreadsFromDb(); if (bookmarks != null && bookmarks.Any()) { BookmarkedThreads = bookmarks.OrderBy(node => node.OrderNumber).ToObservableCollection(); } string refreshTime = await ApplicationData.Current.LocalSettings.ReadAsync <string>(RefreshKey); if ((!BookmarkedThreads.Any() || (!string.IsNullOrEmpty(refreshTime) && DateTime.Parse(refreshTime) > (DateTime.UtcNow.AddHours(1.00))))) { await Refresh(); } } catch (Exception ex) { error = ex.Message; } if (!string.IsNullOrEmpty(error)) { await ResultChecker.SendMessageDialogAsync($"Failed to get Bookmarks (Load Inital List): {error}", false); } IsLoading = false; }
public async Task LoginUserWithPassword() { IsLoading = true; await RemoveUserCookies(); var result = await _authenticationManager.AuthenticateAsync(Username, Password); if (!result.IsSuccess) { await ResultChecker.SendMessageDialogAsync(result.Error, false); IsLoading = false; return; } WebManager = new WebClient(result.AuthenticationCookieContainer); var userManager = new UserManager(WebManager); // 0 gets us the default user. var userResult = await userManager.GetUserFromProfilePageAsync(0); if (userResult == null) { await ResultChecker.SendMessageDialogAsync("Failed to get user", false); IsLoading = false; return; } try { var newUser = new UserAuth { AvatarLink = userResult.AvatarLink, IsDefaultUser = true, UserName = userResult.Username, CookiePath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, Guid.NewGuid().ToString() + ".cookie") }; await UserAuthDatabase.AddOrUpdateUser(newUser); CookieManager.SaveCookie(result.AuthenticationCookieContainer, newUser.CookiePath); } catch (Exception ex) { await ResultChecker.SendMessageDialogAsync($"Failed to save user: {ex.Message}", false); IsLoading = false; return; } IsLoading = false; IsLoggedIn = true; App.ShellViewModel.PopulateNavItems(); NavigationService.Navigate(typeof(Views.MainPage)); }
public async Task AddOrRemoveFavorite(Forum forum) { try { var result = await ForumsDatabase.UpdateForumBookmark(forum); GetFavoriteForums(); } catch (Exception e) { await ResultChecker.SendMessageDialogAsync($"Failed to add or remove favorite: {e.Message}", false); } }
public async Task SendSticker(StickerSelection stickerSelection) { string error; try { var result = new Result(); if (GroupMembers.Any() && IsNewMessage) { result = await _messageManager.CreateStickerPostWithNewGroupMessage(GroupMembers.ToArray(), stickerSelection.ManifestUrl, stickerSelection.Number.ToString(), stickerSelection.ImageUrl, stickerSelection.PackageId, stickerSelection.Type, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } else { result = await _messageManager.CreateStickerPost(SelectedMessageGroup.MessageGroupId, stickerSelection.ManifestUrl, stickerSelection.Number.ToString(), stickerSelection.ImageUrl, stickerSelection.PackageId, stickerSelection.Type, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { SelectedMessageGroup = JsonConvert.DeserializeObject <MessageGroup>(result.ResultJson); await GetMessages(SelectedMessageGroup); //await GetMessageGroups(Shell.Instance.ViewModel.CurrentUser.Username); IsNewMessage = false; } return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
public async Task LoadAsync(bool forceRefresh = false) { IsLoading = true; try { LoginUser(); GetFavoriteForums(); await GetMainPageForumsAsync(forceRefresh); } catch (Exception e) { await ResultChecker.SendMessageDialogAsync($"Failed to setup forum list: {e.Message}", false); } IsLoading = false; }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state) { var error = string.Empty; try { await BuildList(); return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
private async Task SendMessageWithMedia() { var realImage = await ConvertToJpeg(AttachedImage); var result = new Result(); if (GroupMembers.Any() && IsNewMessage) { result = await _messageManager.CreateNewGroupMessageWithMedia(GroupMembers.ToArray(), Message, ImagePath, realImage, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } else { if (SelectedMessageGroup == null) { await ResultChecker.SendMessageDialogAsync("Selected Message Group Null!", false); } else { result = await _messageManager.CreatePostWithMedia(SelectedMessageGroup.MessageGroupId, Message, ImagePath, realImage, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } } await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { IsImageAttached = false; AttachedImage = null; SelectedMessageGroup = JsonConvert.DeserializeObject <MessageGroup>(result.ResultJson); await GetMessages(SelectedMessageGroup); //await GetMessageGroups(Shell.Instance.ViewModel.CurrentUser.Username); IsNewMessage = false; } }
public async Task LogoutUser() { IsLoading = true; try { //await _authenticationManager.LogoutAsync(WebManager.AuthenticationCookie); await RemoveUserCookies(); await UserAuthDatabase.RemoveUser(User); IsLoggedIn = false; App.ShellViewModel.PopulateNavItems(); } catch (Exception ex) { await ResultChecker.SendMessageDialogAsync($"Failed to log user out: {ex.Message}", false); } IsLoading = false; }
public async Task SelectMessageGroup(object sender, ItemClickEventArgs e) { var selectedMessageGroup = e.ClickedItem as MessageGroupItem; string error; try { MessageCollection.Clear(); await GetMessages(selectedMessageGroup.MessageGroup); return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
public async Task <bool> LoginDefaultUser() { string errorMessage; try { var defaultUsers = await _udb.GetDefaultUserAccounts(); if (!defaultUsers.Any()) { return(false); } var defaultUser = defaultUsers.First(); var loginResult = await LoginTest(defaultUser); if (loginResult) { if (Shell.Instance.ViewModel.CurrentUser != null) { await AccountAuthHelpers.UpdateUserIsDefault(Shell.Instance.ViewModel.CurrentUser); } CurrentUser = defaultUser; IsLoggedIn = true; return(true); //new NavigateToWhatsNewPage().Execute(null); } else { return(false); } } catch (Exception ex) { errorMessage = ex.Message; } // Failed to log in with default user, tell them. await ResultChecker.SendMessageDialogAsync(errorMessage, false); return(false); }
private async Task <List <Category> > LoadForumsFromSite() { if (_forumManager == null) { _forumManager = new ForumManager(WebManager); } try { var forumResult = await _forumManager.GetForumCategoriesAsync(); IsLoading = false; return(forumResult); } catch (Exception ex) { await ResultChecker.SendMessageDialogAsync("Failed to update initial forum list", false); IsLoading = false; return(new List <Category>()); } }
private async Task SetupPosts(Thread postresult) { var errorMessage = ""; try { //Selected.LoggedInUserName = postresult.LoggedInUserName; //Selected.CurrentPage = postresult.CurrentPage; //Selected.TotalPages = postresult.TotalPages; //Selected.Posts = postresult.Posts; // If the user is the "Test" user, say they are not logged in (even though they are) if (Selected.LoggedInUserName == "Testy Susan") { IsLoggedIn = false; Selected.IsLoggedIn = false; } var count = Selected.Posts.Count(node => !node.HasSeen); if (Selected.RepliesSinceLastOpened > 0) { if ((Selected.RepliesSinceLastOpened - count < 0) || count == 0) { Selected.RepliesSinceLastOpened = 0; } else { Selected.RepliesSinceLastOpened -= count; } } //Selected.Name = postresult.Name; return; } catch (Exception ex) { errorMessage = ex.Message; } await ResultChecker.SendMessageDialogAsync($"Error parsing thread: {errorMessage}", false); }
private async void NewMessage(object sender, RoutedEventArgs e) { string error; if (!MessageFriendList.SelectedItems.Any()) { return; } try { ViewModel.MessageCollection?.Clear(); var usernameObjectList = MessageFriendList.SelectedItems.ToList(); var friendList = usernameObjectList.Cast <Friend>().ToList(); var usernameList = friendList.Select(node => node.OnlineId).ToList(); ViewModel.IsNewMessage = true; ViewModel.GroupMembers = usernameList; var selectedGroupMessage = new MessageGroup() { MessageGroupDetail = new MessageGroupDetail() { MessageGroupName = string.Join(",", usernameList) } }; ViewModel.SelectedMessageGroup = selectedGroupMessage; ViewModel.Selected = new MessageGroupItem() { MessageGroup = selectedGroupMessage }; FriendMessageFlyout.Hide(); return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state) { if (state.ContainsKey(nameof(Username)) && state.ContainsKey(nameof(NpcommunicationId)) && state.ContainsKey(nameof(TrophyName))) { Username = state[nameof(Username)]?.ToString(); NpcommunicationId = state[nameof(NpcommunicationId)]?.ToString(); TrophyName = state[nameof(TrophyName)]?.ToString(); } string error; try { if (TrophyDetailList == null || !TrophyDetailList.Any()) { if (string.IsNullOrEmpty(NpcommunicationId) || string.IsNullOrEmpty(Username)) { var trophyNavString = parameter as string; if (string.IsNullOrEmpty(trophyNavString)) { return; } var trophyNav = JsonConvert.DeserializeObject <TrophyNavProperties>(trophyNavString); NpcommunicationId = trophyNav.NpCommunicationId; Username = trophyNav.Username; TrophyName = trophyNav.TrophyName; } await SetTrophyDetailList(); } return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
private async Task SendMessageWithoutMedia() { var result = new Result(); if (GroupMembers.Any() && IsNewMessage) { result = await _messageManager.CreateNewGroupMessage(GroupMembers.ToArray(), Message, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region); } else { if (SelectedMessageGroup == null) { await ResultChecker.SendMessageDialogAsync("Selected Message Group Null!", false); } else { result = await _messageManager.CreatePost(SelectedMessageGroup.MessageGroupId, Message, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region); } } await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { SelectedMessageGroup = JsonConvert.DeserializeObject <MessageGroup>(result.ResultJson); await GetMessages(SelectedMessageGroup); await GetMessageGroups(Locator.ViewModels.MainPageVm.CurrentUser.Username); IsNewMessage = false; } }