Skip to content

Commit

Permalink
Merge pull request #113 from Encamina/@hramos/FixWarnings/Encamina.En…
Browse files Browse the repository at this point in the history
…marcha.Bot

Fixed warnings CS8603 and CS8625 in Encamina.Enmarcha.Bot
  • Loading branch information
HugoRamosEs authored May 8, 2024
2 parents 1e41544 + c4f6b11 commit 4640318
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Previous classification is not required if changes are simple or all belong to t
- Fixed warnings CS8603 and CS8025 in:
- `Encamina.Enmarcha.AI`.
- `Encamina.Enmarcha.AspNet`
- `Encamina.Enmarcha.Bot`
- Corrected a typo in the Spanish error message in `ResponseMessages.es.resx` from "ha encontrar" to "ha encontrado".

## [8.1.5]
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>8.1.6</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionPrefix>8.1.7</VersionPrefix>
<VersionSuffix>preview-01</VersionSuffix>
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IMetadataProcessor
/// <returns>
/// A read only collection of answers processed with given metadata options.
/// </returns>
Task<IReadOnlyCollection<IAnswer>> ProcessAnswersAsync(IEnumerable<IAnswer> answers, MetadataOptions metadataOptions, CancellationToken cancellationToken);
Task<IReadOnlyCollection<IAnswer>> ProcessAnswersAsync(IEnumerable<IAnswer> answers, MetadataOptions? metadataOptions, CancellationToken cancellationToken);

/// <summary>
/// Process a message to obtain metadata options from it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface IQuestionRequestOptions
/// <summary>
/// Gets the metadata options.
/// </summary>
MetadataOptions MetadataOptions { get; }
MetadataOptions? MetadataOptions { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public QuestionRequestOptions(IEnumerable<string> sources)
public virtual IReadOnlyCollection<string> Sources { get; } = Array.Empty<string>();

/// <inheritdoc/>
public virtual MetadataOptions MetadataOptions { get; init; }
public virtual MetadataOptions? MetadataOptions { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface ITextTranslationRequest
/// <summary>
/// Gets the language to translate from.
/// </summary>
CultureInfo FromLanguage { get; init; }
CultureInfo? FromLanguage { get; init; }

/// <summary>
/// Gets the collection of languages to translate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Encamina.Enmarcha.AI.TextsTranslation.Abstractions;
public class TextTranslationRequest : ITextTranslationRequest
{
/// <inheritdoc/>
public virtual CultureInfo FromLanguage { get; init; }
public virtual CultureInfo? FromLanguage { get; init; }

/// <inheritdoc/>
public virtual ICollection<CultureInfo> ToLanguages { get; init; } = new List<CultureInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ protected DialogsProviderBase(IServiceProvider serviceProvider)
}

/// <inheritdoc/>
public virtual Dialog GetById(string dialogId) => GetDialogByType(dialogsById?[dialogId], d => FilterById(d, dialogId));
public virtual Dialog? GetById(string dialogId) => GetDialogByType(dialogsById?[dialogId], d => FilterById(d, dialogId));

/// <inheritdoc/>
public virtual Dialog GetByIntent(string dialogIntent) =>
public virtual Dialog? GetByIntent(string dialogIntent) =>
GetDialogByType(dialogsByIntent?[dialogIntent.ToUpperInvariant()], d => FilterByIntent(d, dialogIntent));

/// <inheritdoc/>
public virtual Dialog GetByName(string dialogName) =>
public virtual Dialog? GetByName(string dialogName) =>
GetDialogByType(dialogsByName?[dialogName.ToUpperInvariant()], d => FilterByName(d, dialogName));

/// <inheritdoc/>
public virtual bool TryGetById(string dialogId, out Dialog dialog)
public virtual bool TryGetById(string dialogId, out Dialog? dialog)
{
if (dialogsById == null)
{
Expand All @@ -78,7 +78,7 @@ public virtual bool TryGetById(string dialogId, out Dialog dialog)
}

/// <inheritdoc/>
public virtual bool TryGetByIntent(string dialogIntent, out Dialog dialog)
public virtual bool TryGetByIntent(string dialogIntent, out Dialog? dialog)
{
if (dialogsByIntent == null)
{
Expand All @@ -94,7 +94,7 @@ public virtual bool TryGetByIntent(string dialogIntent, out Dialog dialog)
}

/// <inheritdoc/>
public virtual bool TryGetByName(string dialogName, out Dialog dialog)
public virtual bool TryGetByName(string dialogName, out Dialog? dialog)
{
if (dialogsByName == null)
{
Expand All @@ -110,20 +110,20 @@ public virtual bool TryGetByName(string dialogName, out Dialog dialog)
}

/// <inheritdoc/>
public virtual Dialog GetByType(Type dialogType, Func<Dialog, bool> filterExpression = null) => GetDialogByType(dialogType, filterExpression);
public virtual Dialog? GetByType(Type dialogType, Func<Dialog, bool>? filterExpression = null) => GetDialogByType(dialogType, filterExpression);

/// <inheritdoc/>
public virtual T GetByType<T>(Func<Dialog, bool> filterExpression = null) where T : Dialog => GetDialogByType<T>(filterExpression);
public virtual T? GetByType<T>(Func<Dialog, bool>? filterExpression = null) where T : Dialog => GetDialogByType<T>(filterExpression);

/// <inheritdoc/>
public virtual bool TryGetByType(Type dialogType, out Dialog dialog, Func<Dialog, bool> filterExpression = null)
public virtual bool TryGetByType(Type dialogType, out Dialog? dialog, Func<Dialog, bool>? filterExpression = null)
{
dialog = GetDialogByType(dialogType, filterExpression);
return dialog != null;
}

/// <inheritdoc/>
public virtual bool TryGetByType<T>(out T dialog, Func<Dialog, bool> filterExpression = null) where T : Dialog
public virtual bool TryGetByType<T>(out T? dialog, Func<Dialog, bool>? filterExpression = null) where T : Dialog
{
dialog = GetDialogByType<T>(filterExpression);
return dialog != null;
Expand Down Expand Up @@ -169,7 +169,7 @@ private static IDictionary<string, Type> BuildFromIntent(IEnumerable<Dialog> dia
return result;
}

private Dialog GetDialogByType(Type dialogType, Func<Dialog, bool> filterPredicate)
private Dialog? GetDialogByType(Type? dialogType, Func<Dialog, bool>? filterPredicate)
{
if (dialogType == null)
{
Expand All @@ -180,7 +180,7 @@ private Dialog GetDialogByType(Type dialogType, Func<Dialog, bool> filterPredica
return (serviceScope.ServiceProvider.GetServices(dialogType) as IEnumerable<Dialog>)?.FirstOrDefault(d => filterPredicate == null || filterPredicate(d));
}

private T GetDialogByType<T>(Func<Dialog, bool> filterPredicate) where T : Dialog
private T? GetDialogByType<T>(Func<Dialog, bool>? filterPredicate) where T : Dialog
{
using var serviceScope = serviceProvider.CreateScope();
return serviceScope.ServiceProvider.GetServices<T>()?.FirstOrDefault(d => filterPredicate == null || filterPredicate(d));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IDialogProvider
/// <returns>
/// A valid <see cref="Dialog"/>.
/// </returns>
Dialog GetById(string dialogId);
Dialog? GetById(string dialogId);

/// <summary>
/// Tries to get a <see cref="Dialog"/> from its unique identifier.
Expand All @@ -28,5 +28,5 @@ public interface IDialogProvider
/// <returns>
/// Returns <see langword="true"/> if a valid <see cref="Dialog"/> is found by its unique identifier; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetById(string dialogId, out Dialog dialog);
bool TryGetById(string dialogId, out Dialog? dialog);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IDialogTypeProvider
/// <returns>
/// A valid <see cref="Dialog"/>.
/// </returns>
Dialog GetByType(Type dialogType, Func<Dialog, bool> filterExpression = null);
Dialog? GetByType(Type dialogType, Func<Dialog, bool>? filterExpression = null);

/// <summary>
/// Gets a <see cref="Dialog"/> by its type from a generic type parameter.
Expand All @@ -27,7 +27,7 @@ public interface IDialogTypeProvider
/// <returns>
/// A valid <see cref="Dialog"/>.
/// </returns>
T GetByType<T>(Func<Dialog, bool> filterExpression = null) where T : Dialog;
T? GetByType<T>(Func<Dialog, bool>? filterExpression = null) where T : Dialog;

/// <summary>
/// Tries to get a <see cref="Dialog"/> from its type.
Expand All @@ -42,7 +42,7 @@ public interface IDialogTypeProvider
/// <returns>
/// Returns <see langword="true"/> if a valid <see cref="Dialog"/> is found by its type; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetByType(Type dialogType, out Dialog dialog, Func<Dialog, bool> filterExpression = null);
bool TryGetByType(Type dialogType, out Dialog? dialog, Func<Dialog, bool>? filterExpression = null);

/// <summary>
/// Tries to get a <see cref="Dialog"/> by its type from a generic type parameter.
Expand All @@ -57,7 +57,7 @@ public interface IDialogTypeProvider
/// <returns>
/// Returns <see langword="true"/> if a valid <see cref="Dialog"/> is found by its type; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetByType<T>(out T dialog, Func<Dialog, bool> filterExpression = null) where T : Dialog;
bool TryGetByType<T>(out T? dialog, Func<Dialog, bool>? filterExpression = null) where T : Dialog;
}

#pragma warning restore S2360 // Optional parameters should not be used
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IIntendedDialogProvider
/// <returns>
/// A valid <see cref="Dialog"/>.
/// </returns>
Dialog GetByIntent(string dialogIntent);
Dialog? GetByIntent(string dialogIntent);

/// <summary>
/// Tries to get a <see cref="Dialog"/> from its intent.
Expand All @@ -28,5 +28,5 @@ public interface IIntendedDialogProvider
/// <returns>
/// Returns <see langword="true"/> if a valid <see cref="Dialog"/> is found by its intent; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetByIntent(string dialogIntent, out Dialog dialog);
bool TryGetByIntent(string dialogIntent, out Dialog? dialog);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface INamedDialogProvider
/// <returns>
/// A valid <see cref="Dialog"/>.
/// </returns>
Dialog GetByName(string dialogName);
Dialog? GetByName(string dialogName);

/// <summary>
/// Tries to get a <see cref="Dialog"/> from its name.
Expand All @@ -28,5 +28,5 @@ public interface INamedDialogProvider
/// <returns>
/// Returns <see langword="true"/> if a valid <see cref="Dialog"/> is found by its name; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetByName(string dialogName, out Dialog dialog);
bool TryGetByName(string dialogName, out Dialog? dialog);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected NamedComponentDialogBase() : this(null)
/// Initializes a new instance of the <see cref="NamedComponentDialogBase"/> class.
/// </summary>
/// <param name="dialogId">The unique identifier for this dialog.</param>
protected NamedComponentDialogBase(string dialogId) : base(dialogId)
protected NamedComponentDialogBase(string? dialogId) : base(dialogId)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected NamedDialogBase() : this(null)
/// Initializes a new instance of the <see cref="NamedDialogBase"/> class.
/// </summary>
/// <param name="dialogId">The unique identifier for this dialog.</param>
protected NamedDialogBase(string dialogId) : base(dialogId)
protected NamedDialogBase(string? dialogId) : base(dialogId)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ public SendResponseResult(ResourceResponse resourceResponse)
/// <summary>
/// Gets the resource response.
/// </summary>
public ResourceResponse ResourceResponse { get; init; }
public ResourceResponse? ResourceResponse { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Encamina.Enmarcha.AI.Abstractions;
#pragma warning disable S2360 // Optional parameters should not be used

using Encamina.Enmarcha.AI.Abstractions;
using Encamina.Enmarcha.AI.QuestionsAnswering.Abstractions;

using Encamina.Enmarcha.Bot.Skills.QuestionAnswering;
Expand All @@ -11,8 +13,6 @@

using ExceptionMessages = Encamina.Enmarcha.Bot.Skills.QuestionAnswering.Resources.ExceptionMessages;

#pragma warning disable S2360 // Optional parameters should not be used

namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public QuestionAnsweringDialog(string id, QuestionAnsweringDialogServices questi
/// <inheritdoc/>
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
{
ResourceResponse response = null;
ResourceResponse? response = null;

if (dc.Context.Activity.Type == ActivityTypes.Message && !string.IsNullOrWhiteSpace(dc.Context.Activity.Text))
{
Expand All @@ -85,7 +85,7 @@ public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc,
return await dc.EndDialogAsync(response, cancellationToken);
}

private static IActivity BuildMessageActivity(string message, bool withVerbose, IEnumerable<IAnswer> answers)
private static IActivity BuildMessageActivity(string message, bool withVerbose, IEnumerable<IAnswer>? answers)
{
var activity = MessageFactory.Text(message, message);

Expand All @@ -102,7 +102,7 @@ private static bool VerboseFromTurnContextValue(ITurnContext turnContext)
return turnContext.Activity.Value is JObject activityValue && (activityValue[Constants.ActivityValueVerbose]?.Value<bool>() ?? false);
}

private async Task<QuestionRequest> BuildQuestionRequestAsync(string question, string userId, MetadataOptions metadataOptions, IEnumerable<string> sources, CancellationToken cancellationToken)
private async Task<QuestionRequest> BuildQuestionRequestAsync(string question, string userId, MetadataOptions? metadataOptions, IEnumerable<string> sources, CancellationToken cancellationToken)
{
var questionRequestOptions = new QuestionRequestOptions(sources)
{
Expand All @@ -119,7 +119,7 @@ private async Task<QuestionRequest> BuildQuestionRequestAsync(string question, s
};
}

private async Task<IEnumerable<IAnswer>> ProcessQuestionResultAsync(QuestionResult result, MetadataOptions metadataOptions, IEnumerable<string> sources, CancellationToken cancellationToken)
private async Task<IEnumerable<IAnswer>> ProcessQuestionResultAsync(QuestionResult result, MetadataOptions? metadataOptions, IEnumerable<string> sources, CancellationToken cancellationToken)
{
IEnumerable<IAnswer> answers = result.Answers;

Expand All @@ -141,7 +141,7 @@ private async Task<IEnumerable<IAnswer>> ProcessQuestionResultAsync(QuestionResu
return answers;
}

private async Task<ResourceResponse> SendAnswerAsync(IEnumerable<IAnswer> answers, ITurnContext turnContext, CancellationToken cancellationToken)
private async Task<ResourceResponse?> SendAnswerAsync(IEnumerable<IAnswer> answers, ITurnContext turnContext, CancellationToken cancellationToken)
{
var verbose = configurationOptions.Verbose || VerboseFromTurnContextValue(turnContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace Encamina.Enmarcha.Bot.Skills.QuestionAnswering;

internal record class QuestionAnsweringDialogServices(ICognitiveServiceFactory<IQuestionAnsweringService> QuestionAnsweringCognitiveServiceFactory,
IBotTelemetryClient BotTelemetryClient = null,
ISourcesProcessor SourcesProcessor = null,
IMetadataProcessor MetadataProcessor = null,
IQuestionRequestProcessor QuestionRequestProcessor = null,
IQuestionResultProcessor QuestionResultProcessor = null,
ISendAnswersProcessor SendAnswersProcessor = null,
IIntentResponsesProvider IntentResponsesProvider = null);
IBotTelemetryClient? BotTelemetryClient = null,
ISourcesProcessor? SourcesProcessor = null,
IMetadataProcessor? MetadataProcessor = null,
IQuestionRequestProcessor? QuestionRequestProcessor = null,
IQuestionResultProcessor? QuestionResultProcessor = null,
ISendAnswersProcessor? SendAnswersProcessor = null,
IIntentResponsesProvider? IntentResponsesProvider = null);
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected BotCloudAdapterWithErrorHandlerBase(IBotAdapterOptions<BotCloudAdapter
/// <summary>
/// Gets this adapter's options.
/// </summary>
protected virtual IBotAdapterOptions<BotCloudAdapterWithErrorHandlerBase> Options { get; init; }
protected virtual IBotAdapterOptions<BotCloudAdapterWithErrorHandlerBase>? Options { get; init; }

/// <summary>
/// An error handler that can catch exceptions in the middleware or application.
Expand Down
Loading

0 comments on commit 4640318

Please sign in to comment.