Esempio n. 1
0
        public static async Task <S3GetFileResponse> GetFile(S3GetFileRequest request)
        {
            LambdaLogger.Log($"Entering: GetFile({JsonConvert.SerializeObject(request)}");

            S3GetFileResponse response = new S3GetFileResponse
            {
                FilePath    = request.FilePath,
                IsSuccess   = true,
                FileContent = string.Empty
            };

            try
            {
                GetObjectRequest S3Request = new GetObjectRequest
                {
                    BucketName = S3Constants.BUCKET_NAME,
                    Key        = request.FilePath
                };

                GetObjectResponse S3Response = await S3Client.GetObjectAsync(S3Request);

                if (S3Response.HttpStatusCode != System.Net.HttpStatusCode.OK)
                {
                    response.IsSuccess    = false;
                    response.ErrorMessage = string.Format("Status Code: {0}", S3Response.HttpStatusCode);
                }
                else
                {
                    response.FilePath = S3Response.Key;
                    using (StreamReader reader = new StreamReader(S3Response.ResponseStream))
                    {
                        response.FileContent = reader.ReadToEnd();
                    }
                }
            }
            catch (Exception exp)
            {
                LambdaLogger.Log($"Error: {exp}");

                response.IsSuccess    = false;
                response.ErrorMessage = string.Format("Error: {0}", exp.Message);
            }

            LambdaLogger.Log($"Leaving: GetFile({JsonConvert.SerializeObject(response)})");

            return(response);
        }
Esempio n. 2
0
        public async Task <string> GetToken()
        {
            LambdaLogger.Log($"Entering: GetToken()");

            string response = string.Empty;

            try
            {
                S3GetFileResponse S3Response = await S3Helper.GetFile(new S3GetFileRequest
                {
                    FilePath = MTGServiceConstants.AuthenticateJsonFilepath
                });

                if (S3Response.IsSuccess)
                {
                    if (string.IsNullOrEmpty(S3Response.FileContent))
                    {
                        throw new Exception("S3 Response content is null or empty! ya bish!");
                    }

                    AuthenticateDto authenticateDto = JsonConvert.DeserializeObject <AuthenticateDto>(S3Response.FileContent);

                    if (authenticateDto == null)
                    {
                        throw new Exception("S3 Authenticate response content could not be deserialized!");
                    }

                    response = authenticateDto.AccessToken;
                }
            }
            catch (Exception exp)
            {
                LambdaLogger.Log($"Error: {exp}");
                throw;
            }

            LambdaLogger.Log($"Leaving: GetToken({response})");

            return(response);
        }