internal async Task TryLoginAsync() { if (IsSignedIn || String.IsNullOrWhiteSpace(UserName) || String.IsNullOrWhiteSpace(Password)) { return; } var session = App.Settings.Credential; if (session != null && !session.Expired) // Login with credential cookie { LightKindomHtmlClient.Credential = session; IsSignedIn = true; return; } IsLoading = true; LoadingText = "Logging into Light Kindom"; try { var credential = await LightKindomHtmlClient.LoginAsync(UserName, Password); IsSignedIn = true; App.Settings.UserName = UserName; App.Settings.Password = Password; App.Settings.Credential = credential; } catch (Exception exception) { MessageBox.Show("Login failed, please check your network and username / password."); } IsLoading = false; LoadingText = ""; }
async void FavoriteList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move) { return; } try { CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); if (e.NewItems != null) { foreach (FavourVolume vol in e.NewItems) { if (String.IsNullOrEmpty(vol.FavId)) { await LightKindomHtmlClient.AddUserFavoriteVolume(vol.VolumeId); } } } if (e.OldItems != null) { foreach (FavourVolume vol in e.OldItems) { if (!String.IsNullOrEmpty(vol.FavId)) { await LightKindomHtmlClient.DeleteUserFavorite(vol.FavId); } } } } catch (Exception exception) { Debug.WriteLine("Error : Failed to Sync User Favorite : " + exception.Message); } }
public async Task LoadCommentsAsync(LineViewModel lineView) { if (lineView.Comments.Count != 0) { return; } string lineId = lineView.Id.ToString(); Debug.WriteLine("Loading Comments : line_id = " + lineId + " ,chapter_id = " + ChapterId); try { lineView.IsLoading = true; var comments = await LightKindomHtmlClient.GetCommentsAsync(lineId, ChapterId); foreach (var comment in comments) { lineView.Comments.Add(new Comment(comment)); } lineView.IsLoading = false; } catch (Exception) { Debug.WriteLine("Comments load failed : line_id = " + lineId + " ,chapter_id = " + ChapterId); } }
public async Task LoadUserRecentAsync() { if (!IsLoading && !IsUserRecentLoaded && IsSignedIn) { LoadingText = "Loading user recent..."; IsLoading = true; try { RecentList = new ObservableCollection <Descriptor>(); var recentList = (await LightKindomHtmlClient.GetUserRecentViewedVolumesAsync()).ToList(); foreach (var item in recentList) { RecentList.Add(item); } } catch (Exception) { RecentList = null; MessageBox.Show("Load User recent failed."); } IsLoading = false; LoadingText = ""; } }
public async Task LoadUserFavouriateAsync() { if (!IsLoading && (FavouriateList == null) && IsSignedIn) { LoadingText = "Loading user favouriates..."; IsLoading = true; try { FavouriateList = new ObservableCollection <FavourVolume>(); var favList = await LightKindomHtmlClient.GetUserFavoriteVolumesAsync(); foreach (var item in favList) { FavouriateList.Add(item); } } catch (Exception) { FavouriateList = null; MessageBox.Show("Load User favouriate failed."); } IsLoading = false; LoadingText = ""; } }
public Task <Chapter> GetChapterAsync(string chptId, string volId, string serId, bool forceRefresh = false) { if (!forceRefresh && ChapterCache.ContainsKey(chptId) && !ChapterCache[chptId].IsFaulted) { return(ChapterCache[chptId]); } if (ChapterCache.Count > MaxCachedUnit) { var outdates = (from item in ChapterCache where item.Value.IsCompleted select item.Key).ToArray(); foreach (var key in outdates) { ChapterCache.Remove(key); if (ChapterCache.Count < MaxCachedUnit) { break; } } } var task = GetAsync <Chapter>( ChaptersFolder, string.Format(ChapterFileName, chptId), () => LightKindomHtmlClient.GetChapterAsync(chptId, volId, serId), null, forceRefresh); ChapterCache[chptId] = task; CachedChapterSet.Add(chptId); return(task); }
public async Task <bool> AddUserFavriteAsync(Volume vol, string seriesTitle = "Untitled") { if (FavoriteList.Any(fav => fav.VolumeId == vol.Id)) { return(true); } try { var favId = await LightKindomHtmlClient.AddUserFavoriteVolume(vol.Id); await SyncFavoriteListAsync(true); //FavourVolume favol = new FavourVolume //{ // VolumeId = vol.Id, // FavId = favId, // VolumeNo = vol.VolumeNo.ToString(), // CoverImageUri = vol.CoverImageUri, // Description = vol.Description, // VolumeTitle = vol.Title, // SeriesTitle = seriesTitle, // FavTime = DateTime.Now.AddSeconds(-5) //}; //FavoriteList.Add(favol); //CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Add User Favorite : " + exception.Message); } return(false); }
public static async Task <List <Descriptor> > GetSeriesIndexAsync(bool forceRefresh = false) { var index = await GetAsync(CacheFolder, "series_index.json", () => LightKindomHtmlClient.GetSeriesIndexAsync(), TimeSpan.FromDays(1)); if (index.Count == 0) { index = await GetAsync(CacheFolder, "series_index.json", () => LightKindomHtmlClient.GetSeriesIndexAsync(), TimeSpan.FromDays(1), true); } return(index); }
public async Task SyncRecentListAsync() { var recent = await LightKindomHtmlClient.GetUserRecentViewedVolumesAsync(); RecentList = recent.Select(item => new BookmarkInfo { Position = new NovelPositionIdentifier { VolumeId = item.Id }, VolumeTitle = item.Title }).ToList(); }
public static async Task <List <Descriptor> > GetSeriesIndexAsync(bool forceRefresh = false) { var index = await DataCache.GetAsync("series_index", () => LightKindomHtmlClient.GetSeriesIndexAsync(), DateTime.Now.AddDays(7)); if (index.Count == 0) { index = await DataCache.GetAsync("series_index", () => LightKindomHtmlClient.GetSeriesIndexAsync(), DateTime.Now.AddDays(7), true); } return(index); }
//public void LoadSampleData() //{ // string NovelText; // using (var reader = new System.IO.StreamReader("SampleData\\SampleNovel.txt")) // { // NovelText = reader.ReadToEnd(); // } // System.IO.StringReader rawTextReader = new System.IO.StringReader(NovelText); // string line; // while ((line = rawTextReader.ReadLine()) != null && Lines.Count < 7000) // { // Lines.Add(new LineViewModel(line, "Add comments here")); // } //} public async Task LoadCommentListAsync() { var commentedLines = await LightKindomHtmlClient.GetCommentedLinesListAsync(ChapterId); foreach (var lId in commentedLines) { if (Lines[lId - 1].Id != lId) { Debug.WriteLine("Can't find explicit comment line"); } Lines[lId - 1].MarkAsCommented(); } }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); ViewModel.IsLoading = true; bool isAuthed = false; try { isAuthed = await LightKindomHtmlClient.ValidateLoginAuth(); } catch (Exception) { } if (!isAuthed) { Frame.Navigate(typeof(AuthPage)); return; } try { var loginTask = ViewModel.TryLogInWithUserInputCredentialAsync(); await loginTask; } catch (Exception) { Debug.WriteLine("Failed to login"); AppGlobal.User = null; } if (!AppGlobal.IsSignedIn) { MessageDialog diag = new MessageDialog(resourceLoader.GetString("LoginFailedMessageDialogDetail"), resourceLoader.GetString("LoginFailedMessageDialogTitle")); var dialogShow = diag.ShowAsync(); await dialogShow; ViewModel.IsLoading = false; } else { ViewModel.IsLoading = false; #if WINDOWS_UWP SigninPopup.Hide(); #else SigninPopup.IsOpen = false; SigninPopup.Visibility = Windows.UI.Xaml.Visibility.Collapsed; #endif await ViewModel.FavoriteSection.LoadAsync(true); } }
internal void Logout() { if (!IsSignedIn) { return; } LightKindomHtmlClient.Logout(); UserName = ""; Password = ""; Settings.UserName = UserName; Settings.Password = Password; Settings.Credential = null; IsSignedIn = false; }
public async Task <Series> GetIndexAsync(bool forceRefresh = false) { if (_indexUpdateTask != null) { return(await _indexUpdateTask); } if (Index == null || forceRefresh) { _indexUpdateTask = GetAsync(BookFolder, SeriesMetaFileName, () => LightKindomHtmlClient.GetSeriesAsync(_seriesId), TimeSpan.FromDays(7), forceRefresh).ContinueWith(ts => { Index = ts.Result; _indexUpdateTask = null; return(ts.Result); }); await _indexUpdateTask; } return(Index); }
public async Task <bool> RemoveUserFavriteAsync(string favId) { var vol = FavoriteList.FirstOrDefault(fav => fav.FavId == favId); if (String.IsNullOrEmpty(favId) || vol == null) { return(false); } try { await LightKindomHtmlClient.DeleteUserFavorite(favId); FavoriteList.Remove(vol); CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Remove User Favorite : " + exception.Message); } return(false); }
public static async Task PushBookmarkToUserFavortiteAsync(bool forceSyncFromCloud = false) { //if (forceSyncFromCloud) //{ // var favList = from fav in User.FavoriteList orderby fav.VolumeId group fav by fav.SeriesTitle; // List<string> // foreach (var series in favList) // { // var vol = series.LastOrDefault(); // if (BookmarkList.Any(bk => bk.SeriesTitle == vol.SeriesTitle)) // continue; // } //} foreach (var bk in BookmarkList) { if (!User.FavoriteList.Any(fav => bk.Position.VolumeId == fav.VolumeId)) { var result = await LightKindomHtmlClient.AddUserFavoriteVolume(bk.Position.VolumeId); } } }
public static async Task <bool> SignInAutomaticllyAsync(bool forecRefresh = false) { var userName = Settings.UserName; var session = Settings.Credential; var password = Settings.Password; if (String.IsNullOrEmpty(password) || String.IsNullOrEmpty(userName)) { return(false); } try { if (!forecRefresh && !session.Expired) { LightKindomHtmlClient.Credential = session; User = new UserInfo { UserName = userName, Password = password, Credential = session }; } else { var newSession = await LightKindomHtmlClient.LoginAsync(userName, password); if (newSession == null) { return(false); } Settings.Credential = newSession; User = new UserInfo { UserName = userName, Password = password, Credential = newSession }; } return(true); } catch (Exception) { return(false); } }
public static async Task <UserInfo> SignInAsync(string userName, string password) { try { var session = await LightKindomHtmlClient.LoginAsync(userName, password); if (session == null) { return(null); } Settings.Credential = session; Settings.SetUserNameAndPassword(userName, password); User = new UserInfo { UserName = userName, Password = password, Credential = session }; } catch (Exception) { return(null); } return(User); }
public async Task <bool> AddUserFavriteAsync(Volume vol, string seriesTitle = null) { if (FavoriteList == null) { return(false); } if (FavoriteList.Any(fav => fav.VolumeId == vol.Id)) { return(true); } try { var result = await LightKindomHtmlClient.AddUserFavoriteVolume(vol.Id); if (!result) { return(false); } FavourVolume favol = new FavourVolume { VolumeId = vol.Id, FavId = null, VolumeNo = vol.VolumeNo.ToString(), CoverImageUri = vol.CoverImageUri, Description = vol.Description, VolumeTitle = vol.Title, SeriesTitle = seriesTitle, FavTime = DateTime.Now.AddSeconds(-5) }; FavoriteList.Add(favol); CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Add User Favorite : " + exception.Message); } return(false); }
public async Task <bool> RemoveUserFavriteAsync(string[] favIds) { try { await LightKindomHtmlClient.DeleteUserFavorite(favIds); foreach (var favId in favIds) { var f = FavoriteList.FirstOrDefault(fa => fa.FavId == favId); if (f != null) { FavoriteList.Remove(f); } } CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Remove User Favorite : " + exception.Message); } return(false); }
public async Task <bool> AddUserFavriteAsync(string volId) { if (FavoriteList.Any(fav => fav.VolumeId == volId)) { return(true); } try { var result = await LightKindomHtmlClient.AddUserFavoriteVolume(volId); if (!result) { return(false); } await SyncFavoriteListAsync(true); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Add User Favorite : " + exception.Message); } return(false); }
public async Task LoadOnlineAsync() { if (!IsLoading && !IsLoaded) { IsLoading = true; try { var recentList = await LightKindomHtmlClient.GetUserRecentViewedVolumesAsync(); if (recentList != null) { this.Clear(); foreach (var item in recentList) { var hvm = new HistoryItemViewModel { Position = new NovelPositionIdentifier { VolumeId = item.Id, }, SeriesTitle = item.Title, }; this.Add(hvm); } } } catch (Exception exception) { throw exception; //MessageBox.Show("Load User recent failed."); } NotifyPropertyChanged("IsEmpty"); IsLoading = false; } }
public static Task <Chapter> GetChapterAsync(string id, bool forceRefresh = false) { if (!forceRefresh && ChapterCache.ContainsKey(id) && !ChapterCache[id].IsFaulted) { return(ChapterCache[id]); } if (ChapterCache.Count > MaxCachedUnit) { var outdates = from item in ChapterCache where item.Value.IsCompleted select item.Key; foreach (var key in outdates) { ChapterCache.Remove(key); if (ChapterCache.Count < MaxCachedUnit) { break; } } } var task = DataCache.GetAsync("chapter-" + id, () => LightKindomHtmlClient.GetChapterAlterAsync(id), null, forceRefresh); ChapterCache[id] = task; return(task); }
public static Task <Series> GetSeriesAsync(string id, bool forceRefresh = false) { if (forceRefresh == false && SeriesCache.ContainsKey(id) && !SeriesCache[id].IsFaulted) { return(SeriesCache[id]); } if (SeriesCache.Count > MaxCachedUnit) { var outdates = from item in SeriesCache where item.Value.IsCompleted select item.Key; foreach (var key in outdates) { SeriesCache.Remove(key); if (SeriesCache.Count < MaxCachedUnit) { break; } } } var task = DataCache.GetAsync("series-" + id, () => LightKindomHtmlClient.GetSeriesAsync(id), DateTime.Now.AddDays(7), forceRefresh); SeriesCache[id] = task; return(task); }
public async Task ClearUserInfoAsync() { await LightKindomHtmlClient.LogoutAsync(); await CachedClient.ClearUserFavoriteCacheAsync(); }
public static Task <IList <KeyValuePair <string, IList <BookItem> > > > GetRecommandedBookLists() { return(DataCache.GetAsync("popular_series", () => LightKindomHtmlClient.GetRecommandedBookLists(), DateTime.Now.AddDays(1))); }
public static Task <List <Descriptor> > GetSeriesIndexAsync(bool forceRefresh = false) { return(DataCache.GetAsync("series_index", () => LightKindomHtmlClient.GetSeriesIndexAsync())); }
public static Task <Chapter> GetChapterAsync(string id, bool forceRefresh = false) { return(DataCache.GetAsync("chapter-" + id, () => LightKindomHtmlClient.GetChapterAsync(id))); }
public static Task <Volume> GetVolumeAsync(string id, bool forceRefresh = false) { return(DataCache.GetAsync("volume-" + id, () => LightKindomHtmlClient.GetVolumeAsync(id))); }
public static Task <Series> GetSeriesAsync(string id, bool forceRefresh = false) { return(DataCache.GetAsync("series-" + id, () => LightKindomHtmlClient.GetSeriesAsync(id))); }