public async Task AddObjectToUploadQueueAsync(string bucketName, string key, string accessGrant, Stream stream, string identifier, CustomMetadata customMetadata) { await InitAsync().ConfigureAwait(false); var entry = new UploadQueueEntry(); entry.AccessGrant = accessGrant; entry.Identifier = identifier; entry.BucketName = bucketName; entry.Key = key; entry.TotalBytes = (int)stream.Length; entry.BytesCompleted = 0; if (customMetadata != null) { entry.CustomMetadataJson = JsonSerializer.Serialize(customMetadata); } var entryData = new UploadQueueEntryData(); entryData.Bytes = new byte[stream.Length]; stream.Read(entryData.Bytes, 0, (int)stream.Length); await _connection.RunInTransactionAsync((SQLiteConnection transaction) => { transaction.Insert(entry); entryData.UploadQueueEntryId = entry.Id; transaction.Insert(entryData); }); ProcessQueueInBackground(); UploadQueueChangedEvent?.Invoke(QueueChangeType.EntryAdded, entry); }
async public Task <bool> AddCustomMetadataAsync(string name, string metadata) { var customMeta = new CustomMetadata() { Metadata = metadata }; HttpContent postContent = new StringContent( JsonSerializer.Serialize(customMeta), Encoding.UTF8, "application/json"); using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"{ _serverUrl }/lucene/addmeta/{ _indexName }?name={ name }")) { ModifyHttpRequest(requestMessage); requestMessage.Content = postContent; using (var httpResponse = await _httpClient.SendAsync(requestMessage)) { var apiResult = await httpResponse.DeserializeFromSuccessResponse <ApiResult>(); return(apiResult.Success); } } }
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); }
async public Task <IApiResult> AddMeta(string id, string name, [FromBody] CustomMetadata metaData) { return(await SecureMethodHandler(id, (id) => { return Task.FromResult <IApiResult>(new ApiResult( _lucene.AddCustomMetadata(id, name, metaData.Metadata) )); })); }
public static Error upload_set_custom_metadata(Upload p0, CustomMetadata p1) { global::System.IntPtr cPtr = storj_uplinkPINVOKE.upload_set_custom_metadata(Upload.getCPtr(p0), CustomMetadata.getCPtr(p1)); Error ret = (cPtr == global::System.IntPtr.Zero) ? null : new Error(cPtr, false); if (storj_uplinkPINVOKE.SWIGPendingException.Pending) { throw storj_uplinkPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public async Task <List <string> > GetByCustomMetadata(CustomMetadata metadata) { var giphy = new Giphy(_apiKey); var searchParameter = new SearchParameter() { Query = metadata.Query }; // Returns gif results var gifResult = await giphy.GifSearch(searchParameter); return(gifResult.Data.Select(data => data.Url).ToList()); }
public async Task <IActionResult> FetchGifsByMetadata([FromBody] CustomMetadata metadata) { try { var urls = await _fetchingManager.GetByCustomMetadata(metadata); return(Ok(JsonConvert.SerializeObject(urls))); } catch (Exception e) { _logger.Log(LogLevel.Error, e.ToString()); return(BadRequest("failed to fetch gifs by metadata")); } }
public async Task UpdateCustomMetaData_Works() { string bucketname = "update-custom-metadata-works"; await _bucketService.CreateBucketAsync(bucketname); var bucket = await _bucketService.GetBucketAsync(bucketname); byte[] bytesToUpload = GetRandomBytes(2048); CustomMetadata customMetadata = new CustomMetadata(); customMetadata.Entries.Add(new CustomMetadataEntry() { Key = "my-key 1a", Value = "my-value 1a" }); customMetadata.Entries.Add(new CustomMetadataEntry() { Key = "my-key 2a", Value = "my-value 2a" }); var uploadOperation = await _objectService.UploadObjectAsync(bucket, "myfile1.txt", new UploadOptions(), bytesToUpload, customMetadata, false); await uploadOperation.StartUploadAsync(); CustomMetadata customMetadataUpdated = new CustomMetadata(); customMetadataUpdated.Entries.Add(new CustomMetadataEntry() { Key = "my-key 1b", Value = "my-value 1b" }); customMetadataUpdated.Entries.Add(new CustomMetadataEntry() { Key = "my-key 2b", Value = "my-value 2b" }); await _objectService.UpdateObjectMetadataAsync(bucket, "myfile1.txt", customMetadataUpdated); var stat = await _objectService.GetObjectAsync(bucket, "myfile1.txt"); var objectList = await _objectService.ListObjectsAsync(bucket, new ListObjectsOptions()); Assert.AreEqual(1, objectList.Items.Count); Assert.AreEqual(2, stat.CustomMetadata.Entries.Count); Assert.AreEqual("my-key 1b", stat.CustomMetadata.Entries[0].Key); Assert.AreEqual("my-value 1b", stat.CustomMetadata.Entries[0].Value); Assert.AreEqual("my-key 2b", stat.CustomMetadata.Entries[1].Key); Assert.AreEqual("my-value 2b", stat.CustomMetadata.Entries[1].Value); }
public async Task PutAsync(string remotename, Stream stream, CancellationToken cancelToken) { var bucket = await _bucketService.EnsureBucketAsync(_bucket); CustomMetadata custom = new CustomMetadata(); custom.Entries.Add(new CustomMetadataEntry { Key = TardigradeFile.TARDIGRADE_LAST_ACCESS, Value = DateTime.Now.ToUniversalTime().ToString("O") }); custom.Entries.Add(new CustomMetadataEntry { Key = TardigradeFile.TARDIGRADE_LAST_MODIFICATION, Value = DateTime.Now.ToUniversalTime().ToString("O") }); var upload = await _objectService.UploadObjectAsync(bucket, GetBasePath() + remotename, new UploadOptions(), stream, custom, false); await upload.StartUploadAsync(); }
private async Task Upload_X_BytesFromStreamWithMetadata(long bytes) { string bucketname = "uploadqueuetestwithmetadata"; await ((UploadQueueService)_uploadQueueService).ClearAllPendingUploadsAsync(); await _bucketService.CreateBucketAsync(bucketname); var bucket = await _bucketService.GetBucketAsync(bucketname); byte[] bytesToUpload1 = GetRandomBytes(bytes); byte[] bytesToUpload2 = GetRandomBytes(bytes * 2); var mstream1 = new MemoryStream(bytesToUpload1); var mstream2 = new MemoryStream(bytesToUpload2); var customMetadata1 = new CustomMetadata(); customMetadata1.Entries.Add(new CustomMetadataEntry { Key = "META1KEY", Value = "meta1value" }); var customMetadata2 = new CustomMetadata(); customMetadata2.Entries.Add(new CustomMetadataEntry { Key = "META2KEY", Value = "meta2value" }); await _uploadQueueService.AddObjectToUploadQueueAsync(bucketname, "myqueuefile1.txt", _access.Serialize(), mstream1, "file1", customMetadata1); await _uploadQueueService.AddObjectToUploadQueueAsync(bucketname, "myqueuefile2.txt", _access.Serialize(), mstream2, "file2", customMetadata2); _uploadQueueService.ProcessQueueInBackground(); while (_uploadQueueService.UploadInProgress) await Task.Delay(100); _uploadQueueService.StopQueueInBackground(); var download1 = await _objectService.DownloadObjectAsync(bucket, "myqueuefile1.txt", new DownloadOptions(), false); await download1.StartDownloadAsync(); Assert.IsTrue(download1.Completed); Assert.AreEqual(bytesToUpload1.Count(), download1.BytesReceived); var object1 = await _objectService.GetObjectAsync(bucket, "myqueuefile1.txt"); Assert.AreEqual("META1KEY", object1.CustomMetadata.Entries[0].Key); Assert.AreEqual("meta1value", object1.CustomMetadata.Entries[0].Value); var download2 = await _objectService.DownloadObjectAsync(bucket, "myqueuefile2.txt", new DownloadOptions(), false); await download2.StartDownloadAsync(); Assert.IsTrue(download2.Completed); Assert.AreEqual(bytesToUpload2.Count(), download2.BytesReceived); var object2 = await _objectService.GetObjectAsync(bucket, "myqueuefile2.txt"); Assert.AreEqual("META2KEY", object2.CustomMetadata.Entries[0].Key); Assert.AreEqual("meta2value", object2.CustomMetadata.Entries[0].Value); }
private Message CreateMessageWithObects() { CustomMetadata metadata = new CustomMetadata() { MyProperty = 1, Info = "My info" }; MyMessage messgae = new MyMessage() { intProperty = 99, strProperty = "message body" }; return(new Message() { Channel = "Sample.test1", Metadata = metadata.ToString(), Body = messgae.ToByteArray() }); }
public async Task <Response> GetByCustomMetadata(CustomMetadata metadata) { if (_cashingMechanism.HasCashedSearchResultByQuery(metadata.Query)) { _logger.LogDebug("Getting from cash"); return(new Response { Urls = _cashingMechanism.GetCashedSearchResultByQuery(metadata.Query), Key = metadata.Query }); } _logger.LogDebug("Getting from cash"); var urls = await _fetchingService.GetByCustomMetadata(metadata);; _cashingMechanism.CashSearchResult(urls, metadata.Query); return(new Response { Urls = urls, Key = metadata.Query }); }
private Request CreateRequestWithObjects(int i) { CustomMetadata metadata = new CustomMetadata() { MyProperty = i, Info = "My info" }; MyMessage messgae = new MyMessage() { intProperty = i, strProperty = $"Request {i}" }; return(new Request() { Channel = "MyChannel.SimpleRequest", Metadata = metadata.ToString(), Body = messgae.ToByteArray(), Timeout = 5000, CacheKey = "key_" + i, CacheTTL = 5000 // Millisecond }); }
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); }
public async Task UpdateObjectMetadataAsync(Bucket bucket, string targetPath, CustomMetadata metadata) { await UploadOperation.customMetadataSemaphore.WaitAsync(); try { metadata.ToSWIG(); //Appends the customMetadata in the go-layer to a global field using (var options = new SWIG.UplinkUploadObjectMetadataOptions()) using (SWIG.UplinkError error = await Task.Run(() => SWIG.storj_uplink.uplink_update_object_metadata2(_access._project, bucket.Name, targetPath, options)).ConfigureAwait(false)) { if (error != null && !string.IsNullOrEmpty(error.message)) { throw new CouldNotUpdateObjectMetadataException(error.message); } } } finally { UploadOperation.customMetadataSemaphore.Release(); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CustomMetadata obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public async Task <UploadOperation> UploadObjectAsync(Bucket bucket, string targetPath, UploadOptions uploadOptions, Stream stream, CustomMetadata customMetadata, bool immediateStart) { var uploadOptionsSWIG = uploadOptions.ToSWIG(); _uploadOptions.Add(uploadOptionsSWIG); using (SWIG.UplinkUploadResult uploadResult = await Task.Run(() => SWIG.storj_uplink.uplink_upload_object(_access._project, bucket.Name, targetPath, uploadOptionsSWIG)).ConfigureAwait(false)) { UploadOperation upload = new UploadOperation(stream, uploadResult, targetPath, customMetadata); if (immediateStart) { upload.StartUploadAsync(); //Don't await it, otherwise it would "block" UploadObjectAsync } return(upload); } }
public async Task AddObjectToUploadQueueAsync(string bucketName, string key, string accessGrant, byte[] objectData, string identifier, CustomMetadata customMetadata) { await AddObjectToUploadQueueAsync(bucketName, key, accessGrant, new MemoryStream(objectData), identifier, null).ConfigureAwait(false); }
public async Task <ChunkedUploadOperation> UploadObjectChunkedAsync(Bucket bucket, string targetPath, UploadOptions uploadOptions, CustomMetadata customMetadata) { var uploadOptionsSWIG = uploadOptions.ToSWIG(); SWIG.UploadResult uploadResult = await Task.Run(() => SWIG.storj_uplink.upload_object(_access._project, bucket.Name, targetPath, uploadOptionsSWIG)); ChunkedUploadOperation upload = new ChunkedUploadOperation(uploadResult, targetPath, customMetadata); return(upload); }
public async Task <UploadOperation> UploadObjectAsync(Bucket bucket, string targetPath, UploadOptions uploadOptions, byte[] bytesToUpload, CustomMetadata customMetadata, bool immediateStart = true) { var uploadOptionsSWIG = uploadOptions.ToSWIG(); SWIG.UploadResult uploadResult = await Task.Run(() => SWIG.storj_uplink.upload_object(_access._project, bucket.Name, targetPath, uploadOptionsSWIG)); UploadOperation upload = new UploadOperation(bytesToUpload, uploadResult, targetPath, customMetadata); if (immediateStart) { upload.StartUploadAsync(); //Don't await it, otherwise it would "block" UploadObjectAsync } return(upload); }
public async Task <UploadOperation> UploadObjectAsync(Bucket bucket, string targetPath, UploadOptions uploadOptions, byte[] bytesToUpload, CustomMetadata customMetadata) { return(await UploadObjectAsync(bucket, targetPath, uploadOptions, bytesToUpload, customMetadata, true).ConfigureAwait(false)); }
private static Guid SendDocument(EAAuth tokenClient, bool isDevelopment, FileInfo fi, string Naziv, string Koda, string NazivDobavitelja, string SifraDobavitelja, string DavcnaStevilkaDobavitelja, string StevilkaRacuna, DateTime DatumIzdajeRacuna, int Leto, string Node) { var client = GetClient(tokenClient, isDevelopment); var token = tokenClient.GetBearerToken(); var nodes = client.GetAllNodes(token); var node = nodes.Where(n => n.Code == Node).FirstOrDefault(); if (node == null) { throw new Exception("didn't find node using Node parameter"); } var metas = client.GetCustomMetadataTypes(tokenClient.GetBearerToken()); var aMetadata = new Metadata(); aMetadata.NodeGuid = node.NodeGuid; aMetadata.FileName = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length); aMetadata.FileExtension = fi.Extension; aMetadata.DigitalSignatureType = PS.EA.SDK.Enums.DigitalSignatureType.None; aMetadata.CreatedDate = DatumIzdajeRacuna; aMetadata.Title = Koda; aMetadata.Code = Koda; aMetadata.Receiver = NazivDobavitelja; aMetadata.CustomMetadatas = new List <CustomMetadata>(); foreach (var md in metas) { CustomMetadata aMd = null; if (md.Label == "Šifra partnerja") { aMd = new CustomMetadata { CustomMetadataType = new CustomMetadataType { CustomMetadataTypeGuid = md.CustomMetadataTypeGuid }, Value = SifraDobavitelja }; } if (md.Label == "Davčna številka partnerja") { aMd = new CustomMetadata { CustomMetadataType = new CustomMetadataType { CustomMetadataTypeGuid = md.CustomMetadataTypeGuid }, Value = DavcnaStevilkaDobavitelja }; } if (md.Label == "Številka računa") { aMd = new CustomMetadata { CustomMetadataType = new CustomMetadataType { CustomMetadataTypeGuid = md.CustomMetadataTypeGuid }, Value = StevilkaRacuna }; } if (md.Label == "Datum izdaje računa") { aMd = new CustomMetadata { CustomMetadataType = new CustomMetadataType { CustomMetadataTypeGuid = md.CustomMetadataTypeGuid }, Value = DatumIzdajeRacuna.ToString("yyyy-MM-ddThh:mm:ss") }; } if (md.Label == "Leto") { aMd = new CustomMetadata { CustomMetadataType = new CustomMetadataType { CustomMetadataTypeGuid = md.CustomMetadataTypeGuid }, Value = Leto.ToString() }; } if (aMd != null) { aMetadata.CustomMetadatas.Add(aMd); } } byte[] bytes = File.ReadAllBytes(fi.FullName); return(client.AddDocument(token, bytes, aMetadata)); }