Beispiel #1
0
        private async Task LeaveGym(Facility facilityView, ApplicationUser user, Facility facility, List <UsersInGymDetail> facilityDetails, UsersInGymDetail currentFacilityDetailDb)
        {
            user.IsInsideGym = false;
            // if it is not 0 then we can decrement to avoid negatives
            if (facility.NumberOfClientsInGym != 0)
            {
                facility.NumberOfClientsInGym--;
            }

            // adjust all variables to update the user to a left gym status
            if (user.WillUseWeightsRoom)
            {
                facility.NumberOfClientsUsingWeightRoom--;
                user.WillUseWeightsRoom = false;
            }
            if (user.WillUseCardioRoom && facility.NumberOfClientsUsingCardioRoom != 0)
            {
                facility.NumberOfClientsUsingCardioRoom--;
                user.WillUseCardioRoom = false;
            }
            if (user.WillUseStretchRoom && facility.NumberOfClientsUsingStretchRoom != 0)
            {
                facility.NumberOfClientsUsingStretchRoom--;
                user.WillUseWeightsRoom = false;
            }

            // if there are entries for facilities, loop through all the facilities, remove the entry which is stamped with the current user entry
            if (facilityDetails.Count() > 0)
            {
                _facilityContext.UsersInGymDetails.Remove(currentFacilityDetailDb);
            }

            facilityView.IsCameraScanSuccessful = false;
            user.IsWithin10m             = false;
            user.IsCameraScanSuccessful  = false;
            user.AccessGrantedToFacility = false;

            // delete detected image from S3 bucket
            try
            {
                string keyName = $"{user.FirstName}_{user.Id}.jpg";

                var deleteObjectRequest = new Amazon.S3.Model.DeleteObjectRequest
                {
                    BucketName = bucket,
                    Key        = keyName
                };

                await S3Client.DeleteObjectAsync(deleteObjectRequest);
            }
            catch (AmazonS3Exception e)
            {
                _logger.LogInformation(e.Message);
            }
            catch (Exception e)
            {
                _logger.LogInformation(e.Message);
            }
        }
Beispiel #2
0
        public Task DeleteAsync(string fullFileName, CancellationToken cancellationToken = default)
        {
            CheckDisposed();

            if (string.IsNullOrWhiteSpace(fullFileName))
            {
                throw new ArgumentNullException(nameof(fullFileName));
            }

            var request = new DeleteObjectRequest {
                BucketName = BucketName, Key = AdjustKey(fullFileName)
            };

            return(S3Client.DeleteObjectAsync(request, cancellationToken));
        }
Beispiel #3
0
        private async Task <(Guid, string)> ProcessS3File(S3Event evnt, ILambdaLogger logger)
        {
            var s3Event = evnt.Records?[0].S3;

            if (s3Event == null)
            {
                return(Guid.Empty, null);
            }

            try
            {
                if (!s3Event.Object.Key.Contains(Config.GetSection("RiskIdFilePrefix").Value))
                {
                    logger.LogLine($"File {s3Event.Object.Key} from bucket {s3Event.Bucket.Name} is not an valid file");
                    return(Guid.Empty, null);
                }

                var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key);

                Guid id = Guid.NewGuid();
                if (response != null)
                {
                    string fileName = $@"PendingProcessing/{Path.GetFileNameWithoutExtension(s3Event.Object.Key)}_{id}"
                                      + $"{Path.GetExtension(s3Event.Object.Key)}";

                    await S3Client.CopyObjectAsync(s3Event.Bucket.Name, s3Event.Object.Key, s3Event.Bucket.Name, fileName)
                    .ConfigureAwait(false);

                    await S3Client.DeleteObjectAsync(s3Event.Bucket.Name, s3Event.Object.Key).ConfigureAwait(false);

                    using (StreamReader reader = new StreamReader(
                               await S3Client.GetObjectStreamAsync(s3Event.Bucket.Name, fileName, null)))
                    {
                        var content = await reader.ReadToEndAsync();

                        return(id, content);
                    }
                }
            }
            catch (Exception e)
            {
                logger.LogLine(e.Message);
                logger.LogLine(e.StackTrace);
                throw;
            }

            return(Guid.Empty, null);
        }
        /// <summary>
        /// Deletes the content for the specified media.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="id">The unique id</param>
        public async Task <bool> DeleteAsync(string id)
        {
            var objectKey = Url.Combine(StorageOptions.KeyPrefix, id);

            try
            {
                await S3Client.DeleteObjectAsync(StorageOptions.BucketName, objectKey);

                Logger?.LogInformation($"Successfully deleted Piranha S3 Media {id}");
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #5
0
        public async Task Delete(string key)
        {
            var deleteRequest = new DeleteObjectRequest
            {
                BucketName = BucketName,
                Key        = key
            };

            try {
                DeleteObjectResponse response = await S3Client.DeleteObjectAsync(deleteRequest);

                Logger.LogInformation($"Deleted object {key} from bucket {BucketName}. Request Id: {response.ResponseMetadata.RequestId}");
            }
            catch (AmazonS3Exception e) {
                Response.StatusCode = (int)e.StatusCode;
                var writer = new StreamWriter(Response.Body);
                writer.Write(e.Message);
            }
        }
Beispiel #6
0
        public static async Task <bool> DeleteFile(string FileId)
        {
            try
            {
                DeleteObjectRequest request = new DeleteObjectRequest();
                request.BucketName = Config.S3BucketName;
                request.Key        = FileId;

                await S3Client.DeleteObjectAsync(request);

                return(true);
            }
            catch (Exception e)
            {
                if (Globals.Config.IsDebug)
                {
                    Console.WriteLine("[S3] " + e.ToString());
                }

                return(false);
            }
        }
Beispiel #7
0
 private static async Task <bool> DeleteObject(S3Client client, string bucketName, string objectName)
 {
     return((await client.DeleteObjectAsync(bucketName, objectName).ConfigureAwait(false)).IsSuccess);
 }