public void Dispose() { if (_storageClient != null) { _storageClient.Dispose(); } }
/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public string FunctionHandler(JsonElement json, ILambdaContext context) { try { string bodyEncoded = json.GetProperty("body").ToString(); string body = ""; try { body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyEncoded)); } catch (Exception) { body = bodyEncoded; } var request = JsonSerializer.Deserialize <LambdaRequest>(body); byte[] bytes = Convert.FromBase64String(request.ImagemBase64); Image im = Image.FromBytes(bytes); var result = visionClient.AnalyzeImage(im, Constants.DEFAULT_MIN_CONFIDENCE); result.TotemID = request.TotemID; result.NumeroImagem = request.NumeroImagem; if (result.Sucesso) { var storageClient = new StorageClient(request.TotemID); var resp = storageClient.SaveImage(bytes, string.Format("{0}.jpeg", request.NumeroImagem)); if (!resp.Success) { result.Sucesso = false; result.Descricao = "Não foi possível salvar a imagem no repositório." + resp.Description; } else { result.Sucesso = true; result.MediaLink = resp.Description; result.Descricao = "Imagem OK - salva no repositório."; } try { storageClient.Dispose(); } catch (Exception) { } } return(JsonSerializer.Serialize(result)); } catch (Exception e) { return(string.Format("JSON: {0} \n\n EXCEPTION: {1}", json.ToString(), e.ToString())); } }
public void Dispose() { _client.DeleteBucket(BucketName, new DeleteBucketOptions { DeleteObjects = true }); _client.Dispose(); DeleteGlossary.DeleteGlossarySample(ProjectId, GlossaryId); }
public Material Transcribe(string fnAudio, string langCode) { // Keep storage client for full operation; will be removing file at the end StorageClient sc = null; Bucket bucket = null; try { sc = StorageClient.Create(GoogleCredential.FromFile(fnCredential)); // Get out bucket, create on demand var buckets = sc.ListBuckets(projectId); foreach (var x in buckets) { if (x.Name == bucketName) { bucket = x; } } if (bucket == null) { bucket = sc.CreateBucket(projectId, bucketName); } // Kill all existing objects var objs = sc.ListObjects(bucketName); foreach (var x in objs) { sc.DeleteObject(x); } // Upload the damned thing using (var f = File.OpenRead(fnAudio)) { sc.UploadObject(bucketName, objName, null, f); } // NOW RECOGNIZE var mat = transcribeFromObject("gs://" + bucketName + "/" + objName, langCode); return(mat); } finally { // Delete all objects in bucket if (bucket != null) { var objs = sc.ListObjects(bucketName); foreach (var x in objs) { sc.DeleteObject(x); } } // Adios storage jerk if (sc != null) { sc.Dispose(); } } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { _storageClient.Dispose(); } disposedValue = true; } }
protected override void Dispose(bool dispose) { lock (this) { if (_Client != null) { try { _Client.Dispose(); } catch { } } _Client = null; } }
public void Dispose() { _client?.Dispose(); }
public void Dispose() { _storageClient.Dispose(); }
protected override void DisposeStorageClient() { _storageClient?.Dispose(); _storageClient = null; }