public InitializeAsync ( ) : System.Threading.Tasks.Task | ||
리턴 | System.Threading.Tasks.Task |
private async void Model_AddedNew(object sender, Csla.Core.AddedNewEventArgs <FileReference> e) { if (IsAdding) { return; } IsAdding = true; var newItem = e.NewObject; var destinationDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var fileName = GenerateUniqueFileNameFor(destinationDirectory); PrepareToShowModal(); var fullFileName = await DependencyService.Get <IPhotoPicker>().GetCopiedFilePath(destinationDirectory, fileName); if (fullFileName == null) { if (newItem != null) { Model.Remove(newItem); } return; } newItem.FileName = fullFileName; var photoVM = new PhotoViewModel(newItem); await photoVM.InitializeAsync(); PhotoViewModels.Add(photoVM); IsAdding = false; }
public Photos(FileReferenceList fileReferenceList) { IsAdding = false; Model = fileReferenceList; _choosePhotoCommand = new Command(ChoosePhoto); _deletePhotoCommand = new Command(async obj => { var photoVM = (PhotoViewModel)obj; PhotoViewModels.Remove(photoVM); var fileRef = photoVM.FileReference; Model.Remove(fileRef); var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var fullPath = Path.Combine(documentsPath, fileRef.FileName); if (File.Exists(fullPath)) { await Task.Run(() => File.Delete(fullPath)); } }); Model.AddedNew += async(o, e) => { if (IsAdding) { return; } IsAdding = true; var newItem = e.NewObject; var destinationDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var fileName = GenerateUniqueFileNameFor(destinationDirectory); PrepareToShowModal(); var fullFileName = await DependencyService.Get <IPhotoPicker>().GetCopiedFilePath(destinationDirectory, fileName); if (fullFileName == null) { if (newItem != null) { Model.Remove(newItem); } return; } newItem.FileName = fullFileName; var photoVM = new PhotoViewModel(newItem); await photoVM.InitializeAsync(); PhotoViewModels.Add(photoVM); IsAdding = false; }; PhotoViewModels = new ObservableCollection <PhotoViewModel>(); }
private void ChoosePhoto() { Model.AddedNew += (async(o, e) => { var newItem = e.NewObject; var rootFolder = FileSystem.Current.LocalStorage; var fileName = await GenerateUniqueFileNameFor(FileSystem.Current.LocalStorage); var path = await DependencyService.Get <IPhotoPicker>().GetCopiedFilePath(rootFolder.Path, fileName); if (path == null) { Model.Remove(newItem); return; } newItem.FileName = path; var photoVM = new PhotoViewModel(newItem); await photoVM.InitializeAsync(); PhotoViewModels.Add(photoVM); }); BeginAddNew(); }