void OpenTest_Click(object sender, EventArgs e) { if (CreateTestWindow.ShowDialog() == DialogResult.OK) { using (StreamReader file = new StreamReader(CreateTestWindow.FileName, Encoding.Unicode)) { while (!file.EndOfStream) //Reading till end of file { string line = file.ReadLine(); List <Answer> answers = new List <Answer>(); byte m = 0; string[] elements = new string[3]; for (int i = 0; i < line.Length; i++) //Reading all line { if (i + 2 < line.Length && line.Substring(i, 3) == "<<<") { i += 3; for (int j = i; j + 2 < line.Length && line.Substring(j, 3) != ">>>"; j++) //Finding elements { elements[m] += line[j]; } if (m == 2) { bool AnswerOrCorrect = true, AnswerIsCorrect = false; string tmp = "", tmp2 = ""; for (int j = 0; j <= elements[2].Length; j++) //Reading answers { if ((j < elements[2].Length - 3 && elements[2].Substring(j, 3) == "|||") || j == elements[2].Length) //Checking is this element is answer or correction of answer { if (AnswerOrCorrect) { AnswerOrCorrect = false; j += tmp2.Length + 2; } else { AnswerOrCorrect = true; if (tmp2 == "True") { AnswerIsCorrect = true; } else if (tmp2 == "False") { AnswerIsCorrect = false; } if (j == elements[2].Length - 1) { break; } answers.Add(new Answer(AnswerIsCorrect, tmp)); tmp = ""; tmp2 = ""; j += tmp.Length + 2; } } else { if (AnswerOrCorrect) { tmp += elements[2][j]; } else { tmp2 += elements[2][j]; } } } } i += elements[m].Length; if (m < 3) { m++; } else { m = 0; } } } Questions.Add(new Question(elements[0], ToBoolean(elements[1]))); //Now we're adding our questions into a list Questions[Questions.Count - 1].Answers = answers; } } QuestionIndex.Value = 0; basic_showing.Invoke(); } }
public void ShowCreateTestWindow() { if (this.holoScriptApp == null) return; this.holoScriptApp.PauseApplication(); int index = 0; ListViewItem selectedItem; if (this.lv_LogInformation.SelectedItems.Count > 0) selectedItem = this.lv_LogInformation.SelectedItems[0]; else selectedItem = null; CreateTestWindow window; // get the function from the database if (selectedItem != null) { String functionStr = selectedItem.SubItems[3].Text; InterceptedFunction function = InterceptedFunctionDB.GetInstance("functions.xml").GetFunctionByName(functionStr); if (function == null) { MessageBox.Show(this, "Function " + functionStr + " not defined in the function database."); this.holoScriptApp.ResumeApplication(); return; } // get the parameters string from the list view String paramStr = selectedItem.SubItems[6].Text; String[] splitParamStrings = paramStr.Split(','); // remove any leading spaces index = 0; foreach (String p in splitParamStrings) { splitParamStrings[index] = p.Trim(); index++; } // set the default values of each test parameter if (function != null) { int paramIndex = 0; foreach (InterceptedFunctionParameter fp in function.Parameters) { if (splitParamStrings != null) fp.TestValue = splitParamStrings[paramIndex]; else fp.TestValue = null; paramIndex++; } } window = new CreateTestWindow(function); } else window = new CreateTestWindow(null); if (selectedItem != null) { String rv = selectedItem.SubItems[4].Text; window.ReturnValue = (rv == null) ? "0" : rv; String ec = selectedItem.SubItems[5].Text; window.ErrorCode = (ec == null) ? "0" : ec; } else { window.ErrorCode = "0"; window.ReturnValue = "0"; } window.ShowDialog(); while ( (window.FunctionName == null) || (window.DialogResult != DialogResult.OK) ) { if (window.DialogResult != DialogResult.OK) { this.holoScriptApp.ResumeApplication(); return; } else if (window.FunctionName == null) { MessageBox.Show("Please choose a function to test", "Create a Test"); window.ShowDialog(); } } string testID = null; string section = window.Section; string testFunction = window.FunctionName; string action = window.Action; int numParams = window.NumApplicableParams; Array AppParamValues = window.ApplicableParamValues; Array AppParams = window.ApplicableParams; Array AppTypes = window.ApplicableParamTypes; Array AppPos = window.ApplicableParamPos; //make sure we capture changes made in the dlg string[] actionArray = action.Split(' '); string newReturnValue = actionArray[0]; string newErrorCode = actionArray[1]; string newParamStr = ""; // Convert the error string into an error code string strErrorCode = null; if (actionArray.Length > 0) strErrorCode = ErrorCodeDB.GetInstance().GetCodeFromString(actionArray[1]); if (strErrorCode != null) { action = actionArray[0] + ' '; action += strErrorCode; } index = 1; foreach (string param in AppParamValues) { if (index != AppParamValues.Length) newParamStr += param + ", "; else newParamStr += param; index++; } if (testFunction.Trim().CompareTo("") != 0) //this.holoScriptApp.CreateScheduledTest(section, testFunction, action, numParams, AppParamValues, AppTypes, AppPos, ref testID); //if testid is new then a new entry will be created, otherwise the existing one will be altered AddScheduledTestItem(testFunction, newErrorCode, newReturnValue, newParamStr, testID); this.holoScriptApp.ResumeApplication(); }
//************************************************************************* // Method: ModifyTest // // Description: Worker function for modifying an existing test. Called by // right clicking or double clicking a scheduled test in the list view // // Parameters: // functionName - string that contains the function name // paramStr - string that contains a comma delimeted list of parameter values to the function // returnValue - string that contains the return value // errorCode - string that contains the error code // testID - string that contains the unique testID for this test // // Return Value: none //************************************************************************* private void ModifyTest(string functionName, string paramStr, string returnValue, string errorCode, string testID) { this.holoScriptApp.PauseApplication(); InterceptedFunction function = InterceptedFunctionDB.GetInstance("functions.xml").GetFunctionByName(functionName); if (function == null) { MessageBox.Show(this, "Function " + functionName + " not defined in the function database."); this.holoScriptApp.ResumeApplication(); return; } String[] functionParameters = paramStr.Split(','); // remove any leading spaces int index = 0; foreach (String p in functionParameters) { functionParameters[index] = p.Trim(); index++; } // set the default values of each test parameter index = 0; foreach (InterceptedFunctionParameter fp in function.Parameters) { fp.TestValue = functionParameters[index]; index++; } CreateTestWindow window = new CreateTestWindow(function); window.ReturnValue = returnValue; window.ErrorCode = errorCode; if (window.ShowDialog() != DialogResult.OK) { this.holoScriptApp.ResumeApplication(); return; } string section = window.Section; string testFunction = window.FunctionName; string action = window.Action; int numParams = window.NumApplicableParams; Array AppParamValues = window.ApplicableParamValues; Array AppParams = window.ApplicableParams; Array AppTypes = window.ApplicableParamTypes; Array AppPos = window.ApplicableParamPos; //make sure we capture changes made in the dlg string[] actionArray = action.Split(' '); string newReturnValue = actionArray[0]; string newErrorCode = actionArray[1]; string newParamStr = ""; // Convert the error string into an error code string strErrorCode = null; if (actionArray.Length > 0) strErrorCode = ErrorCodeDB.GetInstance().GetCodeFromString(actionArray[1]); if (strErrorCode != null) { action = actionArray[0] + ' '; action += strErrorCode; } index = 1; foreach (string param in AppParamValues) { if (index != AppParamValues.Length) newParamStr += param + ", "; else newParamStr += param; index++; } //if testid is null a new test will be created, otherwise the existing one will be altered //this.holoScriptApp.CreateScheduledTest(section, testFunction, action, numParams, AppParamValues, AppTypes, AppPos, ref testID); //if testid is new then a new entry will be created, otherwise the existing one will be altered AddScheduledTestItem(testFunction, newErrorCode, newReturnValue, newParamStr, testID); this.holoScriptApp.ResumeApplication(); }
/// <summary> /// click on create test window /// </summary> public void SelectCreateTestWindow() { CreateTestWindow.Wait(3).Click(); }