diff options
-rw-r--r-- | ComicRackWebViewer/API.cs | 196 | ||||
-rw-r--r-- | ComicRackWebViewer/Entities.cs | 226 |
2 files changed, 0 insertions, 422 deletions
diff --git a/ComicRackWebViewer/API.cs b/ComicRackWebViewer/API.cs deleted file mode 100644 index 9e31ede..0000000 --- a/ComicRackWebViewer/API.cs +++ /dev/null @@ -1,196 +0,0 @@ -using System; -using System.Windows; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.Drawing.Drawing2D; -using System.IO; -using System.Linq; -using cYo.Projects.ComicRack.Engine; -using cYo.Projects.ComicRack.Engine.IO.Provider; -using cYo.Projects.ComicRack.Viewer; -using Nancy; -using Nancy.OData; - -namespace ComicRackWebViewer -{ - public static class API - { - public static BooksList GetIssuesOfList(string name, NancyContext context) - { - var list = Program.Database.ComicLists.FirstOrDefault(x => x.Name == name); - if (list == null) - { - return new BooksList - { - Comics = Enumerable.Empty<Comic>(), - Name = name - }; - } - return new BooksList - { - Comics = context.ApplyODataUriFilter(list.GetBooks().Select(x => x.ToComic())).Cast<Comic>(), - Name = name - }; - } - - - public static IEnumerable<Series> GetSeries() - { - return Plugin.Application.GetLibraryBooks().AsSeries(); - } - - public static BooksList GetSeries(Guid id, NancyContext context) - { - var books = Plugin.Application.GetLibraryBooks(); - var book = books.Where(x => x.Id == id).First(); - var series = books.Where(x => x.ShadowSeries == book.ShadowSeries) - .Where(x => x.ShadowVolume == book.ShadowVolume) - .Select(x => x.ToComic()) - .OrderBy(x => x.Number).ToList(); - return new BooksList - { - Comics = context.ApplyODataUriFilter(series).Cast<Comic>(), - Name = book.ShadowSeries - }; - } - - public static Response GetThumbnailImage(Guid id, int page, IResponseFormatter response) - { - var bitmap = Image.FromStream(new MemoryStream(GetPageImageBytes(id, page)), false, false); - double ratio = 200D / (double)bitmap.Height; - int width = (int)(bitmap.Width * ratio); - var callback = new Image.GetThumbnailImageAbort(() => true); - var thumbnail = bitmap.GetThumbnailImage(width, 200, callback, IntPtr.Zero); - MemoryStream stream = GetBytesFromImage(thumbnail); - return response.FromStream(stream, MimeTypes.GetMimeType(".jpg")); - } - - - public static MemoryStream GetBytesFromImage(Image image) - { - var bitmap = new Bitmap(image); - MemoryStream stream = new MemoryStream(); - bitmap.Save(stream, ImageFormat.Jpeg); - stream.Position = 0; - return stream; - } - - private static byte[] GetPageImageBytes(Guid id, int page) - { - try - { - var comic = GetComics().First(x => x.Id == id); - var index = comic.TranslatePageToImageIndex(page); - var provider = GetProvider(comic); - if (provider == null) - { - return null; - } - return provider.GetByteImage(index); // ComicRack returns the page converted to a jpeg image..... - } - catch //(Exception e) - { - //MessageBox.Show(e.ToString()); - return null; - } - } - - public static Response GetPageImage(Guid id, int page, IResponseFormatter response) - { - var bytes = GetPageImageBytes(id, page); - if (bytes == null) - { - return response.AsRedirect("/original/Views/spacer.png"); - } - return response.FromStream(new MemoryStream(bytes), MimeTypes.GetMimeType(".jpg")); - } - - - public static Image Resize(Image img, int width, int height) - { - //create a new Bitmap the size of the new image - Bitmap bmp = new Bitmap(width, height); - //create a new graphic from the Bitmap - Graphics graphic = Graphics.FromImage((Image)bmp); - graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; - //draw the newly resized image - graphic.DrawImage(img, 0, 0, width, height); - //dispose and free up the resources - graphic.Dispose(); - //return the image - return (Image)bmp; - } - - private static ImageProvider GetProvider(ComicBook comic) - { - var provider = comic.CreateImageProvider(); - if (provider == null) - { - return null; - } - if (provider.Status != ImageProviderStatus.Completed) - { - provider.Open(false); - } - return provider; - } - - public static Comic GetComic(Guid id) - { - try - { - var comic = GetComics().First(x => x.Id == id); - return comic.ToComic(); - } - catch//(Exception e) - { - //MessageBox.Show(e.ToString()); - return null; - } - } - - - public static IQueryable<ComicBook> GetComics() - { - return Plugin.Application.GetLibraryBooks().AsQueryable(); - } - - public static Response GetIcon(string key, IResponseFormatter response) - { - var image = ComicBook.PublisherIcons.GetImage(key); - if (image == null) - { - return response.AsRedirect("/original/Views/spacer.png"); - } - return response.FromStream(API.GetBytesFromImage(image), MimeTypes.GetMimeType(".jpg")); - } - - public static IEnumerable<Publisher> GetPublishers() - { - return Plugin.Application.GetLibraryBooks().GroupBy(x => x.Publisher).Select(x => - { - return x.GroupBy(y => y.Imprint).Select(y => new Publisher { Name = x.Key, Imprint = y.Key }); - }).SelectMany(x => x).OrderBy(x => x.Imprint).OrderBy(x => x.Name); - } - - public static IEnumerable<Series> GetSeries(string publisher, string imprint) - { - IEnumerable<ComicBook> comics; - if (string.Compare(publisher, "no publisher", true) == 0) - { - comics = Plugin.Application.GetLibraryBooks().Where(x => string.IsNullOrEmpty(x.Publisher)); - } - else - { - comics = Plugin.Application.GetLibraryBooks().Where(x => string.Compare(publisher, x.Publisher, true) == 0); - if (string.IsNullOrEmpty(imprint)) - { - comics = comics.Where(x => string.IsNullOrEmpty(x.Imprint)); - } - comics = comics.Where(x => string.Compare(imprint, x.Imprint, true) == 0); - } - return comics.AsSeries(); - } - } -} diff --git a/ComicRackWebViewer/Entities.cs b/ComicRackWebViewer/Entities.cs deleted file mode 100644 index 7298740..0000000 --- a/ComicRackWebViewer/Entities.cs +++ /dev/null @@ -1,226 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using cYo.Projects.ComicRack.Engine;
-using cYo.Projects.ComicRack.Engine.Database;
-
-
-namespace ComicRackWebViewer
-{
- // (Smart/Folder/Item) list
- public class ComicList
- {
- public string Name { get; set; }
- public Guid Id { get; set; }
- public int ListsCount { get; set; }
- public IEnumerable<ComicList> Lists { get; set; }
- public string Type { get; set; }
- }
-
- // Collection of books from a FolderList
- public class BooksList
- {
- public string Name { get; set; }
- public Guid Id { get; set; }
- public IEnumerable<Comic> Comics { get; set; }
- public bool IsDesc { get; set; }
- }
-
- public class Publisher
- {
- public string Name { get; set; }
- public string Imprint { get; set; }
- }
-
- public class Series : IEquatable<Series>
- {
- public string Title { get; set; }
- public int Volume { get; set; }
- public Guid Id { get; set; }
- public int Count { get; set; }
-
- public bool Equals(Series other)
- {
- return Title.Equals(other.Title) && (Volume.Equals(other.Volume));
- }
-
- public override bool Equals(object obj)
- {
- var series = obj as Series;
- if (series == null)
- {
- return false;
- }
- return Equals(series);
- }
-
- public override int GetHashCode()
- {
- return Title.GetHashCode() ^ Volume.GetHashCode() * 29;
- }
- }
-
- public class ComicDate : IComparable<ComicDate>, IComparable
- {
- public ComicDate(int year, int month)
- {
- Year = year;
- Month = month;
- }
-
- public int Year { get; set; }
- public int Month { get; set; }
-
-
- public int CompareTo(ComicDate other)
- {
- if (Year == other.Year)
- {
- return Month.CompareTo(other.Month);
- }
- return Year.CompareTo(other.Year);
- }
-
- public int CompareTo(object obj)
- {
- var date = obj as ComicDate;
- if (date == null)
- {
- return -1;
- }
- return CompareTo(date);
- }
- }
-
- public class Comic
- {
- public string FilePath { get; set; }
- public string Caption { get; set; }
- public string Title { get; set; }
- public int Volume { get; set; }
- public string Number { get; set; }
- public int Count { get; set; }
- public Guid Id { get; set; }
- public int Month { get; set; }
- public int Year { get; set; }
- public ComicDate Date { get; set; }
- public int PageCount { get; set; }
- public string AlternateSeries { get; set; }
- public int AlternateCount { get; set; }
- public string Summary { get; set; }
- public string Publisher { get; set; }
- public string Imprint { get; set; }
- public string Series { get; set; }
- public string Format { get; set; }
- public float Rating { get; set; }
- public string Writer { get; set; }
- public string Penciller { get; set; }
- public string Inker { get; set; }
- public string Colorist { get; set; }
- public string Letterer { get; set; }
- public string CoverArtist { get; set; }
- public string Editor { get; set; }
- public string Genre { get; set; }
- public string Tags { get; set; }
- public string Characters { get; set; }
- public string Teams { get; set; }
- public string Locations { get; set; }
- public string Web { get; set; }
- public string Notes { get; set; }
- public string ScanInfo { get; set; }
- public string Opened { get; set; }
- public int LastPageRead { get; set; }
- }
-
-
- public static class EntityExtensions
- {
- public static IEnumerable<Series> AsSeries(this IEnumerable<ComicBook> comics)
- {
- return comics.Select(x => x.ToSeries()).Distinct();
- }
-
-
- public static ComicList ToComicList(this ComicListItem x, int depth = -1)
- {
- ComicList list = new ComicList{
- Name = x.Name,
- Id = x.Id,
- ListsCount = 0,
- Type = x.GetType().ToString().Split('.').LastOrDefault()
- };
-
- ComicListItemFolder folderList = x as ComicListItemFolder;
- if (folderList != null)
- {
- list.ListsCount = folderList.Items.Count;
- // recurse ?
- if (depth != 0)
- {
- list.Lists = folderList.Items.Select(c => c.ToComicList(depth-1));
- }
- }
-
- return list;
- }
-
- public static Comic ToComic(this ComicBook x)
- {
- return new Comic
- {
- Id = x.Id,
- FilePath = x.FilePath,
- Caption = x.Caption,
-
- Title = x.Title,
- Volume = x.Volume,
- Number = x.Number,
- Year = x.Year,
- Series = x.Series,
- Format = x.Format,
- Count = x.Count,
-
- Month = x.Month,
-
- Date = new ComicDate(x.Year, x.Month),
- PageCount = x.PageCount,
- AlternateCount = x.AlternateCount,
- AlternateSeries = x.AlternateSeries,
- Summary = x.Summary,
- Publisher = x.Publisher,
- Imprint = x.Imprint,
-
- Rating = x.Rating,
- Writer = x.Writer,
- Penciller = x.Penciller,
- Inker = x.Inker,
- Colorist = x.Colorist,
- Letterer = x.Letterer,
- CoverArtist = x.CoverArtist,
- Editor = x.Editor,
- Genre = x.Genre,
- Tags = x.Tags,
- Characters = x.Characters,
- Teams = x.Teams,
- Locations = x.Locations,
- Web = x.Web,
- Notes = x.Notes,
- ScanInfo = x.ScanInformation,
- Opened = x.OpenedTimeAsText,
- LastPageRead = x.LastPageRead
- };
- }
-
-
- public static Series ToSeries(this ComicBook x)
- {
- return new Series
- {
- Title = x.ShadowSeries,
- Volume = x.ShadowVolume,
- Id = x.Id,
- };
- }
-
- }
-}
|