private async Task <string> ReplaceConsoleInput(string codeInput) { var tempCode = codeInput; var inputDictionary = new Dictionary <int, DataInputFormStringField>(); var readLineIndexes = tempCode.AllIndexesOf(ReadlinePattern); var regex = new Regex(Regex.Escape(ReadlinePattern)); var inputForm = new ModalDataInputForm("User Inputs", "User console input"); for (int i = 1; i <= readLineIndexes.Count(); i++) { string userInput = ""; var inputField1 = inputForm.AddStringField($"Input{i}", $"{ReadlinePattern} {i}", userInput, "The user's input."); inputDictionary.Add(i, inputField1); } if (await inputForm.ShowAsync(ModalService)) { int j = 1; tempCode = regex.Replace(tempCode, m => { var input = inputDictionary[j].Value; Console.WriteLine($"Console.ReadLine() replaced with \"{input}\""); j++; return($"\"{input}\""); }); } var code = tempCode; return(code); }
protected async Task AddChapter() { if (OneQuiz.Id == 0) { var response = await ModalDialog.ShowMessageBoxAsync("Question", "Do you want to save this new quiz ?", MessageBoxButtons.YesNo); if (response == MessageBoxDialogResult.No) { return; } var result = await TrySavingChanges(); if (result == false) { return; } } ModalDataInputForm frm = new ModalDataInputForm("Add chapter", "Please give a title"); var titleFld = frm.AddStringField("title", "Title", "", "The title of the chapter"); if (await frm.ShowAsync(ModalDialog)) { var chapter = new Chapter { Title = titleFld.Value, QuizTopicId = OneQuiz.Id }; var addedChapter = await ChapterService.AddChapter(chapter); if (OneQuiz.Chapters == null) { OneQuiz.Chapters = new List <Chapter>(); } OneQuiz.Chapters.Add(addedChapter); StateHasChanged(); } }
private async Task SaveUserSnippet(string snippet) { if (!AppState.HasUser) { var result = await ModalService.ShowDialogAsync <LoginProvider>("Sign-in to Save"); if (!result.Success) { return; } } var inputForm = new ModalDataInputForm("Save User Snippet", "what should we call this code snippet?"); var snippetField = inputForm.AddStringField("Name", "Snippet Name", ""); string snippetName = ""; var options = new ModalDialogOptions() { Style = "small-modal" }; if (await inputForm.ShowAsync(ModalService, options)) { snippetName = snippetField.Value; } var newSnippet = new UserSnippet { Name = snippetName, Snippet = snippet }; var userData = AppState.UserAppData; userData.Snippets.Add(newSnippet); AppState.UpdateUserAppData(userData); var requestResult = await PublicClient.AddUserSnippet(AppState.UserName, newSnippet); isSnippetSaving = false; message = requestResult ? $"Successfully saved snippet: {snippetName}" : "Save snippet failed"; StateHasChanged(); }