示例#1
0
        public async Task <bool> UpdateChatbotDetails(ChatbotDetails chatbotDetails)
        {
            var c = await Task.Run(() => db.ChatbotDetails.FirstOrDefault(X => X.chatbotId == chatbotDetails.chatbotId));

            c.chatbotName = chatbotDetails.chatbotName;
            //c.baseUrl = chatbotDetails.baseUrl;
            //c.botAutorizeTokenScheme = chatbotDetails.botAutorizeTokenScheme;
            c.BotSecret = chatbotDetails.BotSecret;
            //c.contentType = chatbotDetails.contentType;
            //c.conversationUrlExtension = chatbotDetails.conversationUrlExtension;
            //c.conversationUrlExtensionEnding = chatbotDetails.conversationUrlExtensionEnding;
            //c.isActive = chatbotDetails.isActive;
            //c.tokenUrlExtension = chatbotDetails.tokenUrlExtension;
            c.lastEdit = DateTime.Now;


            await Task.Run(() => db.ChatbotDetails.Update(c));

            if (await db.SaveChangesAsync() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        public void StartVmsAsync(ChatbotDetails details)
        {
            var vmList = _azure.VirtualMachines.List().ToList();

            if (details.RunWithCompleteLandscape)
            {
                var otherVmsToStart = vmList.Where(x => x.Tags.Any(y => y.Key.Contains("Landschaft")) && x.Tags.Values.Contains(details.LandscapeTag)).ToList();
                if (details.OnlyObligationVms)
                {
                    foreach (var virtualMachine in GetObligationVmsForLandscapeTag(details.LandscapeTag))
                    {
                        virtualMachine.StartAsync();
                    }
                }
                else
                {
                    foreach (var vm in otherVmsToStart)
                    {
                        vm.StartAsync();
                    }
                }
            }
            else
            {
                vmList.First(x => x.Name == details.VmName).StartAsync();
            }
        }
        public async Task <IActionResult> RegisterNewChatbot()
        {
            var c = new ChatbotDetails();
            List <ChatbotTypes> types = await chatbotRepository.GetAllTypes();

            c.chatbotTypes = types;
            return(View(c));
        }
示例#4
0
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                var noLuisDetails = new ChatbotDetails()
                {
                    Intent = AzureBotLuis.Intent.StartSingleVm,
                    User   = _userStateAccessors.GetAsync(stepContext.Context, cancellationToken: cancellationToken).Result
                };

                // LUIS ist nicht konfiguriert, StartVmDialog wird gestartet
                return(await stepContext.BeginDialogAsync(nameof(StartVmDialog), noLuisDetails, cancellationToken));
            }

            // Call LUIS and gather Intent and details (Note the TurnContext has the response to the prompt.)
            var luisResult = await _luisRecognizer.RecognizeAsync <AzureBotLuis>(stepContext.Context, cancellationToken);

            var details = new ChatbotDetails()
            {
                Intent = luisResult.TopIntent().intent,
                User   = _userStateAccessors.GetAsync(stepContext.Context, cancellationToken: cancellationToken).Result
            };

            //TODO LUIS weiter trainieren und dafür sorgen das mehr Entities erkannt werden (evtl auf Score eingehen?)
            details = ShowWarningForUnsupportedVms(stepContext.Context, luisResult, details, cancellationToken).Result;

            switch (luisResult.TopIntent().intent)
            {
            case AzureBotLuis.Intent.StartSingleVm:
                return(await stepContext.BeginDialogAsync(nameof(StartVmDialog), details, cancellationToken));

            case AzureBotLuis.Intent.StartVmLandscape:
                return(await stepContext.BeginDialogAsync(nameof(StartVmLandscapeDialog), details, cancellationToken));

            case AzureBotLuis.Intent.ShutDownSingleVm:
                return(await stepContext.BeginDialogAsync(nameof(ShutDownVmDialog), details, cancellationToken));

            case AzureBotLuis.Intent.ShutDownVmLandscape:
                return(await stepContext.BeginDialogAsync(nameof(ShutDownVmLandscapeDialog), details, cancellationToken));

            case AzureBotLuis.Intent.Configure:
                return(await stepContext.BeginDialogAsync(nameof(ConfigureDialog), details, cancellationToken));

            default:
                // Catch all for unhandled intents (gibt eigentlich keine unhandled intents)
                var didntUnderstandMessageText =
                    $"Sorry, I didn't get that. Please try asking in a different way (intent was {luisResult.TopIntent().intent})";
                var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken);

                break;
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }
示例#5
0
        public async Task <bool> DeleteChatbot(ChatbotDetails chatbot)
        {
            var r = db.Remove(chatbot);

            if (await db.SaveChangesAsync() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <IActionResult> RegisterNewChatbot([FromForm][Bind("chatbotName", "BotSecret")] ChatbotDetails chatbotDetails)
        {
            if (ModelState.IsValid)
            {
                var u = await chatbotRepository.RegisterNewChatbot(chatbotDetails);

                TempData["success"] = String.Format("Chatbot {0} ble registrert.", chatbotDetails.chatbotName);
                return(RedirectToAction("Chatbots"));
            }

            TempData["error"] = String.Format("Chatbot {0} ble ikke registrert.", chatbotDetails.chatbotName);
            return(View());
        }
示例#7
0
        private async Task <DialogTurnResult> ObligationOrAllStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            ChatbotDetails details = new ChatbotDetails();

            //Hier kommt er aus einem anderen Dialog zurück
            if (stepContext.Result is ChatbotDetails d)
            {
                details = d;
                if (!d.RunWithCompleteLandscape)
                {
                    return(await stepContext.EndDialogAsync(details, cancellationToken));
                }
            }
            if (stepContext.Result is bool b)
            {
                details = (ChatbotDetails)stepContext.Values["details"];
                //Frage mit ja beantwortet
                if (b)
                {
                    details.RunWithCompleteLandscape = true;
                }
                //Frage mit Nein beantwortet->keine ganze Landschaft also Dialog wieder verlassen
                else
                {
                    details.RunWithCompleteLandscape = false;
                    return(await stepContext.EndDialogAsync(details, cancellationToken));
                }
            }

            if (details.Intent == AzureBotLuis.Intent.ShutDownSingleVm)
            {
                return(await stepContext.EndDialogAsync(details, cancellationToken));
            }

            stepContext.Values["details"] = details;

            IList <Choice> choices = new List <Choice>();

            choices.Add(new Choice("Nur die notwendigen VMs"));
            choices.Add(new Choice("Alle VMs"));

            var message       = "Für welche VMs der Landschaft " + details.LandscapeTag + " soll der Vorgang durchgeführt werden?";
            var promptMessage = MessageFactory.Text(message, message, InputHints.ExpectingInput);

            return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions()
            {
                Choices = choices, Prompt = promptMessage, Style = ListStyle.SuggestedAction
            }, cancellationToken));
        }
示例#8
0
        public async void ShutDownVmsAsync(ChatbotDetails details)
        {
            var vmList = _azure.VirtualMachines.List().ToList();

            if (details.RunWithCompleteLandscape)
            {
                var vmsToShutDown = vmList.Where(x => x.Tags.Any(y => y.Key.Contains("Landschaft")) && x.Tags.Values.Contains(details.LandscapeTag.Replace("Landschaft ", ""))).ToList();
                foreach (var vm in vmsToShutDown)
                {
                    await vm.DeallocateAsync();
                }
            }
            else
            {
                await vmList.First(x => x.Name == details.VmName).DeallocateAsync();
            }
        }
        public async Task <IActionResult> UpdateChatbotDetails([FromForm][Bind("chatbotId", "chatbotName", "contentType", "BotSecret",
                                                                               "baseUrl", "tokenUrlExtension", "conversationUrlExtension", "botAutorizeTokenScheme", "isActive")] ChatbotDetails chatbotDetails)
        {
            //if (ModelState.IsValid)
            //{
            var c = await chatbotRepository.UpdateChatbotDetails(chatbotDetails);

            if (c)
            {
                TempData["success"] = String.Format("Chatbot {0} ble oppdatert.", chatbotDetails.chatbotName);
                return(RedirectToAction("Chatbots"));
            }
            TempData["error"] = String.Format("Chatbot {0} ble ikke oppdatert.", chatbotDetails.chatbotName);
            return(RedirectToAction("Chatbots"));
            //}

            //TempData["error"] = String.Format("modelstate unvalid for {0}", chatbotDetails.chatbotName);
            //return RedirectToAction("Chatbots");
        }
示例#10
0
 public async Task <bool> RegisterNewChatbot(ChatbotDetails chatbotDetails)
 {
     chatbotDetails.contentType = "application/json";
     chatbotDetails.baseUrl     = "https://directline.botframework.com";
     chatbotDetails.conversationUrlExtension       = "/v3/directline/conversations/";
     chatbotDetails.conversationUrlExtensionEnding = "/activities";
     chatbotDetails.tokenUrlExtension      = "/v3/directline/tokens/generate";
     chatbotDetails.botAutorizeTokenScheme = "Bearer";
     chatbotDetails.regDate  = DateTime.Now;
     chatbotDetails.lastEdit = DateTime.Now;
     chatbotDetails.isActive = false;
     db.ChatbotDetails.Add(chatbotDetails);
     if (await db.SaveChangesAsync() < 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#11
0
    private static async Task AddChatbot(ApplicationDbContext context)
    {
        var chatbot1 = new ChatbotDetails
        {
            regDate     = DateTime.Now,
            lastEdit    = DateTime.Now,
            chatbotName = "Svarta Bjørn 1",
            TypeId      = 2,
            isActive    = false,
            contentType = "application/json",
            baseUrl     = "https://directline.botframework.com",
            conversationUrlExtensionEnding = "/activities",
            tokenUrlExtension        = "/v3/directline/tokens/generate",
            conversationUrlExtension = "/v3/directline/conversations/",
            botAutorizeTokenScheme   = "Bearer",
            BotSecret = "SGOlKUQmphg.cwA.0ho.CYEuXR9VGPjZ19d7n7zKKjSYpVamhVYgh7qEdE_gxn0"
        };
        await context.AddAsync(chatbot1);

        await context.SaveChangesAsync();

        var chatbot2 = new ChatbotDetails
        {
            regDate     = DateTime.Now,
            lastEdit    = DateTime.Now,
            chatbotName = "Svarta Bjørn 2",
            TypeId      = 2,
            isActive    = true,
            contentType = "application/json",
            baseUrl     = "https://directline.botframework.com",
            conversationUrlExtensionEnding = "/activities",
            tokenUrlExtension        = "/v3/directline/tokens/generate",
            conversationUrlExtension = "/v3/directline/conversations/",
            botAutorizeTokenScheme   = "Bearer",
            BotSecret = "U3uIHr5dEVY.cwA.PbQ.IUlQuQsWrZHAg2wX4qM3wDa6i7W8buvXaGiSgFIAkRg"
        };
        await context.AddAsync(chatbot2);

        await context.SaveChangesAsync();
    }
示例#12
0
        //endRegion Steps

        #region Methods

        private static async Task <ChatbotDetails> ShowWarningForUnsupportedVms(ITurnContext context, AzureBotLuis luisResult, ChatbotDetails details, CancellationToken cancellationToken)
        {
            var unsupportedVms          = new List <string>();
            var unsupportedVmLandscapes = new List <string>();
            var azureHandler            = new AzureHandler(details.User.Tenant, details.User.TokenResponse.Token);

            if (luisResult.Entities.VmLandscapeName != null)
            {
                if (!string.IsNullOrWhiteSpace(luisResult.Entities.VmLandscapeName[0]))
                {
                    var vmsWithLuisLandscapeTag = azureHandler.GetListOfVms().Where(x => x.Tags.Any(y => y.Key == "Landschaft" && y.Value == luisResult.Entities.VmLandscapeName[0]));

                    if (vmsWithLuisLandscapeTag.Any())
                    {
                        details.LandscapeTag             = luisResult.Entities.VmLandscapeName[0];
                        details.RunWithCompleteLandscape = true;
                    }
                    else
                    {
                        unsupportedVmLandscapes.Add(luisResult.Entities.VmLandscapeName[0]);
                    }
                }
            }

            if (luisResult.Entities.VmName != null)
            {
                if (!string.IsNullOrWhiteSpace(luisResult.Entities.VmName[0]))
                {
                    var listOfVms = azureHandler.GetListOfVms().Select(x => x.Name).ToList();
                    if (listOfVms.Any(x => x == luisResult.Entities.VmName[0]))
                    {
                        details.VmName = luisResult.Entities.VmName[0];
                    }
                    else
                    {
                        unsupportedVms.Add(luisResult.Entities.VmName[0]);
                    }
                }
            }


            if (details.Intent == AzureBotLuis.Intent.StartSingleVm || details.Intent == AzureBotLuis.Intent.StartVmLandscape)
            {
                if (unsupportedVms.Any() || unsupportedVmLandscapes.Any())
                {
                    var messageText = "Du hast eine Vm oder Landschaft angegeben die nicht in deinem Azure Account zu finden war.";
                    var message     = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput);
                    await context.SendActivityAsync(message, cancellationToken);

                    foreach (var unsupportedLandscape in unsupportedVmLandscapes)
                    {
                        if (azureHandler.GetListOfVms().FirstOrDefault(x => x.Name == unsupportedLandscape) != null)
                        {
                            details.Intent = AzureBotLuis.Intent.StartSingleVm;
                            details.VmName = unsupportedLandscape;

                            var messageText2 = "Stattdessen wurde eine VM mit dem selben Namen gefunden. Ich gehen davon aus, das du diese gemeint hast.";
                            var message2     = MessageFactory.Text(messageText2, messageText2, InputHints.IgnoringInput);
                            await context.SendActivityAsync(message2, cancellationToken);
                        }
                    }

                    foreach (var unsupportedVm in unsupportedVms)
                    {
                        if (azureHandler.GetAllAvailableLandscapes().FirstOrDefault(x => x == unsupportedVm) != null)
                        {
                            details.Intent       = AzureBotLuis.Intent.StartVmLandscape;
                            details.LandscapeTag = unsupportedVm;

                            var messageText2 = "Stattdessen wurde eine Landschaft mit dem selben Namen gefunden. Ich gehen davon aus, das du diese gemeint hast.";
                            var message2     = MessageFactory.Text(messageText2, messageText2, InputHints.IgnoringInput);
                            await context.SendActivityAsync(message2, cancellationToken);
                        }
                    }
                }
            }

            if (details.Intent == AzureBotLuis.Intent.ShutDownSingleVm || details.Intent == AzureBotLuis.Intent.ShutDownVmLandscape)
            {
                if (unsupportedVms.Any() || unsupportedVmLandscapes.Any())
                {
                    var messageText = "Du hast eine Vm oder Landschaft angegeben die nicht in deinem Azure Account zu finden sind.";
                    var message     = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput);
                    await context.SendActivityAsync(message, cancellationToken);

                    foreach (var unsupportedLandscape in unsupportedVmLandscapes)
                    {
                        if (azureHandler.GetListOfVms().FirstOrDefault(x => x.Name == unsupportedLandscape) != null)
                        {
                            details.Intent = AzureBotLuis.Intent.ShutDownSingleVm;
                            details.VmName = unsupportedLandscape;

                            var messageText2 = "Stattdessen wurde eine VM mit dem selben Namen gefunden. Ich gehen davon aus, das du diese gemeint hast.";
                            var message2     = MessageFactory.Text(messageText2, messageText2, InputHints.IgnoringInput);
                            await context.SendActivityAsync(message2, cancellationToken);
                        }
                    }

                    foreach (var unsupportedVm in unsupportedVms)
                    {
                        if (azureHandler.GetAllAvailableLandscapes().FirstOrDefault(x => x == unsupportedVm) != null)
                        {
                            details.Intent       = AzureBotLuis.Intent.ShutDownVmLandscape;
                            details.LandscapeTag = unsupportedVm;

                            var messageText2 = "Stattdessen wurde eine Landschaft mit dem selben Namen gefunden. Ich gehen davon aus, das du diese gemeint hast.";
                            var message2     = MessageFactory.Text(messageText2, messageText2, InputHints.IgnoringInput);
                            await context.SendActivityAsync(message2, cancellationToken);
                        }
                    }
                }
            }

            return(details);
        }