public async Task <ActionResult <ComicItem> > PostComicItem(ComicItem comicItem) { _context.ComicItems.Add(comicItem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetComicItem", new { id = comicItem.Id }, comicItem)); }
private void fetchComicDataFromWeb(int forPivotIndex) { Uri comicDataUri = getComicDataUri(forPivotIndex); if (comicDataUri != null) { ComicItem model = App.comicListModel.getComicModel(forPivotIndex); model.pivotIndex = forPivotIndex; App.comicListModel.ComicLoading = true; try { Debug.WriteLine("Fetching comic strip: " + comicDataUri.ToString()); WebClient comicDataClient = new WebClient(); comicDataClient.DownloadStringCompleted += ComicJSONFetchCompleted; comicDataClient.DownloadStringAsync(comicDataUri, model); } catch (WebException e) { Debug.WriteLine("Web access already in progress. Cannot start a new one... cancelling. Error: " + e.ToString()); model = null; } } }
public async Task <IActionResult> PutComicItem(long id, ComicItem comicItem) { if (id != comicItem.Id) { return(BadRequest()); } _context.Entry(comicItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ComicItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private void showNewComic(ComicItem currentComicModel, MemoryStream comicBytes) { BitmapImage comicImage = new BitmapImage(); comicImage.SetSource(comicBytes); currentComicModel.ComicImage = comicImage; }
private void GotoComicView(ComicItem comicItem) { if (vp == null) { vp = new ViewPage(); } vp.DataContext = comicItem?.Subs; Main_Panel.Content = vp; vp.ToTop(); GC.Collect(2); }
private Uri getComicDataUri(int pivotIndex) { ComicItem model = App.comicListModel.getComicModel(pivotIndex); if (model == null) { return(null); } // Uri comicUri = new Uri("http://lakka.kapsi.fi:61950/rest/comic/get?id=" + model.ComicId); Uri comicUri = new Uri("http://scala-comic-server.herokuapp.com/comic?id=" + model.ComicId); return(comicUri); }
private void ComicStrip_Tap(object sender, System.Windows.Input.GestureEventArgs e) { if (App.comicListModel.ComicLoading) { return; } ComicItem model = App.comicListModel.getComicModel(TopPivot.SelectedIndex); if (model == null) { Debug.WriteLine("Model null!"); return; } Debug.WriteLine("TopPivot.SelectedIndex: " + TopPivot.SelectedIndex); NavigationService.Navigate(new Uri("/Fullscreen.xaml?comicIndex=" + TopPivot.SelectedIndex.ToString(), UriKind.Relative)); }
public static bool Load(string path, ICollection <Comic> list) { if (Directory.Exists(path)) { DirectoryInfo DF = new DirectoryInfo(path); var _new = new Comic(); _new.Name = DF.Name; try { _new.Cover = DF.GetFiles("cover.*")[0].FullName; } catch (Exception) { } try { _new.Info = DF.GetFiles("info.txt")[0].FullName; } catch (Exception) { } try { _new.Synopsis = DF.GetFiles("synopsis.txt")[0].FullName; } catch (Exception) { } _new.Subs = new ObservableCollection <ComicItem>(); var _DFD = DF.GetDirectories().ToList(); _DFD.Sort((a, b) => { if (string.IsNullOrEmpty(a.Name) && string.IsNullOrEmpty(b.Name)) { return(0); } if (string.IsNullOrEmpty(a.Name)) { return(-1); } if (string.IsNullOrEmpty(b.Name)) { return(1); } return(StrCmpLogicalW(a.Name, b.Name)); }); foreach (var item in _DFD) { var _newsub = new ComicItem(); _newsub.Name = item.Name; _newsub.Subs = new ObservableCollection <string>(); var _FL = item.GetFiles().ToList(); _FL.Sort((a, b) => { return(StrCmpLogicalW(a.Name, b.Name)); }); foreach (var sub in _FL) { if ("|.jpg|.png|.bmp|.gif|.jpeg".IndexOf(sub.Extension) > 0) { _newsub.Subs.Add(sub.FullName); } } _new.Subs.Add(_newsub); } if (_new.Subs.Count == 0) { _new.IsComic = false; } else { _new.IsComic = true; } list.Add(_new); return(true); } else { return(false); } }
private void ComicListFetchCompleted(object sender, DownloadStringCompletedEventArgs e) { WebClient wc = sender as WebClient; if (wc != null) { wc = null; } if (RESTError(e)) { Debug.WriteLine("Error fetching comic list! Error: " + e.Error.ToString()); return; } // Process JSON to get interesting data. DataContractJsonSerializer jsonparser = new DataContractJsonSerializer(typeof(PivotComicsData)); PivotComicsData serverComics = null; try { byte[] jsonArray = Encoding.UTF8.GetBytes(e.Result); MemoryStream jsonStream = new MemoryStream(jsonArray); serverComics = (PivotComicsData)jsonparser.ReadObject(jsonStream); } catch (SerializationException) { Debug.WriteLine("Cannot serialize the JSON. Giving up! Json: " + e.Result); return; } // Populate the model with comic data. IEnumerator <ComicInfo> enumerator = serverComics.comics.GetEnumerator(); while (enumerator.MoveNext()) { ComicInfo comic = enumerator.Current; ComicItem model = new ComicItem(); model.ComicName = comic.name; model.ComicId = comic.comicid; Debug.WriteLine("Got comic from server. Name: " + comic.name + ", id: " + comic.comicid); App.comicListModel.addComic(model); } // Check to see if we have some comic in the DB which is not present on the server. Need to remove that. Collection <ComicItem> comicsInDB = App.comicListModel.AllComicsListModel; IEnumerator <ComicInfo> serverComicsEnum = serverComics.comics.GetEnumerator(); foreach (ComicItem localComic in comicsInDB) { bool found = false; while (serverComicsEnum.MoveNext()) { ComicInfo serverComic = serverComicsEnum.Current; if (localComic.ComicId == serverComic.comicid) { found = true; break; } } if (!found) { Debug.WriteLine("Server does not contain the comic anymore. Removing locally: " + localComic.ComicName); App.comicListModel.removeComicItem(localComic); } serverComicsEnum.Reset(); } // Activate the first comic after the pivots have been populated. if (TopPivot.Items.Count > 0) { TopPivot.SelectedItem = TopPivot.Items[0]; } }
void FetchComicReadCompleted(object sender, OpenReadCompletedEventArgs e) { // Clean the webclient that was created when this request was created. WebClient webClient = sender as WebClient; if (webClient != null) { webClient = null; } if (RESTError(e)) { Debug.WriteLine("Error fetching comic image! Error: " + e.Error.ToString()); return; } ComicItem currentComicModel = (ComicItem)e.UserState; Debug.WriteLine("Fetched comic strip image."); Stream reply = null; try { reply = (Stream)e.Result; } catch (WebException webEx) { if (webEx.Status != WebExceptionStatus.Success) { Debug.WriteLine("Web error occured. Cannot load image!"); return; } } MemoryStream comicStripBytes = new MemoryStream(); reply.CopyTo(comicStripBytes); byte[] imgBytes = comicStripBytes.ToArray(); if (isGifImage(imgBytes)) { Debug.WriteLine("Image is a GIF"); ExtendedImage gifStrip = new ExtendedImage(); gifStrip.LoadingCompleted += (s, args) => { Debug.WriteLine("GIF loaded. Encoding GIF image to PNG image..."); ExtendedImage gifImage = (ExtendedImage)s; MemoryStream pngBytes = new MemoryStream(); ImageTools.IO.Png.PngEncoder enc = new PngEncoder(); enc.Encode(gifImage, pngBytes); this.Dispatcher.BeginInvoke(() => { Debug.WriteLine("Encoding done. Setting PNG bytes to BitmapImage and showing."); showNewComic(currentComicModel, pngBytes); }); }; gifStrip.UriSource = new Uri(currentComicModel.imageUrl, UriKind.Absolute); } else { Debug.WriteLine("Image is not a GIF. Putting image bytes directly to BitmapImage."); showNewComic(currentComicModel, comicStripBytes); } App.comicListModel.ComicLoading = false; }
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 ); }