Ejemplo n.º 1
0
        public async Task <List <string> > ListBlobs(TypeOfBlobUpload typeOfBlobUpload, string usersEmail)
        {
            try
            {
                if (string.IsNullOrEmpty(usersEmail))
                {
                    return(null);
                }

                BlobContinuationToken continuationToken = null;

                var directory         = cloudBlobContainer.GetDirectoryReference($"Models/{usersEmail}");
                var blobResultSegment = await directory.ListBlobsSegmentedAsync(continuationToken);

                List <string> blobNames = new List <string>();

                if (typeOfBlobUpload == TypeOfBlobUpload.TrainingFile)
                {
                    // Select blobs by name, where the name suggests the file is the training file
                    blobNames.AddRange(blobResultSegment.Results
                                       .OfType <CloudBlockBlob>()
                                       .Where(a => a.Uri.Segments.Last().Contains(".csv"))
                                       .OrderByDescending(b => b.Properties.LastModified)
                                       .Select(i => i.Uri.Segments.Last()).ToList());
                }
                else
                {
                    // Select blobs by name, where the name suggests the file is the model file
                    blobNames.AddRange(blobResultSegment.Results
                                       .OfType <CloudBlockBlob>()
                                       .Where(a => a.Uri.Segments.Last().Contains(".zip"))
                                       .OrderByDescending(b => b.Properties.LastModified)
                                       .Select(i => i.Uri.Segments.Last()).ToList());
                }

                return(blobNames);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> UploadBlob(Stream stream, TypeOfBlobUpload typeOfBlobUpload, string usersEmail, string fileName = null)
        {
            try
            {
                if (typeOfBlobUpload == TypeOfBlobUpload.ModelFile)
                {
                    CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference($"Models/{usersEmail}/Model-{Guid.NewGuid()}.zip");
                    await cloudBlockBlob.UploadFromStreamAsync(stream);
                }
                else
                {
                    CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference($"Models/{usersEmail}/{fileName}");
                    await cloudBlockBlob.UploadFromStreamAsync(stream);
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }