Example #1
0
        protected ApiResult UploadArtifact(Artifact artifact)
        {
            CloudBlockBlob blob     = null;
            string         blobName = AzureStorageApi.GetValidAzureBlobName(artifact.Name);
            string         blobPath = GetBlobPathForArtifact(artifact);

            blob = (CloudBlockBlob)Storage.GetCloudBlob(ArtifactsContainerName, ArtifactsBlobDirectory, blobName,
                                                        BlobType.BlockBlob);
            if (blob == null)
            {
                Error("Could not get reference to blob {0}.", blobPath);
                return(ApiResult.Failure);
            }
            else if (blob.Exists())
            {
                Error("The block blob {0} already exists.", blobPath);
                return(ApiResult.Failure);
            }
            else
            {
                if (artifact is FileArtifact fileArtifact)
                {
                    if (fileArtifact.HasData)
                    {
                        return(Storage.UploadBlobData(blob, fileArtifact.Data));
                    }
                    else
                    {
                        return(Storage.UploadBlobData(blob, fileArtifact.Path));
                    }
                }
                else if (artifact is ImageArtifact imageArtifact)
                {
                    if (imageArtifact.HasData)
                    {
                        return(Storage.UploadBlobData(blob, imageArtifact.Data));
                    }
                    else if (imageArtifact.HasFile && imageArtifact.FileArtifact.HasData)
                    {
                        return(Storage.UploadBlobData(blob, imageArtifact.FileArtifact.Data));
                    }
                    else if (imageArtifact.HasFile)
                    {
                        return(Storage.UploadBlobData(blob, imageArtifact.FileArtifact.Path));
                    }
                    else
                    {
                        throw new Exception("Image artifact {0} does not have associated data or file.".F(artifact.Id));
                    }
                }
                else if (artifact is TextArtifact textArtifact)
                {
                    return(Storage.UploadBlobData(blob, textArtifact.Text.ToArray()));
                }
                else
                {
                    throw new NotImplementedException("Unknown artifact type.");
                }
            }
        }
Example #2
0
 public AzureStorageBlobUpload(Profile profile, params Type[] clients) : base(profile, clients)
 {
     if (ConfigurationManager.ConnectionStrings["OLAFArtifacts"] == null)
     {
         UseEmulator         = true;
         ApiConnectionString = "UseDevelopmentStorage=true";
         Info("{0} service using Azure Storage Emulator.", typeof(AzureStorageBlobUpload).Name);
     }
     else
     {
         ApiConnectionString = ConfigurationManager.ConnectionStrings["OLAFArtifacts"].ConnectionString;
     }
     ArtifactsBlobDirectory = AzureStorageApi.GetValidAzureBlobName(Profile.ArtifactsDirectory.Name);
     Status = ApiStatus.Initializing;
 }
Example #3
0
 protected string GetBlobPathForArtifact(Artifact artifact) => "{0}/{1}/{2}".F(ArtifactsContainerName, ArtifactsBlobDirectory,
                                                                               AzureStorageApi.GetValidAzureBlobName(artifact.Name));