public static void Main(string[] args) { var quest = new Questionnaire { Title = "When to write a Templater plugin?" }; quest.Add( "When should a formatting plugin be used?", "When a simple value conversion is required", new[] { "When a custom data type is required", "To improve performance", "It should never be used. All possible scenarios are already covered" }); quest.Add( "When should a metadata plugin be used?", "To implement common features, such as region collapse", new[] { "When a custom data type is required", "To improve performance", "It should never be used. All possible scenarios are already covered" }); quest.Add( "When should a processor plugin be used?", "When a custom data type is required", new[] { "When a simple value conversion is required", "To improve performance", "It should never be used. All possible scenarios are already covered" }); var factory = Configuration.Builder .Include <Questionnaire>(ProcessQuestionnaire) .Include(FormatDate) .Include(Letter) .WithMatcher(@"[\w\.]+") .Build(); using (var input = new FileStream("template/questions.docx", FileMode.Open)) using (var output = new FileStream("questionnaire.docx", FileMode.Create)) using (var doc = factory.Open(input, output, "docx")) { doc.Process(new { Date = DateTime.Now, Q = quest, Reason = "Example", Authors = new[] { "Mark", "Jane", "Jack" } }); } Process.Start(new ProcessStartInfo("questionnaire.docx") { UseShellExecute = true }); }
public void TestMethod1() { //создаем опросник var questionnaire = new Questionnaire(); //создаем вопрос var quest = new Quest { Id = "A1", Title = "Заголовок вопроса" }; //создаем альтренативу var alt = new Alternative { Code = 1, Title = "Вариант1" }; //добавляем альтернативу в вопрос quest.Add(alt); //добавляем вопрос в опросник questionnaire.Add(quest); //сохраняем опросник в файл SaverLoader.Save(questionnaire, "c:\\temp.q"); //читаем опросник из файла var loadedQuestionnaire = SaverLoader.Load <Questionnaire>("c:\\temp.q"); //проверяем число вопросов и альтернатив в загруженном опроснике Assert.AreEqual(loadedQuestionnaire.Count, questionnaire.Count); Assert.AreEqual(loadedQuestionnaire[0].Count, questionnaire[0].Count); }
public void SetQuestionnaire() { string[] questions = { "CQ01", "CQ02", "CQ03", "CQ04", "CQ05", "CQ06", "CQ07" }; questions.ToList().ForEach(x => { if (!Questionnaire.Keys.Contains(x)) { Questionnaire.Add(x, 0); } }); }
static void Main(string[] args) { var quest = new Questionnaire { Title = "When to write a Templater plugin?" }; quest.Add( "When should a formatting plugin be used?", "When a simple value conversion is required", new[] { "When a custom data type is required", "To improve performance", "It should never be used. All possible scenarios are already covered" }); quest.Add( "When should a metadata plugin be used?", "To implement common features, such as region collapse", new[] { "When a custom data type is required", "To improve performance", "It should never be used. All possible scenarios are already covered" }); quest.Add( "When should a processor plugin be used?", "When a custom data type is required", new[] { "When a simple value conversion is required", "To improve performance", "It should never be used. All possible scenarios are already covered" }); var factory = Configuration.Builder .Include <Questionnaire>(ProcessQuestionnaire) .Include(FormatDate) .Build(); using (var input = new FileStream("questions.docx", FileMode.Open)) using (var output = new FileStream("result.docx", FileMode.Create)) using (var doc = factory.Open(input, output, "docx")) { doc.Process(new { Date = DateTime.Now, Q = quest }); } Process.Start("result.docx"); }
public static void Main(string[] args) { var quest = new Questionnaire { Title = "When to write a Templater plugin?" }; quest.Add( "When should a formatting plugin be used?", "When a simple value conversion is required", new[]{ "When a custom data type is required", "To improve performance", "It should never be used. All possible scenarios are already covered"}); quest.Add( "When should a metadata plugin be used?", "To implement common features, such as region collapse", new[]{ "When a custom data type is required", "To improve performance", "It should never be used. All possible scenarios are already covered"}); quest.Add( "When should a processor plugin be used?", "When a custom data type is required", new[]{ "When a simple value conversion is required", "To improve performance", "It should never be used. All possible scenarios are already covered"}); var factory = Configuration.Builder .Include<Questionnaire>(ProcessQuestionnaire) .Include(FormatDate) .Build(); using (var input = new FileStream("questions.docx", FileMode.Open)) using (var output = new FileStream("questionnaire.docx", FileMode.Create)) using (var doc = factory.Open(input, output, "docx")) { doc.Process(new { Date = DateTime.Now, Q = quest }); } Process.Start("questionnaire.docx"); }
public void TestMethod3() { //создаем опросник var questionnaire = new Questionnaire(); //создаем вопросы с одинаковыми именами questionnaire.Add(new Quest { Id = "A1", Title = "Заголовок вопроса" }); questionnaire.Add(new Quest { Id = "A1", Title = "Заголовок вопроса" }); //запускаем валидатор try { new QuestionnaireValidator().Validate(questionnaire); Assert.Fail("Validator passes duplicates"); } catch { //все ок } }
public void SetQuestionnaire() { string[] qs1 = { "PQ01", "PQ02", "PQ03", "PQ04", "PQ05", "PQ06" }; string[] qs2 = { "PQ07", "PQ08", "PQ09", "PQ10", "PQ11", "PQ12", "PQ13", "PQ14" }; string[] qs3 = { "PQ15", "PQ16", "PQ17", "PQ18", "PQ19", "PQ20" }; string[] qs4 = { "PQ21", "PQ22", "PQ23", "PQ24", "PQ25", "PQ26", "PQ27", "PQ28", "PQ29" }; string[] qs5 = { "PQ30", "PQ31", "PQ32", "PQ33", "PQ34", "PQ35", "PQ36", "PQ37", "PQ38", "PQ39" }; var qs = qs1.Union(qs2).Union(qs3).Union(qs4).Union(qs5).ToList(); qs.ForEach(x => { if (!Questionnaire.Keys.Contains(x)) { Questionnaire.Add(x, 0); } }); }
/// <summary> /// Добавить новый вопрос /// </summary> public Quest AddNewQuest(Questionnaire questionnaire) { //подбираем уникальное имя вопроса var counter = 1; var name = DefaultQuestPrefix + counter; while (questionnaire.Any(q => q.Id == name))//увеличиваем счетчик, пока не найдем имени, которого еще нет в опроснике { counter++; name = DefaultQuestPrefix + counter; } // var quest = new Quest() { Id = name, Title = "Текст вопроса" }; questionnaire.Add(quest); return(quest); }
public void TestMethod4() { //создаем опросник var questionnaire = new Questionnaire(); //создаем вопросы questionnaire.Add(new Quest { Id = "A1" }); questionnaire.Add(new Quest { Id = "A2" }); //создакем калькулятор var calc = new ConditionCalculator(); //проверка синтаксиса с ошибкой try { calc.Check(questionnaire, "A1 - 23"); calc.Check(questionnaire, "A1 = 2 + "); Assert.Fail("Calculator.Check() false positive"); } catch { //все ок } //проверка несуществующих вопросов try { calc.Check(questionnaire, "A23 = 1"); Assert.Fail("Calculator.Check() false positive"); } catch { //все ок } //проверка корректных выражений var anketa = new Anketa(); anketa.Add(new Answer { QuestId = "A1", AlternativeCode = 1 }); anketa.Add(new Answer { QuestId = "A2", AlternativeCode = 1 }); anketa.Add(new Answer { QuestId = "A3", Text = "YES" }); Assert.IsTrue(calc.Calculate(anketa, new Condition { Expression = "A1 = 1" })); Assert.IsTrue(calc.Calculate(anketa, new Condition { Expression = "A1 = A2" })); Assert.IsTrue(calc.Calculate(anketa, new Condition { Expression = "A3 <> 'NO'" })); Assert.IsTrue(calc.Calculate(anketa, new Condition { Expression = "A1 + A2 = 2" })); Assert.IsTrue(calc.Calculate(anketa, new Condition { Expression = "(A1 = 1) and (A3 = 'YES')" })); Assert.IsTrue(calc.Calculate(anketa, new Condition { Expression = "(A1 = 5) or (A3 = 'YES')" })); }
public static void Main(string[] args) { var terminal = new UserTerminal(); IQuestionnaire questionnaire = new Questionnaire(terminal); questionnaire.Settings.WelcomeMessage = "Welcome to my questionnaire"; bool Validator(IQuestion x) => x.Answer.Length > 0; var errorMessage = "Please Provide a value"; IQuestionBuilder builder = new QuestionBuilder(); var askName = builder.Simple().Text("What's your name?").Build(); var askFamily = builder.Simple().Text("What's your family?").AddValidation(Validator, errorMessage).Build(); builder.List() .Text("What's your favorite language?") .AddOptions(new [] { new QuestionOption("Persian"), new QuestionOption("English"), new QuestionOption("Italian"), new QuestionOption("Spanish"), new QuestionOption("French"), new QuestionOption("German") }) .WithHint("Persian") .WithDefaultAnswer("Persian") .AddValidation(x => x.Answer != null) //.AsCheckList( ) .WithErrorMessage("You must select an option") .AddToQuestionnaire(questionnaire) ; questionnaire .Add(askName) .Add(askFamily) ; questionnaire.Start(); var add = true; // loop until there is a question to ask while (questionnaire.CanProceed) { if (add) { var confirm = builder.Simple() .Text("Are you older than 18?") .AsConfirm() .WithHint("Y/n") .WithDefaultAnswer("y") .AddValidation(x => { var q = (Confirm)x; return(q.PossibleAnswers.Contains(x.Answer)); }, "Your value should be either 'y' or 'n'") .Build(); confirm.Finish(q => { if (q.Answer != "y") { return; } var agePrompt = builder.Simple() .Text("How old are you?") .AddValidation(x => { int.TryParse(x.Answer, out var age); return(age >= 18); }, "Your must be older than 18") .Build(); questionnaire.Prompt(agePrompt as Prompt); }); questionnaire.Confirm(confirm as Confirm); add = false; } questionnaire.Next(); } questionnaire.End(); // Print Processed questions foreach (var q in questionnaire.ProcessedQuestions) { terminal.Printer.Write($"{q.Text} : {q.Answer}"); terminal.Printer.WriteLine(); } Console.ReadLine(); }