Exemple #1
0
 protected IAsyncOperation <SoftwareBitmap> GetThumbLocalilyAsync()
 {
     return(Run(async token =>
     {
         using (var db = new GalleryDb())
         {
             db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
             var gId = this.ID;
             var imageModel = db.GalleryImageSet
                              .Include(gi => gi.Image)
                              .Where(gi => gi.GalleryId == gId)
                              .OrderBy(gi => gi.PageId)
                              .FirstOrDefault();
             if (imageModel == null)
             {
                 return null;
             }
             var folder = GalleryImage.ImageFolder ?? await GalleryImage.GetImageFolderAsync();
             var file = await folder.TryGetFileAsync(imageModel.Image.FileName);
             if (file == null)
             {
                 return null;
             }
             try
             {
                 using (var stream = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem))
                 {
                     var decoder = await BitmapDecoder.CreateAsync(stream);
                     return await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                 }
             }
             catch (Exception)
             {
                 return null;
             }
         }
     }));
 }
Exemple #2
0
 public static IAsyncActionWithProgress <double> ClearAllGalleriesAsync()
 {
     return(Run <double>(async(token, progress) =>
     {
         progress.Report(double.NaN);
         var folder = GalleryImage.ImageFolder ?? await GalleryImage.GetImageFolderAsync();
         var getFiles = folder.GetFilesAsync();
         using (var db = new GalleryDb())
         {
             db.SavedSet.RemoveRange(db.SavedSet);
             db.ImageSet.RemoveRange(db.ImageSet);
             await db.SaveChangesAsync();
         }
         var files = await getFiles;
         double c = files.Count;
         var i = 0;
         foreach (var item in files)
         {
             await item.DeleteAsync();
             progress.Report(++i / c);
         }
     }));
 }