Esempio n. 1
0
        public static IAsyncActionWithProgress <double> ClearCachedGalleriesAsync()
        {
            return(Run <double>(async(token, progress) =>
            {
                using (var db = new GalleryDb())
                {
                    var folder = GalleryImage.ImageFolder ?? await GalleryImage.GetImageFolderAsync();
                    var todelete = await db.ImageSet
                                   .Where(im => !db.SavedSet.Any(sm => im.UsingBy.Any(gi => gi.GalleryId == sm.GalleryId)))
                                   .ToListAsync(token);
                    double count = todelete.Count;
                    var i = 0;
                    foreach (var item in todelete)
                    {
                        var file = await folder.TryGetFileAsync(item.FileName);
                        if (file != null)
                        {
                            await file.DeleteAsync();
                        }

                        progress.Report(++i / count);
                    }
                    db.ImageSet.RemoveRange(todelete);
                    await db.SaveChangesAsync();
                }
            }));
        }
Esempio n. 2
0
 protected IAsyncOperation <ImageSource> GetThumbLocalilyAsync()
 {
     return(Run <ImageSource>(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 is null)
             {
                 return null;
             }
             var folder = GalleryImage.ImageFolder ?? await GalleryImage.GetImageFolderAsync();
             var file = await folder.TryGetFileAsync(imageModel.Image.FileName);
             if (file is null)
             {
                 return null;
             }
             try
             {
                 using (var stream = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem))
                 {
                     await CoreApplication.MainView.Dispatcher.Yield();
                     var image = new BitmapImage();
                     await image.SetSourceAsync(stream);
                     return image;
                 }
             }
             catch (Exception)
             {
                 return null;
             }
         }
     }));
 }
Esempio n. 3
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;
             }
         }
     }));
 }
Esempio n. 4
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);
         }
     }));
 }