protected override async Task OnRefreshAsync(bool forceRefresh, CancellationToken ct) { if (string.IsNullOrEmpty(this.ID)) { throw new UserFriendlyException("No item was requested to be displayed."); } if (forceRefresh || this.Item == null) { this.ShowInterstitialAd(); try { if (this.Item == null) { this.Title = Resources.TextLoading; } this.ShowBusyStatus(Resources.TextLoading, this.Item == null); using (var api = new ClientApi()) { this.Item = await api.GetItemByID(this.ID, ct); } } finally { await this.RefreshUIAsync(); } } if (this.Item == null) { this.Title = Resources.TextNotApplicable; throw new ArgumentException("No item to display."); } }
/// <summary> /// Converts a tile ID back into an object instance. /// </summary> /// <param name="tileID">Tile ID to retrieve an object instance for.</param> /// <param name="ct">Cancelation token.</param> /// <returns>Object instance if found else null.</returns> public override async Task <IModel> GenerateModelFromTileIdAsync(string tileID, CancellationToken ct) { try { if (tileID.StartsWith("ItemModel_")) { var id = tileID.Split('_').Last(); using (var api = new ClientApi()) { return(await api.GetItemByID(id, ct)); } } } catch (Exception ex) { throw new Exception(string.Format("Couldn't generate model from tileID = {0}", tileID), ex); } throw new NotImplementedException(string.Format("App has not implemented creating a model from tileID = {0}", tileID)); }