private async void DeleteFavButton_Click(object sender, RoutedEventArgs e) { if (toto != null && _ifavItems.Count > 0) { foreach (var ifavItem in _ifavItems) { if (ifavItem.IdPhoto == toto.IdPhoto) { _ifavItems.Clear(); _items.Clear(); break; } } var result_del = await flickr.DeleteFav(toto.IdPhoto); if (result_del == "ok") { res = await flickr.GetPublicFav(); AdaptiveGridViewControl.ItemsSource = await downloader.DownloadImageFlickr(res, null, _items, _ifavItems, IsFavButtonPressed); MessageDialog msg_ok = new MessageDialog("Votre photo a bien été supprimé des favoris"); await msg_ok.ShowAsync(); } else { MessageDialog msg_failure = new MessageDialog("La suppresion de l'une de vos photos faovrites a rencontrées un problèmes"); await msg_failure.ShowAsync(); } } }
private async void DeleteButton_Click(object sender, RoutedEventArgs e) { if (toto != null) { var is_delete = await flickr.deleteImageFlicr(toto.IdPhoto); if (is_delete == "ok") { var msg = new MessageDialog("Photo Supprimer"); await msg.ShowAsync(); } else { var msg = new MessageDialog("Un problème est survenu lors de la suppression"); await msg.ShowAsync(); return; } _items.Clear(); res = await flickr.GetPublicPhoto(); AdaptiveGridViewControl.ItemsSource = await downloader.DownloadImageFlickr(res, null, _items, _ifavItems, IsFavButtonPressed); } }
/// <summary> /// Log Flickr OnClick Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Flickr_Log_Click(object sender, RoutedEventArgs e) { if (IsLoggedFlickr) { var msg = new MessageDialog("Vous êtes déja Connecté"); await msg.ShowAsync(); } else { string output; flickr = new FlickrAuth(); var callback = new Uri("http://www.example.com/"); var FlickrUri = new Uri(await flickr.GetLonginLink()); try { var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync( WebAuthenticationOptions.None, FlickrUri, callback); if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { output = webAuthenticationResult.ResponseData; await flickr.GetAccessToken(output); await flickr.FlickrOAuthRequest(); res = await flickr.GetPublicPhoto(); AdaptiveGridViewControl.ItemsSource = await downloader.DownloadImageFlickr(res, null, _items, _ifavItems, IsFavButtonPressed); IsLoggedFlickr = true; makeButtonVisible(); } else if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) { output = "HTTP Error returned by AuthenticateAsync() : " + webAuthenticationResult.ResponseErrorDetail; } else if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.UserCancel) { output = "Authentication process was cancelled by the user"; } } catch (Exception exception) { var msg_dialog = new MessageDialog(exception.Message); await msg_dialog.ShowAsync(); } } }
private async void UploadButton_Click(object sender, RoutedEventArgs e) { // Permet de Pick une Image en générant // une boite de dialogue // /!\ Ne prenez pas des photos de vos images, Bureau etc.. // Prenez a aprtir du AppData/Local/Package/9f3d1843-4a64-4da7-a30f-c7fc1df2f7e8_nqw117v1ny6wy/LocalState // mettez vos photos dans ce dossier var picker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary }; picker.FileTypeFilter.Add(".jpg"); var file = await picker.PickSingleFileAsync(); if (file != null) { Stream fs = new FileStream(file.Path, FileMode.Open, FileAccess.Read); var fileName = Path.GetFileName(file.Path); if (IsLoggedFlickr) { var res_upload = await flickr.UploadPhotoFlickr(fs, fileName); if (res_upload == "ok") { res = await flickr.GetPublicPhoto(); _items.Clear(); AdaptiveGridViewControl.ItemsSource = await downloader.DownloadImageFlickr(res, null, _items, _ifavItems, IsFavButtonPressed); } } // Implémenter Upload pour ImGur } }
public async Task <ObservableCollection <MenuItem> > DownloadImageFlickr(FlickrAuth.RootObject root, object Imgur, ObservableCollection <MenuItem> items, ObservableCollection <MenuItem> _ifavItems, bool IsFavButtonPressed) { var ImageAlreadyExist = false; if (root.Stat == "ok") { foreach (var VARIABLE in root.Photos.Photo) { try { if (items.Count > 0) { foreach (var menuItem in items) { if (menuItem.IdPhoto == VARIABLE.Id) { var smg_dialog = new MessageDialog( "L'image que vous essayer d'avoir existe déja dans votre Gallerie."); await smg_dialog.ShowAsync(); ImageAlreadyExist = true; } else { ImageAlreadyExist = false; } } } if (ImageAlreadyExist) { continue; } var rootFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Epicture\\FlickrImages", CreationCollisionOption.OpenIfExists); var coverpic_file = await rootFolder.CreateFileAsync(VARIABLE.Title + ".jpg", CreationCollisionOption.OpenIfExists); var photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_n.jpg"; var baseFlickrURL = string.Format(photoUrl, VARIABLE.Farm, VARIABLE.Server, VARIABLE.Id, VARIABLE.Secret); var bitmapImage = new BitmapImage(new Uri(baseFlickrURL)) { DecodePixelHeight = 100, DecodePixelWidth = 100 }; try { var client = new HttpClient(); // Create HttpClient var buffer = await client.GetByteArrayAsync(baseFlickrURL); // Download file using (var stream = await coverpic_file.OpenStreamForWriteAsync()) { stream.Write(buffer, 0, buffer.Length); // Save } items.Add(new MenuItem { Name = coverpic_file.Path, IdPhoto = VARIABLE.Id }); if (IsFavButtonPressed) { _ifavItems.Add(new MenuItem { Name = coverpic_file.Path, IdPhoto = VARIABLE.Id }); } } catch (Exception e) { var failDialog = new MessageDialog("Download failure Images Flickr\n" + e.Message); await failDialog.ShowAsync(); } } catch (Exception e) { var failDialog = new MessageDialog(e.Message); await failDialog.ShowAsync(); } } } // Implémenter le Download Pour ImGur return(items); }