public StepResult GetResult(Process process, string databaseName) { _process = process; var result = new StepResult(); var resultRows = new List <Row>(); // if we have an input step then we need to get the rows from the input step and then // delete these particular rows if (HasInputStep) { var resultStep = InputStep.GetResult(_process, DatabaseName); var table = _process.GetDatabase(DatabaseName).GetTable(TableName); foreach (var row in resultStep.Rows) { table.RemoveRow(row.Id); } resultRows = resultStep.Rows; } else { // delete all rows in the table var table = _process.GetDatabase(DatabaseName).GetTable(TableName); var rows = table.GetAllRows(); table.RemoveAllRows(); resultRows = rows; } result.Rows = resultRows; return(result); }
/// <summary> /// Reseting the state of the arena when click on Restart button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void restartButton_Click(object sender, EventArgs e) { commandTextBox.Text = ""; _step = InputStep.Initialize; _robotId = 0; finalPositionLabel.Text = ""; arenaPanel.Controls.Clear(); }
private void StampText(PdfDocument pdfDoc, Document doc, InputStep step) { var data = step.GetData <TextInputData>(); float bottom = GetBottom(data, pdfDoc.GetPage(data.Page)); var text = new Text(data.Content) .SetFontSize(data.FontSize); doc.Add(new Paragraph(text) .SetPageNumber(data.Page) .SetFixedPosition(data.Left, bottom, 500)); }
public StepResult GetResult(Process process, string databaseName) { var result = new StepResult(); _process = process; var resultRows = new List <Row>(); // if we have an input step then we need to get the rows from the input step and then // update those rows and save back to the database if (HasInputStep) { var resultStep = InputStep.GetResult(_process, DatabaseName); foreach (var row in resultStep.Rows) { foreach (var value in row.Values) { if (value.ColumnName.ToUpper() == ColumnName.ToUpper()) { value.Value = Value.Replace("'", string.Empty); } } _process.GetDatabase(DatabaseName).GetTable(TableName).UpdateRow(row.ToReference(_process, TableName, DatabaseName), row.Values); } resultRows = resultStep.Rows; } else { var table = _process.GetDatabase(DatabaseName).GetTable(TableName); var rows = table.GetAllRows(); foreach (var row in rows) { foreach (var value in row.Values) { if (value.ColumnName == ColumnName) { value.Value = Value; } } table.UpdateRow(row.ToReference(_process, TableName, DatabaseName), row.Values); } resultRows = rows; } result.Rows = resultRows; return(result); }
private void ExecuteInputStep(InputStep step) { if (step.Action != null) { Console.WriteLine($"UI Element = {step.ElementId}, Input Data = {step.InputData}, Input Action = { step.Action}."); if (step.InputDataArray == null) { step.Action.Fire(WebDriver, step.ElementId, step.InputData); } else { step.Action.Fire(WebDriver, step.ElementId, step.InputDataArray); } } }
/// <summary> /// The method is validating / processing the commands entered by user. /// It is using the Arena class and Command classes to triger the movement of the Robots; /// </summary> private void ProcessCommand() { string[] commands = commandTextBox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); string lastCommand = commands[commands.Length - 1]; switch (_step) { case InputStep.Initialize: string[] commandParts = lastCommand.Split(' '); int maxY = 0; int maxX = 0; if (commandParts.Length != 2 || !int.TryParse(commandParts[0], out maxY) || !int.TryParse(commandParts[1], out maxX)) { MessageBox.Show("The command that you entered is invalid. Expected uppper-right arena coordinates. Try again."); return; } try { Arena.Instance.Init(maxX + 1, maxY + 1); DisplayArena(); } catch (Exception ex) { MessageBox.Show("There was an error while initializing Arena: " + ex.Message); return; } _step = InputStep.SetRobotPosition; break; case InputStep.SetRobotPosition: commandParts = lastCommand.Split(' '); int y = 0; int x = 0; RobotOrientation orientation; if (commandParts.Length != 3 || !int.TryParse(commandParts[0], out x) || !int.TryParse(commandParts[1], out y) || !Enum.TryParse(commandParts[2], out orientation)) { MessageBox.Show("The command that you entered is invalid. Expected position of the robot. Try again."); return; } try { finalPositionLabel.Text = ""; _robotId = RobotFactory.CreateRobot(x, y, orientation); DisplayArena(); } catch (Exception ex) { MessageBox.Show("There was an error while creating a robot: " + ex.Message); return; } _step = InputStep.MoveRobot; break; case InputStep.MoveRobot: for (int i = 0; i < lastCommand.Length; i++) { if (lastCommand[i] != 'L' && lastCommand[i] != 'M' && lastCommand[i] != 'R') { MessageBox.Show("The command that you entered is invalid. Expected commands for the robot [L|M|R]"); return; } } for (int i = 0; i < lastCommand.Length; i++) { try { switch (lastCommand[i]) { case 'L': _robotCommandLeft.Execute(_robotId); break; case 'R': _robotCommandRight.Execute(_robotId); break; case 'M': _robotCommandForward.Execute(_robotId); break; default: break; } DisplayArena(); Application.DoEvents(); Thread.Sleep(500); } catch (Exception ex) { MessageBox.Show($"There was an error while moving the robot with command at positon ${i+1} / ${lastCommand[i]}: " + ex.Message); return; } } Robot robot = Arena.Instance.GetRobot(_robotId); finalPositionLabel.Text = $"Final position: [{robot.X}, {robot.Y}, {robot.Orientation}]"; _step = InputStep.SetRobotPosition; break; default: break; } }