///<summary>Returns a library item from the given bib (the JSON from the libraries web call).</summary> private LibraryItem GetItemFromBib(Bib bib) { if (bib == null) { return(null); } Enum.TryParse(bib.briefInfo.format ?? "", true, out ItemFormat format); return(new LibraryItem { Id = bib.id, Edition = bib.briefInfo.edition, AverageRating = bib.briefInfo.rating?.averageRating ?? 0, TotalCount = bib.briefInfo.rating?.totalCount ?? 0, CallNumber = bib.briefInfo.callNumber, ContentType = bib.briefInfo.contentType, Description = bib.briefInfo.description, PublicationDate = bib.briefInfo.publicationDate, ListAuthors = bib.briefInfo.authors?.ToList(), SourceLibrary = LibraryItemParser.GetLibaryByCode(bib.sourceLibId.ToString()), Format = format, Subtitle = bib.briefInfo.subtitle, Title = bib.briefInfo.title, ListISBNs = bib.briefInfo.isbns?.ToList(), ImageResources = new ItemResources { SmallUrl = bib.briefInfo.jacket?.small ?? "", MediumUrl = bib.briefInfo.jacket?.medium ?? "", LargeUrl = bib.briefInfo.jacket?.large ?? "", } }); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(""); } if (!(value is ItemFormat format)) { throw new ApplicationException($"Bad input to {nameof(FormatToDisplayConverter)}"); } return(LibraryItemParser.FormatToDisplay(format)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(""); } if (!(value is Library library)) { throw new ApplicationException($"Bad input to {nameof(LibraryToLibraryNameConverter)}"); } return(LibraryItemParser.GetLibraryName(library)); }
public async Task ChangeHoldsLocation(long userId, List <string> listHoldIds, Library newLocation) { HttpResponseMessage response = await _client.PatchAsync($"{HOLDS_URL}?locale=en-US", new StringContent(JsonConvert.SerializeObject(new { accountId = userId, holdIds = listHoldIds.ToArray(), location = LibraryItemParser.GetCodeByLibrary(newLocation), }), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw new ApplicationException($"Error: {(int)response.StatusCode} - {response.StatusCode.ToString()}"); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(""); } if (!(value is ItemFormat format)) { throw new ApplicationException($"Bad input to {nameof(FormatToImageConverter)}"); } FormatCategory category = LibraryItemParser.FormatToCategory(format); switch (category) { case FormatCategory.Accessible: return("resource://WcclsMobile.Images.text_format-24px.svg"); case FormatCategory.Audiobook: return("resource://WcclsMobile.Images.volume_up-24px.svg"); case FormatCategory.Book: return("resource://WcclsMobile.Images.menu_book-24px.svg"); case FormatCategory.CDDVD: return("resource://WcclsMobile.Images.album-24px.svg"); case FormatCategory.EBook: return("resource://WcclsMobile.Images.devices-24px.svg"); case FormatCategory.Games: return("resource://WcclsMobile.Images.sports_esports-24px.svg"); case FormatCategory.MagazinesJournals: return("resource://WcclsMobile.Images.newspaper.svg"); case FormatCategory.Movies: return("resource://WcclsMobile.Images.movie-24px.svg"); case FormatCategory.Music: return("resource://WcclsMobile.Images.music_note-24px.svg"); default: return(""); } }
///<summary>Returns all hold information for the given account.</summary> ///<param name="userId">The account ID.</param> ///<returns>The hold information. If null, something went wrong.</returns> public async Task <HoldsResult> GetHolds(long userId) { HttpResponseMessage response = await _client.GetAsync($"{HOLDS_URL}?accountId={userId}&size=25&locale=en-US"); string json = await response.Content.ReadAsStringAsync(); Dictionary <T, V> CreateAnonymousDictionary <T, V>(T firstType, V anonymousType) { return(new Dictionary <T, V>()); } try { #region DeserializeObject var result = JsonConvert.DeserializeAnonymousType(json, new { entities = new { bibs = new Dictionary <string, Bib>(), holds = CreateAnonymousDictionary("", new { actions = new string[0], metadataId = "", holdsId = "", bibTitle = "", autoCheckout = false, holdsPosition = 0, status = "", materialType = "", pickupLocation = new { code = "", name = "", ips = new string[0], }, expiryDate = (DateTime?)new DateTime(), suspendEndDate = (DateTime?)new DateTime(), holdPlacedDate = (DateTime?)new DateTime(), }), }, borrowing = new { holds = new { pagination = new { count = 0, page = 0, limit = 0, pages = 0, } }, summaries = new { inactiveHolds = new { totalOperative = 0, }, holds = new { totalOperative = 0, }, }, }, }); #endregion List <Hold> listHolds = new List <Hold>(); foreach (var holdData in result.entities.holds) { if (!result.entities.bibs.ContainsKey(holdData.Value.metadataId)) { continue; } Bib bib = result.entities.bibs[holdData.Value.metadataId]; Enum.TryParse(holdData.Value.status, true, out HoldStatus holdStatus); Hold hold = new Hold { HoldId = holdData.Value.holdsId, ExpiryDate = holdData.Value.expiryDate, HoldPosition = holdData.Value.holdsPosition, StatusStr = holdData.Value.status, Status = holdStatus, AvailableCopies = bib.availability.availableCopies ?? 0, TotalCopies = bib.availability.totalCopies ?? 0, ListActions = holdData.Value.actions.Select(x => { Enum.TryParse(x ?? "", true, out ItemAction ac); return(ac); }).Where(x => x != ItemAction.Unknown).ToList(), HoldPlacedDate = holdData.Value.holdPlacedDate, SuspendEndDate = holdData.Value.suspendEndDate, PickupLocation = LibraryItemParser.GetLibaryByCode(holdData.Value.pickupLocation?.code), Item = GetItemFromBib(bib), }; listHolds.Add(hold); } return(new HoldsResult { ListHolds = listHolds, ActiveHolds = listHolds.Count(x => x.Status == HoldStatus.In_Transit || x.Status == HoldStatus.Not_Yet_Available), PausedHolds = listHolds.Count(x => x.Status == HoldStatus.Suspended), ReadyForPickup = listHolds.Count(x => x.Status == HoldStatus.Ready_For_Pickup), }); } catch (Exception e) { return(null); } }