Skip to content

Commit

Permalink
style: format code with dotnet-format
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 7dcb415 according to the output
from dotnet-format.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Jan 26, 2024
1 parent 7dcb415 commit d2490c8
Show file tree
Hide file tree
Showing 42 changed files with 1,310 additions and 1,306 deletions.
194 changes: 97 additions & 97 deletions src/Communication/AzureCommunicationServicesAutoConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,101 +24,101 @@ public class AzureCommunicationServicesAutoConfigurator(
ILogger<AzureCommunicationServicesAutoConfigurator> logger
) : IConfigureIHostApplicationBuilder, IConfigureIApplicationBuilder, ILog
{
public ConfigurationOrder Order => ConfigurationOrder.AnyTime;

public ILogger Logger => logger;

public void Configure(IApplicationBuilder builder)
{
var emailSenderOptions = builder.ApplicationServices.GetService<
IOptions<EmailSenderOptions>
>();
if (emailSenderOptions is null)
{
Logger.LogWarning(
"Azure Email Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
var smsSenderOptions = builder.ApplicationServices.GetService<IOptions<SmsSenderOptions>>();
if (smsSenderOptions is null)
{
Logger.LogWarning(
"Azure SMS Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
}

public void Configure(IHostApplicationBuilder builder)
{
var optionsSection = builder.Configuration.GetSection(
AzureCommunicationServicesOptionsBase.ConfigurationSectionName
);
if (!optionsSection.Exists())
{
Logger.LogWarning(
"Azure Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
else
{
builder.Services.Configure<AzureCommunicationServicesOptions>(optionsSection);

var emailCommunicationSection = builder.Configuration.GetSection(
EmailSenderOptions.ConfigurationSectionName
);
if (!emailCommunicationSection.Exists())
{
Logger.LogWarning(
"Azure Email Communication Services options are not configured. Please configure them in your appsettings.json file."
);
builder.Services.AddSingleton<IEmailSender>(
y =>
throw new KeyNotFoundException(
$"The {nameof(EmailSenderOptions)} configuration section was not found in the appsettings.json file."
)
);
}
else
{
builder.Services.Configure<EmailSenderOptions>(emailCommunicationSection);
builder.Services.AddSingleton<IEmailSender>(
y =>
new EmailSender(
y.GetService<IOptions<EmailSenderOptions>>()
?? throw new KeyNotFoundException(
$"The {nameof(EmailSenderOptions)} configuration section was not found in the appsettings.json file."
)
)
);
}
var smsCommunicationSection = builder.Configuration.GetSection(
SmsSenderOptions.ConfigurationSectionName
);
if (!smsCommunicationSection.Exists())
{
Logger.LogWarning(
"Azure SMS Communication Services options are not configured. Please configure them in your appsettings.json file."
);
builder.Services.AddSingleton<ISmsSender>(
y =>
throw new KeyNotFoundException(
$"The {nameof(SmsSenderOptions)} configuration section was not found in the appsettings.json file."
)
);
}
else
{
builder.Services.Configure<SmsSenderOptions>(smsCommunicationSection);
builder.Services.AddSingleton<ISmsSender>(
y =>
new SmsSender(
y.GetService<IOptions<SmsSenderOptions>>()
?? throw new KeyNotFoundException(
$"The {nameof(SmsSenderOptions)} configuration section was not found in the appsettings.json file."
)
)
);
}
}
}
public ConfigurationOrder Order => ConfigurationOrder.AnyTime;

public ILogger Logger => logger;

public void Configure(IApplicationBuilder builder)
{
var emailSenderOptions = builder.ApplicationServices.GetService<
IOptions<EmailSenderOptions>
>();
if (emailSenderOptions is null)
{
Logger.LogWarning(
"Azure Email Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
var smsSenderOptions = builder.ApplicationServices.GetService<IOptions<SmsSenderOptions>>();
if (smsSenderOptions is null)
{
Logger.LogWarning(
"Azure SMS Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
}

public void Configure(IHostApplicationBuilder builder)
{
var optionsSection = builder.Configuration.GetSection(
AzureCommunicationServicesOptionsBase.ConfigurationSectionName
);
if (!optionsSection.Exists())
{
Logger.LogWarning(
"Azure Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
else
{
builder.Services.Configure<AzureCommunicationServicesOptions>(optionsSection);

var emailCommunicationSection = builder.Configuration.GetSection(
EmailSenderOptions.ConfigurationSectionName
);
if (!emailCommunicationSection.Exists())
{
Logger.LogWarning(
"Azure Email Communication Services options are not configured. Please configure them in your appsettings.json file."
);
builder.Services.AddSingleton<IEmailSender>(
y =>
throw new KeyNotFoundException(
$"The {nameof(EmailSenderOptions)} configuration section was not found in the appsettings.json file."
)
);
}
else
{
builder.Services.Configure<EmailSenderOptions>(emailCommunicationSection);
builder.Services.AddSingleton<IEmailSender>(
y =>
new EmailSender(
y.GetService<IOptions<EmailSenderOptions>>()
?? throw new KeyNotFoundException(
$"The {nameof(EmailSenderOptions)} configuration section was not found in the appsettings.json file."
)
)
);
}
var smsCommunicationSection = builder.Configuration.GetSection(
SmsSenderOptions.ConfigurationSectionName
);
if (!smsCommunicationSection.Exists())
{
Logger.LogWarning(
"Azure SMS Communication Services options are not configured. Please configure them in your appsettings.json file."
);
builder.Services.AddSingleton<ISmsSender>(
y =>
throw new KeyNotFoundException(
$"The {nameof(SmsSenderOptions)} configuration section was not found in the appsettings.json file."
)
);
}
else
{
builder.Services.Configure<SmsSenderOptions>(smsCommunicationSection);
builder.Services.AddSingleton<ISmsSender>(
y =>
new SmsSender(
y.GetService<IOptions<SmsSenderOptions>>()
?? throw new KeyNotFoundException(
$"The {nameof(SmsSenderOptions)} configuration section was not found in the appsettings.json file."
)
)
);
}
}
}
}
88 changes: 44 additions & 44 deletions src/Communication/Email/EmailSenderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,48 @@ public record class EmailSenderOptions : AzureCommunicationServicesOptions<Email
public new const string ConfigurationSectionName =
$"{AzureCommunicationServicesOptionsBase.ConfigurationSectionName}:Email";

public override required EmailAddress DefaultFrom { get; set; }

public static new EmailSenderOptions Parse(string connectionString)
{
var options = AzureCommunicationServicesOptions<EmailAddress>.Parse(connectionString);
return new EmailSenderOptions(options);
}

[SetsRequiredMembers]
public EmailSenderOptions(
AzureCommunicationServicesOptionsBase options,
EmailAddress? defaultFrom = null
)
{
DefaultFrom = defaultFrom ?? EmailAddress.Empty;
Endpoint = options.Endpoint;
AccessKey = options.AccessKey;
}

[SetsRequiredMembers]
public EmailSenderOptions(AzureCommunicationServicesOptions<EmailAddress> options)
: base(options)
{
DefaultFrom = options.DefaultFrom;
AdminFrom = options.AdminFrom;
MassDistributionFrom = options.MassDistributionFrom;
SecurityFrom = options.SecurityFrom;
}

[SetsRequiredMembers]
public EmailSenderOptions(string connectionString, EmailAddress? defaultFrom = null)
: this(Parse(connectionString) with { DefaultFrom = defaultFrom ?? EmailAddress.Empty }) { }

[SetsRequiredMembers]
public EmailSenderOptions(string endpoint, string accessKey, EmailAddress? defaultFrom = null)
{
DefaultFrom = defaultFrom ?? EmailAddress.Empty;
Endpoint = endpoint;
AccessKey = accessKey;
}

[SetsRequiredMembers]
public EmailSenderOptions()
: this(EmptyValue) { }
public override required EmailAddress DefaultFrom { get; set; }

public static new EmailSenderOptions Parse(string connectionString)
{
var options = AzureCommunicationServicesOptions<EmailAddress>.Parse(connectionString);
return new EmailSenderOptions(options);
}

[SetsRequiredMembers]
public EmailSenderOptions(
AzureCommunicationServicesOptionsBase options,
EmailAddress? defaultFrom = null
)
{
DefaultFrom = defaultFrom ?? EmailAddress.Empty;
Endpoint = options.Endpoint;
AccessKey = options.AccessKey;
}

[SetsRequiredMembers]
public EmailSenderOptions(AzureCommunicationServicesOptions<EmailAddress> options)
: base(options)
{
DefaultFrom = options.DefaultFrom;
AdminFrom = options.AdminFrom;
MassDistributionFrom = options.MassDistributionFrom;
SecurityFrom = options.SecurityFrom;
}

[SetsRequiredMembers]
public EmailSenderOptions(string connectionString, EmailAddress? defaultFrom = null)
: this(Parse(connectionString) with { DefaultFrom = defaultFrom ?? EmailAddress.Empty }) { }

[SetsRequiredMembers]
public EmailSenderOptions(string endpoint, string accessKey, EmailAddress? defaultFrom = null)
{
DefaultFrom = defaultFrom ?? EmailAddress.Empty;
Endpoint = endpoint;
AccessKey = accessKey;
}

[SetsRequiredMembers]
public EmailSenderOptions()
: this(EmptyValue) { }
}
74 changes: 37 additions & 37 deletions src/Communication/Sms/SmsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,41 @@ public class SmsSender(SmsSenderOptions? options) : ISmsSender
/// <summary>
/// The options.
/// </summary>
private readonly SmsSenderOptions _options = options;

/// <summary>
/// Initializes a new instance of the <see cref="SmsSender"/> class.
/// </summary>
/// <param name="options">The options.</param>
public SmsSender(IOptions<SmsSenderOptions> options)
: this(options?.Value) { }

/// <summary>
/// Creates the client.
/// </summary>
/// <returns>An <see cref="SmsClient" />.</returns>
protected SmsClient CreateClient() => new(_options.ConnectionString);

private SmsClient _client;

/// <summary>
/// Gets the client.
/// </summary>
protected SmsClient Client => _client ??= CreateClient();

/// <summary>
/// Sends the sms asynchronously.
/// </summary>
/// <param name="to">The number of the recipient.</param>
/// <param name="message">The message.</param>
/// <returns>A <![CDATA[Task<SmsSendResult>]]></returns>
public async Task<ISmsSendResult> SendSmsAsync(PhoneNumber @to, string message)
{
return new SmsSendResult(
(await Client.SendAsync(from: _options.DefaultFrom, to: @to, message: message)).Value
);
}

public Task<ISmsSendResult> SendSmsAsync(string to, string message) =>
SendSmsAsync(PhoneNumber.From(to), message);
private readonly SmsSenderOptions _options = options;

/// <summary>
/// Initializes a new instance of the <see cref="SmsSender"/> class.
/// </summary>
/// <param name="options">The options.</param>
public SmsSender(IOptions<SmsSenderOptions> options)
: this(options?.Value) { }

/// <summary>
/// Creates the client.
/// </summary>
/// <returns>An <see cref="SmsClient" />.</returns>
protected SmsClient CreateClient() => new(_options.ConnectionString);

private SmsClient _client;

/// <summary>
/// Gets the client.
/// </summary>
protected SmsClient Client => _client ??= CreateClient();

/// <summary>
/// Sends the sms asynchronously.
/// </summary>
/// <param name="to">The number of the recipient.</param>
/// <param name="message">The message.</param>
/// <returns>A <![CDATA[Task<SmsSendResult>]]></returns>
public async Task<ISmsSendResult> SendSmsAsync(PhoneNumber @to, string message)
{
return new SmsSendResult(
(await Client.SendAsync(from: _options.DefaultFrom, to: @to, message: message)).Value
);
}

public Task<ISmsSendResult> SendSmsAsync(string to, string message) =>
SendSmsAsync(PhoneNumber.From(to), message);
}
Loading

0 comments on commit d2490c8

Please sign in to comment.