有没有办法使该方法适合于覆盖?

时间:2020-10-14 14:19:17

标签: c# methods botframework overriding

我已经在我的机器人内部基于Microsoft Bot Framework v4(c#)实现了转录功能。对于存储类型,我使用了Azure表存储。一切正常。从那里我希望机器人严格从App Service的“配置”选项卡中获取对存储的访问凭据。

但是在我实现了这一点之后,它说我的方法不再适合重写。

protected override async Task OnMessageActivityAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            // First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
            var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);

            // Top intent tell us which cognitive service to use.
            var topIntent = recognizerResult.GetTopScoringIntent();

            // Next, we call the dispatcher with the top intent.
            await DispatchToTopIntentAsync(configuration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
        }

我在OnMessageActivityAsync方法中添加配置参数后,出现此错误。但是我在那里需要参数,因为我在DispatchToTopIntentAsync中使用了它:

// Suche nach der richtigen KnowledgeBase
        private async Task DispatchToTopIntentAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
        {
            switch (intent)
            {
                case "q_SEKAI_Allgemein":
                    await ProcessSEKAI_AllgemeinAsync(configuration, turnContext, cancellationToken);
                    break;
                case "q_SEKAI_HomeOffice":
                    await ProcessSEKAI_HomeOfficeAsync(configuration, turnContext, cancellationToken);
                    break;
                case "q_SEKAI_MixedReality":
                    await ProcessSEKAI_MixedRealityAsync(configuration, turnContext, cancellationToken);
                    break;

                default:
                    // Wird ausgeführt, wenn keine KnowledgeBase gefunden wird
                    _logger.LogInformation($"Dispatch unrecognized intent: {intent}.");

                    await TableStorageEintrag(configuration, turnContext, cancellationToken);
                    break;
            }
        }

在这一部分中,机器人决定哪种知识库最适合进行进一步的工作。

但是我该如何解决此问题?随时询问您是否需要更多信息。然后,我将尽快编辑我的帖子:)

enter image description here

(此屏幕快照指的是这篇文章的答案)

1 个答案:

答案 0 :(得分:3)

您不能更改基本虚拟类的参数,并希望覆盖它。 正确的签名如下,MSDN

protected virtual Task OnMessageActivityAsync(
    ITurnContext<IMessageActivity> turnContext,
    CancellationToken cancellationToken);

您可以在类的构造函数中注入IConfigration

private readonly IConfiguration _iConfiguration;
// Inject it here
public ConstructorOfYourClass(IConfiguration iConfiguration) {
    _iConfiguration = iConfiguration;
}

protected override async Task OnMessageActivityAsync(
    ITurnContext<IMessageActivity> turnContext,
    CancellationToken cancellationToken) {
        .......
    // Use it here
    await DispatchToTopIntentAsync(_iConfiguration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
}