// ViewModel Search Worker // --------------------------------------------------------------------------------------------------------------------------------------------- private void getDataTaskStart(object sender, TaskWorkerEventArgs e) { if (e.Parameters == null && e.Parameters is int == false) { return; } simulatedDelay(); if (getDataTask.CancellationRequested) { return; } int index = (int)e.Parameters; SQLFunctions sqlFunctions = new SQLFunctions(SQLConnection.DatabaseContext); MultiModel displayModel = null; displayModel = sqlFunctions.GetPersonDetails(PersonTableResults[index].PersonID); if (getDataTask.CancellationRequested) { return; } if (displayModel != null) { BitmapImage bitmapImage = ImageSourceReader.Read(displayModel.PhotoURL); e.Results = new Tuple <MultiModel, BitmapImage>(displayModel, bitmapImage);; } }
private async void loadImage(string imagePath) { ProgressBarIsEnabled = true; ProgressBarVisibility = Visibility.Visible; try { BitmapImage bitmapImage = null; Task taskLoadImage = null; taskLoadImage = Task.Run(() => { bitmapImage = ImageSourceReader.Read(imagePath); if (bitmapImage != null) { PhotoURL = imagePath; } }); await taskLoadImage; if (taskLoadImage != null) { taskLoadImage.Dispose(); } Portrait = bitmapImage; } catch (Exception Ex) { LogWriter.Exception("Image task error.", Ex); } ProgressBarVisibility = Visibility.Hidden; ProgressBarIsEnabled = false; }
private void getPage(int page) { int imageCount = Statics.ResourceCatalog.Count(r => r.Contains("ResourceCats")); if (imageCount < 1 || page < 1) { return; } PageCount = ((imageCount - 1) / defaultTake) + 1; // The above checks ensures this does not go badly. PhotoThumbnails.Clear(); ImageSourceReader.Cleanup(); try { var imageFiles = Statics.ResourceCatalog.Where( p => p.Contains("ResourceCats")).Skip(calculateSkip(page)).Take(defaultTake); foreach (string image in imageFiles) { BitmapImage bitmapImage = ImageSourceReader.Read(image); if (bitmapImage == null) { continue; } string[] imageNameSplit = image.Split('.'); string filename = "ResourceCats." + imageNameSplit[2] + ".jpg"; PhotoThumbnails.Add(new CatModel() { Filename = filename, Portrait = bitmapImage }); } } catch (Exception Ex) { LogWriter.Exception("Error pulling catalog data. Please make sure there are no cats chewing on the cables behind your PC.", Ex); } PageCurrent = page; }