/// <summary>
        /// Handles inserting into the azure table. Is only fired when a new blob is detected in queue
        /// and is called through the GeneratePDF method within the webjob
        /// </summary>
        /// <param name="title">The name of the blob being added</param>
        public void InsertIntoCloudTable(string txtBlobName, string pdfBlobName)
        {
            //Name formatting
            int    start            = txtBlobName.IndexOf("/") + 1;
            int    end              = txtBlobName.IndexOf(".");
            string titleNoExtension = txtBlobName.Substring(start, end - start);

            const String partitionName = "FileMetadata_Partition_1";

            var txtBlob = GetCloudBlobContainer().GetDirectoryReference("txtdocs").GetBlobReference(txtBlobName);
            var pdfBlob = GetCloudBlobContainer().GetDirectoryReference("pdfdocs").GetBlobReference(pdfBlobName);
            //Grab both the pdf and text doc containers

            var txtBlobUrl = txtBlob.Uri.ToString();
            var pdfBlobUrl = pdfBlob.Uri.ToString();
            //Grab the relevant URI's for each blob

            TableBatchOperation batchOperation = new TableBatchOperation();

            string rowKey = GetRowKey().ToString(); //Convert the rowkey back to a string

            FileMetadataEntity fileMetadata = new FileMetadataEntity(partitionName, rowKey)
            {
                Title           = titleNoExtension,
                CreationDate    = DateTime.Now,
                TextFileBlobURL = txtBlobUrl,
                PDFFileBlobURL  = pdfBlobUrl,
            };

            batchOperation.Insert(fileMetadata);
            table.ExecuteBatch(batchOperation);
        }
Exemple #2
0
 private static FileMetadata ToDto(FileMetadataEntity entity) => new FileMetadata
 {
     Id        = Guid.Parse(entity.RowKey.Split(';').Last()),
     CreatedBy = entity.CreatedBy,
     Name      = entity.Name,
     Extension = entity.Extension,
     FileSize  = entity.FileSize
 };
        private void SaveFileMetadataToDb(string path)
        {
            var fileInfo = new FileInfo(path);

            var fileMetadataEntity = new FileMetadataEntity
            {
                FileName     = fileInfo.Name,
                DateUploaded = fileInfo.CreationTimeUtc,
                Size         = BytesToString(fileInfo.Length),
                Expires      = fileInfo.CreationTimeUtc.AddDays(90),
                Url          = fileInfo.FullName
            };

            _repository.SaveUploadedFileMetadata(fileMetadataEntity);
        }
        /// <summary>
        /// Finds the last row key in the given azure table utilising the 'LastOrDefault()' method.
        /// If no key is found, automatically default to '1' and if the key is found, increment by 1.
        /// </summary>
        /// <returns></returns>
        public int GetRowKey()
        {
            TableQuery <FileMetadataEntity> query = new TableQuery <FileMetadataEntity>();
            FileMetadataEntity fileMetaDataEntity = table.ExecuteQuery(query).OrderBy(a => a.PartitionKey).LastOrDefault();
            //Grabs the rowKey with the highest number

            int rowKey = 1;

            if (fileMetaDataEntity != null)
            {
                rowKey = Convert.ToInt32(fileMetaDataEntity.RowKey); //Get the last rowkey
                rowKey++;                                            //Increment by one
            }
            return(rowKey);
        }
        public bool SaveUploadedFileMetadata(FileMetadataEntity fileMetadata)
        {
            var isAdded = false;

            try
            {
                _context.UploadedFileInfo.Add(fileMetadata);
                isAdded = Save();
            }
            catch (Exception e)
            {
                // TO DO
            }

            return(isAdded);
        }
Exemple #6
0
        public async Task <FileMetadata> CreateFileMetadata(FileMetadata fileMetadata)
        {
            var entity = new FileMetadataEntity
            {
                PartitionKey = GlobalPartitionKey,
                RowKey       = RowKeyPrefix + fileMetadata.Id,
                CreatedBy    = fileMetadata.CreatedBy,
                Name         = fileMetadata.Name,
                Extension    = fileMetadata.Extension,
                FileSize     = fileMetadata.FileSize
            };

            var result = await _table.ExecuteAsync(TableOperation.Insert(entity));

            var created = (FileMetadataEntity)result.Result;

            return(ToDto(created));
        }