Beispiel #1
0
        private static void deleteUnusedFiles(Func <string, bool> matches)
        {
            var bucketName = Environment.GetEnvironmentVariable("S3_BUCKET_NAME");
            var S3Bucket   = new S3Bucket(bucketName);

            S3Bucket.fetchKeys();

            while (S3Bucket.moveNext())
            {
                var currentKey = S3Bucket.getCurrentKey();

                if (matches.Invoke(currentKey))
                {
                    var S3Object = new S3ObjectMetadata(bucketName, currentKey);
                    S3Object.remove();
                }
            }
        }
        private HttpResult deleteMetadata <Entity>(MetadataDto dto, string type) where Entity : Metadata, new()
        {
            var found = Db.Select <Entity>(e => e.OwnerId == GetCurrentAuthUserId() && e.Id == dto.Id);

            //TODO - transaction?
            if (found.Count != 0)
            {
                var inProgressTasks = Db.Select <Task>(entity => entity.Status == "in progres");

                if (found[0].CanDelete(inProgressTasks))
                {
                    Db.DeleteById <Entity>(dto.Id);

                    var S3Object = new S3ObjectMetadata(Environment.GetEnvironmentVariable("S3_BUCKET_NAME"), $"{GetCurrentAuthUserId()}-{type}-{dto.Id}");
                    S3Object.remove();
                }
            }

            return(new HttpResult(HttpStatusCode.NoContent, "No content"));
        }