/// <summary> /// Adds SAS uri configuration. /// </summary> /// <param name="azureStorageAttachmentConfiguration"></param> /// <param name="messagePropertyToIdentifySasUri">The <see cref="Message"/> user property used for SAS uri.</param> /// <param name="sasTokenValidationTime">The time SAS uri is valid for.</param> /// <returns></returns> public static AzureStorageAttachmentConfiguration WithSasUri( this AzureStorageAttachmentConfiguration azureStorageAttachmentConfiguration, string messagePropertyToIdentifySasUri = DefaultMessagePropertyToIdentitySasUri, TimeSpan?sasTokenValidationTime = null) { if (sasTokenValidationTime == null) { sasTokenValidationTime = DefaultSasTokenValidationTime; } Guard.AgainstNegativeOrZeroTimeSpan(nameof(sasTokenValidationTime), sasTokenValidationTime); azureStorageAttachmentConfiguration.MessagePropertyForSasUri = messagePropertyToIdentifySasUri; azureStorageAttachmentConfiguration.SasTokenValidationTime = sasTokenValidationTime.Value; return(azureStorageAttachmentConfiguration); }
/// <summary> /// Adds blob SAS URI configuration. /// </summary> /// <param name="azureStorageAttachmentConfiguration"></param> /// <param name="messagePropertyToIdentifySasUri">The <see cref="Message"/> user property used for blob SAS URI.</param> /// <param name="sasTokenValidationTime">The time blob SAS URI is valid for. Default value is 7 days.</param> /// <returns></returns> public static AzureStorageAttachmentConfiguration WithBlobSasUri( this AzureStorageAttachmentConfiguration azureStorageAttachmentConfiguration, string messagePropertyToIdentifySasUri = AzureStorageAttachmentConfigurationConstants.DefaultMessagePropertyToIdentitySasUri, TimeSpan?sasTokenValidationTime = null) { if (azureStorageAttachmentConfiguration.UsingSas) { throw new Exception("Invalid configuration: .WithBlobSasUri() requires account shared key and cannot be used with service/container Shared Access Signature."); } if (sasTokenValidationTime == null) { sasTokenValidationTime = DefaultSasTokenValidationTime; } Guard.AgainstNegativeOrZeroTimeSpan(nameof(sasTokenValidationTime), sasTokenValidationTime); azureStorageAttachmentConfiguration.MessagePropertyForBlobSasUri = messagePropertyToIdentifySasUri; azureStorageAttachmentConfiguration.BlobSasTokenValidationTime = sasTokenValidationTime.Value; return(azureStorageAttachmentConfiguration); }
/// <summary> /// Allow body replacement override. /// <remarks> /// By default, message body is replaced with null. /// </remarks> /// </summary> /// <param name="azureStorageAttachmentConfiguration"></param> /// <param name="bodyReplacer">A custom body replacer.</param> /// <returns></returns> public static AzureStorageAttachmentConfiguration OverrideBody( this AzureStorageAttachmentConfiguration azureStorageAttachmentConfiguration, Func <Message, byte[]?> bodyReplacer) { Guard.AgainstNull(nameof(bodyReplacer), bodyReplacer); azureStorageAttachmentConfiguration.BodyReplacer = BodyReplacer; return(azureStorageAttachmentConfiguration); byte[]? BodyReplacer(Message message) { try { return(bodyReplacer(message)); } catch (Exception exception) { throw new Exception($"An exception occurred when executing {nameof(bodyReplacer)} delegate.", exception); } } }
/// <summary> /// Allow attachment blob name overriding. /// </summary> /// <param name="azureStorageAttachmentConfiguration"></param> /// <param name="blobNameResolver">A custom blob name resolver to override the default name set to a GUID.</param> /// <returns></returns> public static AzureStorageAttachmentConfiguration OverrideBlobName( this AzureStorageAttachmentConfiguration azureStorageAttachmentConfiguration, Func <Message, string> blobNameResolver) { Guard.AgainstNull(nameof(blobNameResolver), blobNameResolver); azureStorageAttachmentConfiguration.BlobNameResolver = BlobNameResolver; return(azureStorageAttachmentConfiguration); string BlobNameResolver(Message message) { try { return(blobNameResolver(message)); } catch (Exception exception) { throw new Exception($"An exception occurred when executing the {nameof(blobNameResolver)} delegate.", exception); } } }
/// <summary>Download attachment from Azure Storage blob without registering plugin, using configuration object.</summary> /// <param name="message"><see cref="Message"/></param> /// <param name="configuration"><see cref="AzureStorageAttachmentConfiguration"/> object.</param> /// <returns><see cref="Message"/> with body downloaded from Azure Storage blob.</returns> public static async Task <Message> DownloadAzureStorageAttachment(this Message message, AzureStorageAttachmentConfiguration configuration) { var plugin = new AzureStorageAttachment(configuration); return(await plugin.AfterMessageReceive(message).ConfigureAwait(false)); }
/// <summary>Upload attachment to Azure Storage blob without registering plugin.</summary> /// <param name="message"><see cref="Message"/></param> /// <param name="configuration"><see cref="AzureStorageAttachmentConfiguration"/> object.</param> /// <returns><see cref="Message"/> with body uploaded to Azure Storage blob.</returns> public static async Task <Message> UploadAzureStorageAttachment(this Message message, AzureStorageAttachmentConfiguration configuration) { var plugin = new AzureStorageAttachment(configuration); return(await plugin.BeforeMessageSend(message).ConfigureAwait(false)); }
/// <summary>Instantiate plugin with the required configuration.</summary> /// <param name="client"><see cref="IClientEntity"/>, <see cref="SubscriptionClient"/>, <see cref="QueueClient"/>, <see cref="MessageSender"/>, <see cref="MessageReceiver"/>, or <see cref="SessionClient"/> to register plugin with.</param> /// <param name="configuration"><see cref="AzureStorageAttachmentConfiguration"/> object.</param> /// <returns>Registered plugin as <see cref="ServiceBusPlugin"/>.</returns> public static ServiceBusPlugin RegisterAzureStorageAttachmentPlugin(this IClientEntity client, AzureStorageAttachmentConfiguration configuration) { var plugin = new AzureStorageAttachment(configuration); client.RegisterPlugin(plugin); return(plugin); }
public static AzureStorageAttachmentConfiguration WithSasUri( this AzureStorageAttachmentConfiguration azureStorageAttachmentConfiguration, string messagePropertyToIdentifySasUri = DefaultMessagePropertyToIdentitySasUri, TimeSpan?sasTokenValidationTime = null) => throw new Exception("Deprecated with error. See documentation for all configuration options.");