コード例 #1
0
        public StreamThumbnailViewModel(FilteredPhotoModel photo)
        {
            Model = new FilteredPhotoModel(photo);
            Model.FilteredThumbnailChanged += Model_FilteredThumbnailChanged;

            UpdateFilteredThumbnailBitmap();
        }
コード例 #2
0
        private static async Task <StorageFile> SavePhotoAsync(FilteredPhotoModel photo, StorageFile file)
        {
            CachedFileManager.DeferUpdates(file);

            using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                using (var photoStream = await photo.GetFilteredPhotoAsync())
                    using (var reader = new DataReader(photoStream))
                        using (var writer = new DataWriter(fileStream))
                        {
                            await reader.LoadAsync((uint)photoStream.Size);

                            var buffer = reader.ReadBuffer((uint)photoStream.Size);

                            writer.WriteBuffer(buffer);
                            await writer.StoreAsync();

                            await writer.FlushAsync();
                        }

            var status = await CachedFileManager.CompleteUpdatesAsync(file);

            if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
            {
                return(file);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public PreviewViewModel(FilteredPhotoModel model)
        {
            Model = model;
            Model.FilteredPhotoChanged += Model_FilteredPhotoChanged;

            UpdateResolution();
            UpdatePreview();
        }
コード例 #4
0
        public ThumbnailViewModel(FilteredPhotoModel model, Filter filter, bool highlight = false)
        {
            Model     = new FilteredPhotoModel(model);
            Highlight = highlight;

            _filter = filter;
            Title   = _filter != null ? _filter.Name : string.Empty;
            Model.Filters.Add(_filter);
        }
コード例 #5
0
        private async Task <StorageFile> SaveTemporaryPhotoAsync(FilteredPhotoModel photo)
        {
            var filename = Application.Current.Resources["PhotoSaveTemporaryFilename"] as string;
            var folder   = ApplicationData.Current.TemporaryFolder;

            if (filename != null)
            {
                var task = folder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting).AsTask();
                task.Wait();
                var file = task.Result;

                CachedFileManager.DeferUpdates(file);

                using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                    using (var photoStream = await photo.GetFilteredPhotoAsync())
                        using (var reader = new DataReader(photoStream))
                            using (var writer = new DataWriter(fileStream))
                            {
                                await reader.LoadAsync((uint)photoStream.Size);

                                var buffer = reader.ReadBuffer((uint)photoStream.Size);

                                writer.WriteBuffer(buffer);
                                await writer.StoreAsync();

                                await writer.FlushAsync();
                            }

                var status = await CachedFileManager.CompleteUpdatesAsync(file);

                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    return(file);
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }
コード例 #6
0
        public static async Task <StorageFile> SavePhotoAsync(FilteredPhotoModel photo)
        {
            var filenameFormat = new Windows.ApplicationModel.Resources.ResourceLoader().GetString("PhotoSaveFilenameFormat");
            var filename       = String.Format(filenameFormat, DateTime.Now.ToString("yyyyMMddHHmmss"));

            var picker = new FileSavePicker();

            picker.SuggestedFileName      = filename;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeChoices.Add(".jpg", new List <string>()
            {
                ".jpg"
            });

            var file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                file = await SavePhotoAsync(photo, file);
            }

            return(file);
        }
コード例 #7
0
        public StreamPageViewModel(HighlightStrategy highlightStrategy)
        {
            HighlightStrategy = highlightStrategy;

            Thumbnails = new ThumbnailCollection();

            GoBackCommand = CommandFactory.CreateGoBackCommand();

            SelectPhotoCommand = new DelegateCommand((parameter) =>
            {
                var viewModel = (ThumbnailViewModel)parameter;

                try
                {
                    var copy = new FilteredPhotoModel(viewModel.Model);

                    SessionModel.Instance.Photo = copy;

                    var frame = (Frame)Window.Current.Content;
                    frame.Navigate(typeof(PhotoPage));
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("SelectPhotoCommand failed: " + ex.Message + '\n' + ex.StackTrace);
                }
            });

#if WINDOWS_PHONE_APP
            OpenPhotoCommand = new DelegateCommand(
                (parameter) =>
            {
                StartOpenPhotoFile();
            });
#else
            OpenPhotoCommand = new DelegateCommand(
                async(parameter) =>
            {
                var file = await PickPhotoFileAsync();

                if (file != null)
                {
                    SessionModel.Instance.Photo = new FilteredPhotoModel(file);

                    var frame = (Frame)Window.Current.Content;
                    frame.Navigate(typeof(PhotoPage));
                }
            });
#endif

#if WINDOWS_PHONE_APP
            OpenFolderCommand = new DelegateCommand(
                (parameter) =>
            {
                StartOpenPhotoFolder();
            });
#else
            OpenFolderCommand = new DelegateCommand(
                async(parameter) =>
            {
                var folder = await PickPhotoFolderAsync();

                if (folder != null && (SessionModel.Instance.Folder == null || folder.Path != SessionModel.Instance.Folder.Path))
                {
                    SessionModel.Instance.Folder = folder;

                    await Refresh();
                }
            });
#endif

#if !WINDOWS_PHONE_APP
            CapturePhotoCommand = new DelegateCommand(
                async(parameter) =>
            {
                var file = await CapturePhotoFileAsync();

                if (file != null)
                {
                    SessionModel.Instance.Photo = new FilteredPhotoModel(file);

                    var frame = (Frame)Window.Current.Content;
                    frame.Navigate(typeof(PhotoPage));
                }
            });
#endif

#if WINDOWS_PHONE_APP
            ShowAboutCommand = new DelegateCommand((parameter) =>
            {
                var frame = (Frame)Window.Current.Content;
                frame.Navigate(typeof(AboutPage));
            });
#endif

            RefreshPhotosCommand = new DelegateCommand(
                async(parameter) =>
            {
                await Refresh();
            },
                () =>
            {
                return(!Processing);
            });

            RefreshSomePhotosCommand = new DelegateCommand(
                (parameter) =>
            {
                RefreshSome();
            },
                () =>
            {
                return(!Processing);
            });

            ChangeHighlightStrategyCommand = new DelegateCommand(
                async(parameter) =>
            {
                HighlightStrategy = parameter as HighlightStrategy;

                await Refresh();
            },
                () =>
            {
                return(!Processing);
            });
        }