Esempio n. 1
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            AppInsightsTelemetryClient.GetInstance();

            try
            {
                StringDictionary parameters = new StringDictionary
                {
                    ["connectionString"] = ConfigurationManager.AppSettings["MongoDBStringConnection"],
                    ["mongoDbName"]      = ConfigurationManager.AppSettings["MongoDBName"],
                    ["documentDbName"]   = ConfigurationManager.AppSettings["DocumentDBName"],
                    ["authKey"]          = ConfigurationManager.AppSettings["DocumentDBAuthKey"],
                    ["endPoint"]         = ConfigurationManager.AppSettings["DocumentDBEndPoint"]
                };

                if (Enum.TryParse <DAL.DBType>(ConfigurationManager.AppSettings["DBType"], out DAL.DBType dbt))
                {
                    SharedObjects.DatabaseManager = DBManagerFactory.GetInstance(dbt, parameters);
                }
                else
                {
                    throw new ConfigurationErrorsException("Valor de DBType Incorrecto en el archivo de configuración");
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning($"El servicio de Bot funciona pero no la conexión a la base de datos de preguntas no fue posible: {ex}");
            }
        }
Esempio n. 2
0
        protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context,
                                                                     IMessageActivity message,
                                                                     QnAMakerResults result)
        {
            var answers = GetAnswerData(result);
            var counter = answers.Count();

            if (counter == 0)
            {
                if (isComingFromLuis)
                {
                    AppInsightsTelemetryClient.TrackEvent(message.Id);
                    AppInsightsTelemetryClient.InsertTransaction(context.Activity as IMessageActivity,
                                                                 originalQuestion, 0, 0, SharedObjects.NO_RESULT_ANSWER_IN_DB, (context.Activity as IMessageActivity).Text,
                                                                 AnswerType.noAnswer);
                    typeResultInQnA = SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA_AND_LUIS;
                }

                else
                {
                    typeResultInQnA = SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA;
                }
            }
            else
            {
                typeResultInQnA = SharedObjects.ResultFromQnA.RESULT_FROM_QNA;

                AppInsightsTelemetryClient.TrackEvent(message.Id);
                AppInsightsTelemetryClient.InsertTransaction(context.Activity as IMessageActivity,
                                                             originalQuestion, counter, answers[0].Score, answers[0].Questions[0],
                                                             (isComingFromLuis ? message.Text : "None"),
                                                             (isComingFromLuis ? AnswerType.QnALuis : AnswerType.QnA));

                var carrusel = context.MakeMessage();
                carrusel.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                var options = new List <Attachment>();

                if (counter == 1)
                {
                    await context.PostAsync($"I found 1 answer:");
                }
                else
                {
                    await context.PostAsync($"Are any of these {counter} answers helpful?");
                }

                foreach (var qnaMakerResult in answers)
                {
                    options.Add(CreateCard(qnaMakerResult));
                }

                carrusel.Attachments = options;

                await context.PostAsync(carrusel);
            }
        }
Esempio n. 3
0
        private async Task AfterQnADialog(IDialogContext context, IAwaitable <object> result)
        {
            var    message         = context.Activity as IMessageActivity;
            string typeResultInQnA = (await result as Activity).Text;

            switch (typeResultInQnA)
            {
            case SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA:
                QnADialog dialog = new QnADialog();
                dialog.isComingFromLuis = true;


                string LuisAnswer = GetLuisAnswer(message.Text, out double score);

                if (LuisAnswer == "None")
                {
                    await context.PostAsync(SharedObjects.NO_RESULT_ANSWER);

                    AppInsightsTelemetryClient.TrackEvent(message.Id);
                    AppInsightsTelemetryClient.InsertTransaction(message, message.Text, 0, score, SharedObjects.NO_RESULT_ANSWER_IN_DB, LuisAnswer, AnswerType.noAnswer);
                }
                else
                {
                    dialog.originalQuestion = message.Text;
                    message.Text            = LuisAnswer;
                    await context.Forward(dialog, AfterQnADialog, message);
                }
                break;

            case SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA_AND_LUIS:
                await context.PostAsync(SharedObjects.NO_RESULT_ANSWER);

                break;

            default:
                context.Done(this);
                break;
            }
        }
Esempio n. 4
0
        public static async Task Main(string[] args)
        {
            // load configuration
            DotEnv.Config(false);

            // Wait until the app unloads or is cancelled by external triggers, use it for exceptional scnearios only.
            using (var cts = new CancellationTokenSource())
            {
                // Wait until the app unloads or is cancelled
                AssemblyLoadContext.Default.Unloading += (ctx) => cts.Cancel();
                Console.CancelKeyPress += (sender, cpe) => cts.Cancel();

                var configuration = new ConfigurationBuilder()
                                    .SetBasePath(Environment.CurrentDirectory)
                                    .AddJsonFile("local.settings.json", true)
                                    .AddEnvironmentVariables()
                                    .Build();

                // Bootstrap services using dependency injection.
                var services = new ServiceCollection();
                services.AddLogging(configure =>
                {
                    configure.AddProvider(new SingleLineConsoleLoggerProvider());
                })
                .Configure <LoggerFilterOptions>(options =>
                {
                    string logLevel = configuration.GetValue <string>("LOG_LEVEL");
                    if (Enum.TryParse(logLevel, out Microsoft.Extensions.Logging.LogLevel level))
                    {
                        options.MinLevel = level;
                    }
                    else
                    {
                        options.MinLevel = Microsoft.Extensions.Logging.LogLevel.Information;
                    }
                });
                ITelemetryClient telemetry = new AppInsightsTelemetryClient(configuration);
                services.AddSingleton <ITelemetryClient>(telemetry);
                services.AddSingleton <EnrichmentMessageRouter>();
                services.AddSingleton <IDataSource>(new TestGeneratorDataSource());
                var provider = services.BuildServiceProvider();
                services.AddSingleton <IDataSink>(new BlackHoleDataSink(provider.GetService <ILogger <BlackHoleDataSink> >()));

                var protocol = configuration.GetValue <string>("PROTOCOL");
                if (string.Compare(protocol, "GRPC", true) == 0)
                {
                    services.AddSingleton <IIoTDeviceDataEnricher>(new IoTDeviceGrpcDataEnricher(telemetry, configuration, provider.GetService <ILogger <IoTDeviceGrpcDataEnricher> >()));
                }
                else
                {
                    services.AddSingleton <IIoTDeviceDataEnricher>(new IoTDeviceRestfulDataEnricher(telemetry, configuration, provider.GetService <ILogger <IoTDeviceRestfulDataEnricher> >()));
                }

                services.AddSingleton <IConfiguration>(configuration);

                // Dispose method of ServiceProvider will dispose all disposable objects constructed by it as well.
                using (var serviceProvider = services.BuildServiceProvider())
                {
                    // Get a new message router object.
                    var messagerouter   = serviceProvider.GetService <EnrichmentMessageRouter>();
                    var telemetryClient = serviceProvider.GetService <ITelemetryClient>();
                    telemetryClient.TrackEvent($"MessageRouter starting up on {Environment.MachineName}");
                    await messagerouter.Initiate(cts.Token);
                }
            }
        }