internal async Task <string> GetLocalImageUriAsync(ReportViewItem viewItem) { var cacheFolder = await this.GetCacheFolderAsync(); // build a path based on the native id... var filename = GetCacheFilename(viewItem); StorageFile cacheFile = null; try { cacheFile = await cacheFolder.GetFileAsync(filename); } catch (FileNotFoundException ex) { SinkWarning(ex); } // did we get one? if (cacheFile != null) { Debug.WriteLine(string.Format("Cache image for '{0}' was found locally...", viewItem.NativeId)); return(CalculateLocalImageUrl(viewItem)); } else { Debug.WriteLine(string.Format("Cache image for '{0}' was not found locally...", viewItem.NativeId)); return(null); } }
internal void EnqueueImageDownload(ReportViewItem viewItem) { Debug.WriteLine(string.Format("Enqueuing download for '{0}'...", viewItem.NativeId)); // create a new task... Task <Task <string> > .Factory.StartNew(async() => { Debug.WriteLine(string.Format("Requesting image for '{0}'...", viewItem.NativeId)); // load... var proxy = TinyIoCContainer.Current.Resolve <IGetReportImageServiceProxy>(); var result = await proxy.GetReportImageAsync(viewItem.NativeId); // check... result.AssertNoErrors(); // create the new file... var filename = GetCacheFilename(viewItem); var cacheFolder = await this.GetCacheFolderAsync(); var cacheFile = await cacheFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); using (var stream = await cacheFile.OpenStreamForWriteAsync()) stream.Write(result.ImageBytes, 0, result.ImageBytes.Length); // get the URL... string url = this.CalculateLocalImageUrl(viewItem); Debug.WriteLine(string.Format("Image load for '{0}' finished.", viewItem.NativeId)); return(url); }).ContinueWith(async(t) => { // send it back... Debug.WriteLine(string.Format("Setting image for '{0}'...", viewItem.NativeId)); viewItem.ImageUri = (await t).Result; }, TaskScheduler.FromCurrentSynchronizationContext()); }
internal bool MatchKeyword(ReportViewItem item) { // if we have a keyword, match it, otherwise assume it's ok... if (!(string.IsNullOrEmpty(this.Keyword))) { return(item.Title.ToLower().EndsWith(this.Keyword)); } else { return(true); } }
private string CalculateLocalImageUrl(ReportViewItem viewItem) { return(string.Format("ms-appdata:///local/{0}/{1}.jpg", LocalCacheFolderName, viewItem.NativeId)); }
private string GetCacheFilename(ReportViewItem viewItem) { return(viewItem.NativeId + ".jpg"); }
public static async Task PopulateSuggestionsAsync(string queryText, SearchSuggestionCollection results) { // if we don't have at least three characters to work with, do nothing... if (queryText.Length < 3) { return; } // how many? int maxSuggestions = 5; // get the list... var suggestions = await ReportItem.GetSearchSuggestionsAsync(queryText); // sort the suggestions... var titles = new List <string>(); foreach (var title in suggestions.Keys) { titles.Add(title); } titles.Sort(); // do we have one that we can use as a recommendation? ReportItem recommendation = null; foreach (var title in titles) { if (suggestions[title].Count == 1) { recommendation = suggestions[title][0]; break; } } // if we have a recommendation only show three suggestions... if (recommendation != null) { maxSuggestions -= 2; } // add the suggestions... foreach (var title in titles) { results.AppendQuerySuggestion(title); // enough? if (results.Size == maxSuggestions) { break; } } // add the recommendation... if (recommendation != null) { // we need an image... var viewItem = new ReportViewItem(recommendation); var imageUri = await new ReportImageCacheManager().GetLocalImageUriAsync(viewItem); // add the suggestion... results.AppendSearchSeparator("Recommendation"); results.AppendResultSuggestion(recommendation.Title, recommendation.Description, recommendation.Id.ToString(), RandomAccessStreamReference.CreateFromUri(new Uri(imageUri)), recommendation.Title); } }