Beispiel #1
0
        /// <summary>
        /// Store or update batchFile entity in blob storage.
        /// </summary>
        /// <param name="entity">Represents batchFile entity used for storage and retrieval.</param>
        /// <returns><see cref="Task"/> that represents configuration entity is saved or updated.</returns>
        private async Task StoreOrUpdateBatchFileEntityAsync(BatchFileEntity entity)
        {
            telemetryClient.TrackEvent("StoringBatchBlob", new Dictionary <string, string>
            {
                { "name", entity.Id },
                { "bytes", entity.FileBytes.Length.ToString() },
            });

            try
            {
                // Get a reference to a blob
                var blobClient = batchFileBlobContainer.GetBlockBlobReference(entity.Id);
                await blobClient.UploadFromByteArrayAsync(entity.FileBytes, 0, entity.FileBytes.Length);

                telemetryClient.TrackEvent("StoredBatchBlob", new Dictionary <string, string>
                {
                    { "name", entity.Id },
                    { "uri", blobClient.Uri.ToString() },
                });
            }
            catch (Exception ex)
            {
                telemetryClient.TrackEvent("FailedStoringBatchBlob");
                throw;
            }
        }
        /// <summary>
        /// Store or update BatchFile entity in table storage.
        /// </summary>
        /// <param name="batchFile">Represents batchFile entity used for storage and retrieval.</param>
        /// <returns><see cref="Task"/> that represents configuration entity is saved or updated.</returns>
        public Task UpsertBatchFileAsync(BatchFileEntity batchFile)
        {
            batchFile.PartitionKey = PartitionKey;
            batchFile.RowKey       = batchFile.Id;

            return(this.StoreOrUpdateBatchFileEntityAsync(batchFile));
        }
        /// <summary>
        /// Store or update batchFile entity in table storage.
        /// </summary>
        /// <param name="entity">Represents batchFile entity used for storage and retrieval.</param>
        /// <returns><see cref="Task"/> that represents configuration entity is saved or updated.</returns>
        private async Task <TableResult> StoreOrUpdateBatchFileEntityAsync(BatchFileEntity entity)
        {
            await this.EnsureInitializedAsync().ConfigureAwait(false);

            TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(entity);

            return(await this.batchFileCloudTable.ExecuteAsync(addOrUpdateOperation).ConfigureAwait(false));
        }
Beispiel #4
0
        /// <summary>
        /// Get already saved entity detail from blob table.
        /// </summary>
        /// <param name="id">batchFile id received from bot based on which appropriate row data will be fetched.</param>
        /// <returns><see cref="Task"/> Already saved entity detail.</returns>
        public async Task <BatchFileEntity> GetBatchFileAsync(string id)
        {
            try
            {
                telemetryClient.TrackEvent("FetchingBatchBlob", new Dictionary <string, string>
                {
                    { "name", id },
                });

                await this.EnsureInitializedAsync().ConfigureAwait(false); // When there is no batchFile created by end user

                if (string.IsNullOrEmpty(id))
                {
                    return(null);
                }

                var blobClient = batchFileBlobContainer.GetBlockBlobReference(id);
                var stream     = new MemoryStream();
                await blobClient.DownloadToStreamAsync(stream);

                stream.Position = 0;
                var result = new BatchFileEntity()
                {
                    Id        = id,
                    FileBytes = stream.ToArray(),
                };

                telemetryClient.TrackEvent("FetchedBatchBlob", new Dictionary <string, string>
                {
                    { "name", id },
                });

                return(result);
            }
            catch (Exception ex)
            {
                telemetryClient.TrackEvent("FailedFetchingBatchBlob", new Dictionary <string, string>
                {
                    { "name", id },
                });
                throw;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Store or update BatchFile entity in blob storage.
        /// </summary>
        /// <param name="batchFile">Represents batchFile entity used for storage and retrieval.</param>
        /// <returns><see cref="Task"/> that represents configuration entity is saved or updated.</returns>
        public async Task UpsertBatchFileAsync(BatchFileEntity batchFile)
        {
            await this.EnsureInitializedAsync().ConfigureAwait(false); // When there is no batchFile created by end user

            await this.StoreOrUpdateBatchFileEntityAsync(batchFile);
        }