private async void PersonPicture_Click(object sender, RoutedEventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { return; } var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "NutzMich", Name = "ProfilFoto.jpg", PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium }); if (file == null) { return; } var fileRead = File.OpenRead(file.Path); _profilVM.Profil.ProfilbildBase64 = await _thumbnailHelper.ThumbnailToBase64Async(new Models.AttachmentImage(fileRead)); _profilVM.RefreshProfilbild(); }
public async Task <bool> SetProfilAsync(Profil profil, AttachmentImage image = null) { await InitWriteConnectionAsync(); profil.AnbieterID = _loginService.AnbieterId; if (image != null) { profil.ProfilbildBase64 = await _thumbnailHelper.ThumbnailToBase64Async(image); } profil.AktualisiertAm = DateTime.Now; var profilJSON = Newtonsoft.Json.JsonConvert.SerializeObject(profil); var profilJSONbytes = Encoding.UTF8.GetBytes(profilJSON); string key = "Profile/" + profil.AnbieterID + "/Profil.json"; var customMeta = new CustomMetadata(); customMeta.Entries.Add(new CustomMetadataEntry() { Key = PROFIL_VERSION_VOM, Value = DateTime.Now.ToString() }); var profilUpload = await _writeConnection.ObjectService.UploadObjectAsync(_writeConnection.Bucket, key, new UploadOptions(), profilJSONbytes, customMeta, false); await profilUpload.StartUploadAsync(); Barrel.Current.Empty("profil_" + profil.AnbieterID); return(profilUpload.Completed); }
public async Task <bool> SaveAngebotAsync(Angebot angebot, List <AttachmentImage> images, bool angebotAktiv = true) { await InitWriteConnectionAsync(); angebot.EingestelltAm = DateTime.Now; angebot.AnbieterId = _loginService.AnbieterId; if (images.Count > 0) { angebot.ThumbnailBase64 = await _thumbnailHelper.ThumbnailToBase64Async(images.First()); } if (string.IsNullOrEmpty(angebot.NachrichtenAccess)) { angebot.NachrichtenAccess = _identityService.CreatePartialWriteAccess("Nachrichten/" + _loginService.AnbieterId + "/" + angebot.Id + "/"); } var angebotJSON = Newtonsoft.Json.JsonConvert.SerializeObject(angebot); var angebotJSONbytes = Encoding.UTF8.GetBytes(angebotJSON); string key = "Angebote/" + _loginService.AnbieterId + "/" + angebot.Id.ToString(); var customMeta = new CustomMetadata(); if (angebotAktiv) { customMeta.Entries.Add(new CustomMetadataEntry() { Key = ANGEBOTSSTAUS, Value = ANGEBOT_AKTIV }); } else { customMeta.Entries.Add(new CustomMetadataEntry() { Key = ANGEBOTSSTAUS, Value = ANGEBOT_INAKTIV }); } customMeta.Entries.Add(new CustomMetadataEntry() { Key = ANGEBOT_VERSION_VOM, Value = DateTime.Now.ToString() }); var angebotUpload = await _writeConnection.ObjectService.UploadObjectAsync(_writeConnection.Bucket, key, new UploadOptions(), angebotJSONbytes, customMeta, false); await angebotUpload.StartUploadAsync(); int count = 1; foreach (var image in images) { string fotoKey = "Fotos/" + _loginService.AnbieterId + "/" + angebot.Id.ToString() + "/" + count; //Prüfen, ob das hochzuladende Bild schon existiert try { var existingObject = await _writeConnection.ObjectService.GetObjectAsync(_writeConnection.Bucket, fotoKey); //Es existiert - wenn die Dateigröße gleich ist, dann nicht nochmal hochladen if (existingObject.SystemMetaData.ContentLength == image.Stream.Length) { count++; continue; } } catch { } //Dann existiert es noch nicht image.Stream.Position = 0; var queue = new uplink.NET.Services.UploadQueueService(); await queue.AddObjectToUploadQueue(_writeConnection.Bucket.Name, fotoKey, _identityService.GetIdentityWriteAccess().Serialize(), image.Stream.ToMemoryStream().ToArray(), angebot.Ueberschrift + " - Bild " + count.ToString()); queue.ProcessQueueInBackground(); //var imageUpload = await _writeConnection.ObjectService.UploadObjectAsync(_writeConnection.Bucket, fotoKey, new UploadOptions(), image.Stream, false); //await imageUpload.StartUploadAsync(); count++; image.Stream.Position = 0; Barrel.Current.Add <byte[]>(fotoKey, image.Stream.ToMemoryStream().ToArray(), TimeSpan.FromDays(365)); } while (true) { string fotoKey = "Fotos/" + _loginService.AnbieterId + "/" + angebot.Id.ToString() + "/" + count; try { var existingObject = await _writeConnection.ObjectService.GetObjectAsync(_writeConnection.Bucket, fotoKey); //Es existiert - lösche es - alle gewünschten Bilder sind schon oben await _writeConnection.ObjectService.DeleteObjectAsync(_writeConnection.Bucket, fotoKey); count++; } catch { //Es gibt nicht mehr Bilder, alles bereinigt break; } } Barrel.Current.Add <Angebot>("angebot_" + key.Replace("Angebote/", ""), angebot, TimeSpan.FromDays(180)); return(angebotUpload.Completed); }