コード例 #1
0
 public void Dispose()
 {
     if (_storageClient != null)
     {
         _storageClient.Dispose();
     }
 }
コード例 #2
0
        /// <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()));
            }
        }
コード例 #3
0
 public void Dispose()
 {
     _client.DeleteBucket(BucketName,
                          new DeleteBucketOptions
     {
         DeleteObjects = true
     });
     _client.Dispose();
     DeleteGlossary.DeleteGlossarySample(ProjectId, GlossaryId);
 }
コード例 #4
0
        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();
                }
            }
        }
コード例 #5
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _storageClient.Dispose();
                }

                disposedValue = true;
            }
        }
コード例 #6
0
        protected override void Dispose(bool dispose)
        {
            lock (this)
            {
                if (_Client != null)
                {
                    try
                    {
                        _Client.Dispose();
                    }
                    catch { }
                }

                _Client = null;
            }
        }
コード例 #7
0
 public void Dispose()
 {
     _client?.Dispose();
 }
コード例 #8
0
 public void Dispose()
 {
     _storageClient.Dispose();
 }
コード例 #9
0
 protected override void DisposeStorageClient()
 {
     _storageClient?.Dispose();
     _storageClient = null;
 }