Ejemplo n.º 1
0
        public override Task <IBlobMetadata> FetchMetadataAsync(string virtualPath, NameValueCollection queryString)
        {
            LogFileAppender($"DEBUG :: Trying to get meta data for virtualPath {virtualPath}");
            try
            {
                LogFileAppender($"DEBUG :: Trying to get meta data for virtualPath {virtualPath}");
                var data   = GetDataFromAPI(virtualPath, true);
                var result = new BlobMetadata {
                    Exists = data.RowCount == "1"
                };
                if (result.Exists.Value)
                {
                    result.LastModifiedDateUtc = DateTime.Parse(data.Rows.Row.Values.Value.Text);
                }

                return(Task.FromResult <IBlobMetadata>(result));
            }
            catch (Exception e)
            {
                LogFileAppender($"ERROR :: Something went wrong when trying to fetch metadata, {e}");
                return(Task.FromResult <IBlobMetadata>(new BlobMetadata {
                    Exists = false
                }));
            }
        }
Ejemplo n.º 2
0
        public override async Task <IBlobMetadata> FetchMetadataAsync(string virtualPath, NameValueCollection queryString)
        {
            try
            {
                var cloudBlob = await GetBlobRefAsync(virtualPath);

                var meta = new BlobMetadata {
                    Exists = true
                };

                var utc = cloudBlob.Properties.LastModified;
                if (utc != null)
                {
                    meta.LastModifiedDateUtc = utc.Value.UtcDateTime;
                }

                return(meta);
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 404)
                {
                    return(new BlobMetadata {
                        Exists = false
                    });
                }

                throw;
            }
        }
Ejemplo n.º 3
0
        public static async Task DeleteBlobAsync(BlobMetadata blobMetadata, ILogger log)
        {
            log.LogInformation($"Delete queue process item: {blobMetadata}");

            string containerEndpoint = string.Format("https://{0}.blob.core.windows.net/{1}", Common.GetEnvironmentVariable("SA_NAME"), blobMetadata.ContainerName);

            var blobPathAndName = $"{blobMetadata.BlobPath}/{blobMetadata.BlobName}";

            BlobContainerClient sourceBlobContainerClient = new BlobContainerClient(new Uri(containerEndpoint), new DefaultAzureCredential());

            try
            {
                if (await sourceBlobContainerClient.ExistsAsync())
                {
                    BlobClient blob = sourceBlobContainerClient.GetBlobClient(blobPathAndName);

                    if (await blob.ExistsAsync())
                    {
                        await blob.DeleteAsync();

                        log.LogInformation($"Blob {blobMetadata.BlobName} is deleted");
                    }
                }
            }
            catch (RequestFailedException)
            {
                log.LogInformation($"Failed to complete blob deleting operation: {blobMetadata}");
                throw;
            }
        }
Ejemplo n.º 4
0
 public PackagesContainerConsistencyReport(
     bool isConsistent,
     BlobMetadata packageContentMetadata)
 {
     IsConsistent           = isConsistent;
     PackageContentMetadata = packageContentMetadata;
 }
Ejemplo n.º 5
0
        static void BlobMetadata()
        {
            BlobMetadata md = _Blobs.GetMetadata(InputString("Key:", null, false)).Result;

            Console.WriteLine("");
            Console.WriteLine(md.ToString());
        }
Ejemplo n.º 6
0
 public FlatContainerConsistencyReport(
     bool isConsistent,
     BlobMetadata packageContentMetadata,
     bool hasPackageManifest,
     bool isInIndex)
 {
     IsConsistent           = isConsistent;
     PackageContentMetadata = packageContentMetadata;
     HasPackageManifest     = hasPackageManifest;
     IsInIndex = isInIndex;
 }
Ejemplo n.º 7
0
        public static async Task InfrastructureRun(
            [QueueTrigger("infrastructure")] string myQueueItem,
            ILogger log)
        {
            BlobMetadata blobMetadata = BlobMetadata.Parse(myQueueItem);

            switch (blobMetadata.Command)
            {
            case Command.Delete:
                await Common.DeleteBlobAsync(blobMetadata, log);

                break;
            }
        }
Ejemplo n.º 8
0
            /// <summary>
            /// Instantiate the object.
            /// </summary>
            /// <param name="md">BLOB metadata.</param>
            /// <returns>Object metadata.</returns>
            public static ObjectMetadata FromBlobMetadata(BlobMetadata md)
            {
                if (md == null)
                {
                    throw new ArgumentNullException(nameof(md));
                }

                ObjectMetadata ret = new ObjectMetadata();

                ret.Key           = md.Key;
                ret.ContentType   = md.ContentType;
                ret.ContentLength = md.ContentLength;
                ret.ETag          = md.ETag;
                ret.CreatedUtc    = md.CreatedUtc;
                ret.LastAccessUtc = md.LastAccessUtc;
                ret.LastUpdateUtc = md.LastUpdateUtc;
                return(ret);
            }
Ejemplo n.º 9
0
        public static async Task BindAsync(string container, Stream newBlob, string name, IBinder binder, ILogger log)
        {
            log.LogInformation($"Incoming blob detected\n Name:{name} \n Size: {newBlob.Length} Bytes");

            var newBlobName = $"{container}.{Guid.NewGuid().ToString().Substring(0, 8)}.{name}";

            // A new name for the blob. It should follow naming convention rule as follows
            // ingest/<External Party Identifier>.<Unique String>.<Original File Name>
            var ingestBlobPath = $"ingest/{newBlobName}";

            // This is one aspect of back-end interface implementation
            // The file has to be moved into Ingest folder for the back-end system to begin processing it
            using (var newMovedBlob = await binder.BindAsync <Stream>(new BlobAttribute(ingestBlobPath, FileAccess.Write)))
            {
                // Direct copy from blob to blob in the same storage
                await newBlob.CopyToAsync(newMovedBlob);

                log.LogInformation($"Incoming blob has been moved and renamed\n New location and name:{ingestBlobPath}");
            };

            // This is Audit non-functional requirement implementation
            // The file has to be moved into Archive folder for auditing purposes
            newBlob.Position = 0;

            var archiveBlobPath = $"archive/{newBlobName}";

            using (var newMovedBlob = await binder.BindAsync <Stream>(new BlobAttribute(archiveBlobPath, FileAccess.Write)))
            {
                // Direct copy from blob to blob in the same storage
                await newBlob.CopyToAsync(newMovedBlob);

                log.LogInformation($"Incoming blob has been moved and renamed\n New location and name:{ingestBlobPath}");
            };

            // Blob metadata to be serialized and added in the queue for deletion
            var blobMetadata = new BlobMetadata(Command.Delete, name, "Incoming", container);

            // After we have completed our business with the original file, we are safe to delete it
            var cloudQueue = await binder.BindAsync <CloudQueue>(new QueueAttribute(INFRASTRUCTURE_QUEUE_NAME));

            await cloudQueue.AddMessageAsync(new CloudQueueMessage(blobMetadata.ToString()));

            log.LogInformation($"Incoming blob has been queued for deletion\n Name:{name}");
        }