public void ShowComic(ComicData comic, bool isVictoryComic) { for (int i = 0; i < Mathf.Max(comic.images.Length, comic.stringKeys.Length); i++) { GameObject gameObject = Util.KInstantiateUI(panelPrefab, contentContainer, true); activePanels.Add(gameObject); gameObject.GetComponentInChildren <Image>().sprite = comic.images[i]; gameObject.GetComponentInChildren <LocText>().SetText(comic.stringKeys[i]); } closeButton.ClearOnClick(); if (isVictoryComic) { closeButton.onClick += delegate { Stop(); Show(false); }; } else { closeButton.onClick += delegate { Stop(); }; } }
private void OnImportComicFinished(ComicData comic) { importingComics.Remove(comic); // Need to refresh whole list for correct ordering DisplayComics(); }
protected override void OnComicChanged(ComicData newComic) { labelComicName.Text = newComic?.Name; labelLastComicPageName.Text = newComic.LastReadPage?.Name; progressBarReadProgress.Progress = newComic.ReadProgress; if (newComic.LastReadDate != null) { TimeSpan timeSince = DateTimeOffset.UtcNow - newComic.LastReadDate.Value; labelLastRead.Text = string.Format(Res.ComicInfo_LastRead, timeSince.Days); } else { labelLastRead.Text = string.Empty; } // Different appearance if updating if (newComic.IsUpdating) { // Can't tap on if still importing (need to use Any since Contains isn't supported) if (!ComicDatabase.Instance.GetComicsQuery() .Any(c => c.Id == newComic.Id)) { IsEnabled = false; } Opacity = 0.3f; } else { IsEnabled = true; Opacity = 1.0; } }
private async Task DownloadCoverImage(ComicData comic, CancellationToken cancelToken = default) { if (comic == null || comic.Pages.Count() == 0) { return; } string url = await ComicUpdater.Instance.GetComicImageUrl(comic.Pages.ElementAt(0), cancelToken); if (string.IsNullOrEmpty(url)) { return; } string filePath = await LocalImageService.DownloadImage(new Uri(url), comic.Id, cancelToken); if (string.IsNullOrEmpty(filePath)) { return; } CoverImage.Source = new FileImageSource { File = filePath }; }
public static void ComicPageMarkReadClearsIsNew() { var comic = new ComicData(); var page = new ComicPageData { Comic = comic, IsRead = false, IsNew = true }; database.Write(realm => { // Add 1 comic with 1 page realm.Add(comic); realm.Add(page); }); database.MarkRead(page); Assert.Multiple(() => { Assert.IsTrue(page.IsRead); Assert.IsFalse(page.IsNew); }); }
protected void LinqButton_Click(object sender, EventArgs e) { ComicsDBDataContext db = new ComicsDBDataContext(); string sDirectory = @"~\Comics\Explosm\"; int iIncrementFrom = 1210; int iIncrementTo = 3040; //ComicData columns string sFileName = "Explosm"; string sFileExtension = ".png"; string sWebsite = "Explosm"; int iBumps = 0; string sAbsolutePath = (sDirectory + sFileName + Convert.ToString(iIncrementFrom) + sFileExtension); DateTime oDateNow = DateTime.Now; //This is how the webpage determines if the filepath exists because //(System.IO.File.Exists() doesn't work the way I try to use it) string sCompleteFilePath = HttpContext.Current.Server.MapPath(sDirectory + sFileName + Convert.ToString(iIncrementFrom) + sFileExtension); do { //checks to see if the directory file even exists, if not then skip && increment if(System.IO.File.Exists(sCompleteFilePath) == true) { //returns true if there if FileName exists in the database. var hasName = db.ComicDatas.Any(p => p.FileName.Equals(sFileName + Convert.ToString(iIncrementFrom)) ); //if the FileName does not exist in the column if (hasName == false) { ComicData oColumn = new ComicData(); oColumn.FileName = (sFileName + Convert.ToString(iIncrementFrom)); oColumn.FileExtension = sFileExtension; oColumn.Website = sWebsite; oColumn.Bumps = iBumps; oColumn.FilePath = sAbsolutePath; oColumn.DateAdded = oDateNow; db.ComicDatas.InsertOnSubmit(oColumn); db.SubmitChanges(); } } iIncrementFrom += 1; //re-bind with the incremented data sCompleteFilePath = HttpContext.Current.Server.MapPath(sDirectory + sFileName + Convert.ToString(iIncrementFrom) + sFileExtension); //re-bind with the incremented data sAbsolutePath = (sDirectory + sFileName + Convert.ToString(iIncrementFrom) + sFileExtension); } while (iIncrementFrom <= iIncrementTo); }
private void OnImportComicBegun(ComicData comic) { importingComics.Add(comic); // Just add this comic to start of Library list - no need to refresh whole page ComicLibrary.Insert(0, comic); RaisePropertyChanged(nameof(ComicLibrary)); RaisePropertyChanged(nameof(IsAnyComics)); }
public static void DeletingComicDeletesCoverImage() { var comic = new ComicData(); database.AddComic(comic); string imagePath = LocalImageService.WriteImage(comic.Id, new byte[0]); database.DeleteComic(comic); Assert.IsFalse(File.Exists(imagePath), "Comic cover image was not deleted."); }
private void ComicChanged(ComicData newComic) { if (newComic != previousComic) { if (previousComic != null) { previousComic.Updated -= RefreshComic; previousComic.PropertyChanged -= OnComicDataPropertyChanged; } if (newComic != null) { newComic.Updated += RefreshComic; newComic.PropertyChanged += OnComicDataPropertyChanged; } previousComic = newComic; } if (coverImageDownloadCancel != null) { coverImageDownloadCancel.Cancel(); } if (newComic == null) { CoverImage.Source = null; return; } // Load cover image string coverImagePath = LocalImageService.GetImagePath(newComic.Id); // Cover image hasn't been download yet if (string.IsNullOrEmpty(coverImagePath)) { coverImageDownloadCancel = new CancellationTokenSource(); // Download image, and then set image source DownloadCoverImage(newComic, coverImageDownloadCancel.Token) .SafeFireAndForget(); } else { // Set image source immediately CoverImage.Source = new FileImageSource { File = coverImagePath }; } OnComicChanged(newComic); }
public static void DeleteComic() { var comic = new ComicData(); database.AddComic(comic); database.DeleteComic(comic); var comics = database.GetComics(); var comicCount = comics.Count; Assert.AreEqual(0, comicCount); }
public static async Task ComicNameChangePersistsAfterUpdating( [ValueSource(nameof(EnumerateKnownComicTypes))] MockComic comic) { // Initial comic import ComicData savedComic = await comicUpdater.ImportComic(comic.State1.ArchiveUrl); database.Write(realm => savedComic.Name = "New Name"); // Update comic now that selector has been switched IEnumerable <ComicPageData> pages = await comicUpdater.UpdateComic(savedComic); Assert.AreEqual("New Name", savedComic.Name); }
public static async Task PageIsNewIsFalseWhenImported( [ValueSource(nameof(EnumerateKnownComicTypes))] MockComic comic) { ComicData savedComic = await comicUpdater.ImportComic(comic.State1.ArchiveUrl); Assert.Multiple(() => { // No pages should be new since comic was just imported foreach (var page in savedComic.Pages) { Assert.IsFalse(page.IsNew); } }); }
protected override void OnComicChanged(ComicData newComic) { labelComicName.Text = newComic?.Name; labelComicPageName.Text = newComic.LatestNewPage?.Name; if (newComic.LastUpdatedDate != null) { TimeSpan timeSince = DateTimeOffset.UtcNow - newComic.LastUpdatedDate.Value; labelLastUpdated.Text = string.Format(Res.ComicInfo_LastUpdatedShort, timeSince.Days); } else { labelLastUpdated.Text = string.Empty; } }
public static async Task PageIsNewIsTrueWhenUpdated( [ValueSource(nameof(EnumerateKnownComicTypes))] MockComic comic) { // Initial comic import ComicData savedComic = await comicUpdater.ImportComic(comic.State1.ArchiveUrl); // Switch selector to next stage pageLoader.StateSelector = c => c.State2; // Update comic now that selector has been switched IEnumerable <ComicPageData> pages = await comicUpdater.UpdateComic(savedComic); Assert.GreaterOrEqual(pages.Count(p => p.IsNew), 1); Assert.Fail(); }
public static void DeletingComicDeletesPages() { var comic = new ComicData(); database.Write(realm => { // Add 1 comic with 1 page realm.Add(comic); var page = new ComicPageData { Comic = comic }; realm.Add(page); }); // Delete comic database.DeleteComic(comic); // Check that page was also deleted (should be no pages in database) var pages = database.Realm.All <ComicPageData>(); var pageCount = pages.Count(); Assert.AreEqual(0, pageCount); }
void ComicJSONFetchCompleted(object sender, DownloadStringCompletedEventArgs e) { if (RESTError(e)) { Debug.WriteLine("Error fetching JSON! Error: " + e.Error.ToString()); return; } if (String.IsNullOrEmpty(e.Result)) { Debug.WriteLine("Error: Got no JSON for comic."); return; } // Clean the webclient that was created when this request was created. WebClient webClient = sender as WebClient; if (webClient != null) { webClient = null; } ComicItem model = (ComicItem)e.UserState; // Process JSON to get interesting data. DataContractJsonSerializer jsonparser = new DataContractJsonSerializer(typeof(ComicData)); ComicData data = null; try { byte[] jsonBytes = Encoding.UTF8.GetBytes(e.Result); MemoryStream jsonStream = new MemoryStream(jsonBytes); data = (ComicData)jsonparser.ReadObject(jsonStream); } catch (SerializationException) { Debug.WriteLine("Cannot serialize the JSON. Giving up! Json: " + e.Result); model = null; return; } Debug.WriteLine("Parsing JSON done. Fetching comic from URL: " + data.url); int requestedPivotIndex = model.pivotIndex; model.imageUrl = data.url; model.PubDate = data.pubdate; model.siteUrl = data.siteurl; if (String.IsNullOrEmpty(data.url)) { Debug.WriteLine("Comic URL is empty, cannot fetch comic!"); return; // TODO: Add a broken image indicator... } WebClient wc = new WebClient(); wc.OpenReadCompleted += FetchComicReadCompleted; wc.OpenReadAsync(new Uri(data.url, UriKind.Absolute), model ); }
protected abstract void OnComicChanged(ComicData newComic);
partial void InsertComicData(ComicData instance);
public override void Init(object initData) { Comic = initData as ComicData; }
partial void UpdateComicData(ComicData instance);
partial void DeleteComicData(ComicData instance);