public static void Main(string[] args) { Console.WriteLine("Starting"); DateTime startTime = DateTime.Now; _commandStore = new CommandStore(); var generators = new List<CrossGenerator> { CreateGenerator("../templates/Template1.txt", "../dict/cz", _commandStore), CreateGenerator("../templates/Template2.txt", "../dict/words", _commandStore), CreateGenerator("../templates/Template3.txt", "../dict/cz", _commandStore), CreateGenerator("../templates/Template4.txt", "../dict/cz", _commandStore), CreateGenerator("../templates/american.txt", "../dict/words", _commandStore), CreateGenerator("../templates/british.txt", "../dict/words", _commandStore), CreateGenerator("../templates/japanese.txt", "../dict/cz", _commandStore) }; //command reader const int maxSolutionsCount = 3; var ri = new ReadInput(_commandStore); Task.Run(() => ri.Run()); var tasks = generators.Select(gen1 => Task.Factory.StartNew(() => GenerateAndOutput(gen1, _commandStore, maxSolutionsCount))).ToArray(); Task.WaitAll(tasks); ri.ShouldStop = true; TimeSpan timeSpan = DateTime.Now - startTime; Console.WriteLine("Time elapsed: {0}", timeSpan); }
private void ReadObjectProcessStream(StreamReader reader) { using (var jsonReader = new JsonTextReader(reader) { SupportMultipleContent = true }) { while (jsonReader.Read()) { try { var result = _jsonSerializer.Deserialize <ResultObject>(jsonReader); switch (result) { case ExceptionResultObject exceptionResult: Error?.Invoke(exceptionResult); break; case InputReadRequest _: ReadInput?.Invoke(); break; default: Dumped?.Invoke(result); break; } } catch (Exception ex) { Dumped?.Invoke(ResultObject.Create("Error deserializing result: " + ex.Message, DumpQuotas.Default)); } } } }
// Start is called before the first frame update void Awake() { Input = GameObject.FindGameObjectWithTag("Input").GetComponent <ReadInput>(); course = new int[Input.numOfTracks]; course = Input.Results; // rand = 0 mantem a reta como esta // rand = 1 curva (1,-1) quando vertical vira pra esquerda quando horizontal vira pra cima // rand = 2 curva (2,-2) quando vertical vira pra direita quando horizontal vira pra baixo trackLenght = course.Length + 1; IndividualTracks = new GameObject[trackLenght]; startPos = transform.position; lastPos = startPos; // Instancia o Inicio Instantiate(ObjectsToPlace[3], new Vector3(0, 0, 0) + startPos, Quaternion.identity); decifre(); Instantiate(YourCar, new Vector3(0, 0.5f, -1) + startPos, Quaternion.Euler(0, 90, 0)); for (int i = 0; i < 3; i++) { Instantiate(AICAR, new Vector3(0, 0.5f, i) + startPos, Quaternion.identity); } CheckForOverLaps(); }
private GameLogic gamePreparations() { string player1Name = ReadInput.PlayerName(), player2Name = null; GameLogic.eGameMode gameMode = ReadInput.GameMode(player1Name); if (gameMode == GameLogic.eGameMode.TwoPlayers) { player2Name = ReadInput.PlayerName(); } else { this.m_GameDifficulty = ReadInput.LevelOfDifficulty(); } ReadInput.BoardDimensions(out int boardNumOfRows, out int boardNumOfCols); this.m_CardsData.Capacity = boardNumOfRows * boardNumOfCols / 2; this.cardsDataInitialization(); if (gameMode == GameLogic.eGameMode.OnePlayer) { m_PcPlayerLogic = new GameLogic.Pc(boardNumOfRows, boardNumOfCols); } return(new GameLogic(boardNumOfRows, boardNumOfCols, gameMode, player1Name, player2Name)); }
void Run() { Console.WriteLine("Starting"); DateTime startTime = DateTime.Now; var generators = new List <CrossGenerator> { CreateGenerator("../templates/template1.txt", "../dict/cz", _commandStore), CreateGenerator("../templates/template2.txt", "../dict/words", _commandStore), CreateGenerator("../templates/template3.txt", "../dict/words", _commandStore), CreateGenerator("../templates/template4.txt", "../dict/cz", _commandStore), CreateGenerator("../templates/american.txt", "../dict/words", _commandStore), CreateGenerator("../templates/british.txt", "../dict/words", _commandStore), CreateGenerator("../templates/japanese.txt", "../dict/words", _commandStore) }; //command reader const int maxSolutionsCount = 100; var ri = new ReadInput(_commandStore); Task.Run(() => ri.Run()); var tasks = generators.Select(gen1 => Task.Factory.StartNew(() => GenerateAndOutput(gen1, _commandStore, maxSolutionsCount))).ToArray(); Task.WaitAll(tasks); ri.ShouldStop = true; TimeSpan timeSpan = DateTime.Now - startTime; Console.WriteLine("Time elapsed: {0}", timeSpan); }
public static void Main(string[] args) { List <List <int> > inputList = ReadInput.readInputFromFile(@"..\..\input.txt"); Console.WriteLine(); Console.WriteLine("Output:"); printResult(findMaxResult(findResults(inputList))); }
public static void RunGraph(string graph_path, ReadInput input_function) { if (CurrentProcess != null && !CurrentProcess.HasExited) { CurrentProcess.Kill(); } CurrentProcess = FetchNewProcess(graph_path); Aborting = false; if (input_function != null) { CurrentProcess.StartInfo.RedirectStandardInput = true; } try { //Start process and asynchronous reading CurrentProcess.Start(); CurrentProcess.BeginOutputReadLine(); CurrentProcess.BeginErrorReadLine(); if (input_function != null) { using (StreamWriter writer = new StreamWriter(CurrentProcess.StandardInput.BaseStream, Encoding.ASCII)) { while (!CurrentProcess.HasExited && !Aborting) { byte[] input = input_function(); if (input != null && input.Length != 0) { writer.WriteLine(Encoding.ASCII.GetString(input)); } else { writer.Flush(); } } } } if (Aborting && !CurrentProcess.HasExited) { CurrentProcess.Kill(); CurrentProcess.WaitForExit(); VSLogger.Log("Aborted current process."); } } catch (Win32Exception exception) { VSLogger.LogError("Output:\n" + exception.ToString()); } CurrentProcess.WaitForExit(); CurrentProcess = null; Aborting = false; }
private void submitButton_Click(object sender, EventArgs e) { if (filePath == string.Empty) { return; } var progressWindow = new ProgressWindow(); progressWindow.Show(); // Create isotope map Dictionary <string, List <string> > isotopeMap = null; IsotopeCalc isotopeCalc = new IsotopeCalc(); //isotopeMap = isotopeCalc.IsotopeMap(filePath); // Read data to map Dictionary <string, Dictionary <string, string> > dataMap = null; //if (skylineRadioButton.Checked) //{ // dataMap = ProcessSkyline.ReadDataToMap(filePath); // if (dataMap.Count == 0) return; // // Create isotope map // isotopeMap = isotopeCalc.IsotopeMap(filePath); //} if (radioButtonExcel.Checked) { dataMap = ProcessSciex.ReadDataToMap(filePath); if (dataMap.Count == 0) { return; } } else if (radioButtonMultiQuant.Checked) { dataMap = ReadInput.ReadMultiQuantTxt(filePaths); var templatePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + $"\\DataProcessor\\targeted_300_template-serum-mrm.xlsx"; WriteOutputFile.WriteMapToSheetCompoundsInRows(progressWindow, dataMap, templatePath, "Relative Quant Data", 1); //WriteOutputFile.WriteMapToSheetCompoundsInRows(progressWindow, dataMap, templatePath, "Data Reproducibility", 2); } if (dataMap == null) { progressWindow.progressTextBox.AppendLine("Error reading file."); return; } progressWindow.progressTextBox.AppendLine("Finished reading data.\r\nWriting data"); //WriteOutputFile.WriteSciex(replaceNA, missingValReplace, progressWindow, dataMap, Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + $"\\DataProcessor\\targeted_300_template-tissue.xlsx"); }
public void validate_If_file_does_not_exist_returns_error_message() { //Arrange List <string> listOfInstructions = new List <string>(); string fileName = "input_test_does_not_exist.txt"; string expectedMessage = "File does not exist or does have permission to read"; //Act IReadInput readInput = new ReadInput(); listOfInstructions = readInput.ReadInputFile(Path.GetFullPath(fileName), out string actualMessage); //Assert Assert.AreEqual(expectedMessage, actualMessage); }
//a boolean that wil lbe used to check if there is a difference in files or not public Check() { ReadInput readObj = new ReadInput(); //makes a new object to execute the class readinput string[] listA = readObj.file1.ToArray(); string[] listB = readObj.file2.ToArray(); //converts the lists into arrays to be read into for (int i = 0; i < listA.Length; i++) { counter++; //for loop that goes through the entire array using a index i if (listA[i] != listB[i]) { isDifferent = true; break; //if the array indexes for both lists are not the same it will set the bool to true and break out of the loop. } else { isDifferent = false; //if the lists are the same then they are not different so the bool is set to false } } if (isDifferent == true) { //if statement that checks the state of the bool to output the appropiate message. Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("a.txt and b.txt are different at Line:" + counter.ToString()); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Line" + counter.ToString() + ":"); Console.Write(listA[counter].ToString()); Console.WriteLine(listB[counter].ToString()); //if the files are different it will change the text colour and alert the user they are different. } else { //if the bool is false this message will be shown Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("a.txt and b.txt are not different"); Console.ForegroundColor = ConsoleColor.White; } }
static void Main(string[] args) { // var day1 = new Day1(); // var inputDay1 = ReadInput.ReadInt("/home/yarince/RiderProjects/AdventOFCode/AdventOfCode/input-day1"); // day1.Execute1(inputDay1); // day1.Execute2(inputDay1); // var day2 = new Day2(); // var inputDay2 = ReadInput.ReadStr("/home/yarince/RiderProjects/AdventOFCode/AdventOfCode/input-day2"); // day2.Execute1(inputDay2); // day2.Execute2(inputDay2); var day3 = new Day3(); var inputDay3 = ReadInput.ReadStr("C:\\Users\\Yarince Martis\\Documents\\adventOfCode2020\\AdventOfCode\\input-day3-test"); day3.Execute1(inputDay3); // day3.Execute2(inputDay3); }
static void Main(string[] args) { // AppLog List <string> rawStringList = new List <string>(); var readInput = new ReadInput(); readInput.FillRawStringList(Environment.GetEnvironmentVariable("inputFile"), ref rawStringList); var parseInput = new CleanseRawInput(); parseInput.CleanseRawList(ref rawStringList); var generateJson = new JSONParser(); generateJson.ReplaceAtStrings(ref rawStringList); List <LoggingJSON> jsonObjectList = new List <LoggingJSON>(); generateJson.GenerateJSON(ref rawStringList, ref jsonObjectList); List <string> finalListPriorToOutput = new List <string>(); generateJson.GenerateFinaStringListPriorToOutput(ref jsonObjectList, ref finalListPriorToOutput); // AccessLog List <string> rawAccessLog = new List <string>(); List <string> cleansedLog = new List <string>(); readInput.FillRawAccessLog(Environment.GetEnvironmentVariable("inputLog"), ref rawAccessLog); AccessLog accessLog = new AccessLog(); accessLog.CleanseAccessLog(ref rawAccessLog, ref cleansedLog); Console.WriteLine("press a button .. "); string line = Console.ReadLine(); // Both WriteOutput output = new WriteOutput(); output.WriteToFile(ref finalListPriorToOutput, ref cleansedLog); }
private void playGame(GameLogic i_Game) { eNewGameRequest requestForNewGame; do { printIntroAndRules(i_Game); if (i_Game.GameMode == GameLogic.eGameMode.TwoPlayers) { do { Ex02.ConsoleUtils.Screen.Clear(); turn(i_Game); }while(i_Game.IsGameFinished() == false); } else { playVsPc(i_Game); } Ex02.ConsoleUtils.Screen.Clear(); printScoreBoard(i_Game); printCurrentBoardGame(i_Game.Data); printWinnerOrTie(i_Game); requestForNewGame = ReadInput.NewGameRequest(); if (requestForNewGame == eNewGameRequest.Yes) { ReadInput.BoardDimensions(out int boardNumOfRows, out int boardNumOfCols); this.m_CardsData.Capacity = boardNumOfRows * boardNumOfCols / 2; this.cardsDataInitialization(); if (i_Game.GameMode == GameLogic.eGameMode.OnePlayer) { this.m_GameDifficulty = ReadInput.LevelOfDifficulty(); } i_Game.ResetGame(boardNumOfRows, boardNumOfCols); m_PcPlayerLogic = new GameLogic.Pc(boardNumOfRows, boardNumOfCols); } }while(requestForNewGame == eNewGameRequest.Yes); }
public void validate_If_input_text_file_has_empty_lines_then_list_should_be_zero_with_error_message() { //Arrange string fileName = "input_test.txt"; List <string> listOfInstruction = null; int expectedInstruction = 0; string expectedMessage = "File can not be empty"; using (var fileCreated = File.CreateText(fileName)) { fileCreated.WriteLine(""); } //Act IReadInput readInput = new ReadInput(); listOfInstruction = readInput.ReadInputFile(Path.GetFullPath(fileName), out string actualMessage); //Assert Assert.AreEqual(expectedInstruction, listOfInstruction.Count); Assert.AreEqual(expectedMessage, actualMessage); }
public void validate_If_input_text_file_has_any_line_wit_instruction_but_not_nummber() { //Arrange string fileName = "input_test.txt"; List <string> listOfInstruction = null; string expectedMessage = "Line does not have valid number"; using (var fileCreated = File.CreateText(fileName)) { fileCreated.WriteLine("add 2"); fileCreated.WriteLine("multiply str23"); // invalid number as second part of line fileCreated.WriteLine("apply 3"); } //Act IReadInput readInput = new ReadInput(); listOfInstruction = readInput.ReadInputFile(Path.GetFullPath(fileName), out string actualMessage); //Assert Assert.AreEqual(expectedMessage, actualMessage); }
private void turn(GameLogic i_Game) { bool pointScored = false; string currPlayerTurn; if (i_Game.Turn == GameLogic.eTurn.Player1) { currPlayerTurn = i_Game.Player1.Name; } else { currPlayerTurn = i_Game.Player2.Name; } string firstPickMsg1 = string.Format( @" {0} TURN! First Pick", currPlayerTurn); string secondPickMsg2 = string.Format( @" {0} TURN! Second Pick", currPlayerTurn); string outPutMsg1; printScoreBoard(i_Game); printCurrentBoardGame(i_Game.Data); Console.WriteLine(firstPickMsg1); ReadInput.CardSelection(i_Game.Data, out string firstCardSelection); int firstCardCol = transformDimensionColForUse(firstCardSelection[0]); int firstCardRow = transformDimensionRowForUse(firstCardSelection[1]); i_Game.Data[firstCardRow, firstCardCol].IsFaceUp = true; i_Game.Data[firstCardRow, firstCardCol].IsCurrPick = true; Ex02.ConsoleUtils.Screen.Clear(); printScoreBoard(i_Game); printCurrentBoardGame(i_Game.Data); Console.WriteLine(secondPickMsg2); ReadInput.CardSelection(i_Game.Data, out string seconedCardSelection); int secondCardCol = transformDimensionColForUse(seconedCardSelection[0]); int secondCardRow = transformDimensionRowForUse(seconedCardSelection[1]); i_Game.Data[secondCardRow, secondCardCol].IsFaceUp = true; i_Game.Data[secondCardRow, secondCardCol].IsCurrPick = true; Ex02.ConsoleUtils.Screen.Clear(); printScoreBoard(i_Game); printCurrentBoardGame(i_Game.Data); i_Game.Data[firstCardRow, firstCardCol].IsCurrPick = false; i_Game.Data[secondCardRow, secondCardCol].IsCurrPick = false; if (i_Game.GameMode == GameLogic.eGameMode.OnePlayer) { m_PcPlayerLogic.AddCardPcSaw(firstCardSelection, m_CardsData[i_Game.Data[firstCardRow, firstCardCol].CardIndex]); m_PcPlayerLogic.AddCardPcSaw(seconedCardSelection, m_CardsData[i_Game.Data[secondCardRow, secondCardCol].CardIndex]); } pointScored = i_Game.PlayTurn(firstCardRow, firstCardCol, secondCardRow, secondCardCol); if (pointScored == true) { if (i_Game.GameMode == GameLogic.eGameMode.OnePlayer) { m_PcPlayerLogic.RemoveOpenedCards(firstCardRow, firstCardCol, secondCardRow, secondCardCol, i_Game.Data.GetLength(1)); } outPutMsg1 = string.Format( @"Good job {0}! it's a pair! {0} earn 1 POINT!", currPlayerTurn); Console.WriteLine(outPutMsg1); } else { i_Game.Data[firstCardRow, firstCardCol].IsFaceUp = false; i_Game.Data[secondCardRow, secondCardCol].IsFaceUp = false; Console.WriteLine("Thats not a pair. 2 seconds try to remember the cards"); } System.Threading.Thread.Sleep(2000); Ex02.ConsoleUtils.Screen.Clear(); }
private Statement ParseStatement() { Statement parsedStatement; if (currentToken == listTokens.Count) { ExceptionHandler("statement was expected before end of file"); } if (listTokens[currentToken].Equals("print")) { currentToken++; Write _Write = new Write(); _Write.Expression = ParseExpression(); parsedStatement = _Write; } else if (listTokens[currentToken].Equals("var")) { currentToken++; DeclareVariable _DeclareVariable = new DeclareVariable(); if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _DeclareVariable.Identifier = (string)listTokens[currentToken]; } else { ExceptionHandler("variable name was expected after 'var'"); } currentToken++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.EqualTo.ToString()) { ExceptionHandler("= sign was expected after 'var identifier'"); } currentToken++; _DeclareVariable.Expression = ParseExpression(); parsedStatement = _DeclareVariable; } else if (listTokens[currentToken].Equals("call")) { currentToken++; CallFunction _CallFunction = new CallFunction(); if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _CallFunction.FunctionName = (string)listTokens[currentToken]; } else { ExceptionHandler("function name is expected after 'call'"); } currentToken++; _CallFunction.Parameter1 = ParseExpression(); //index++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.Comma.ToString()) { ExceptionHandler("',' sign was expected after first parameter"); } currentToken++; _CallFunction.Parameter2 = ParseExpression(); //index++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.Comma.ToString()) { ExceptionHandler("',' sign was expected after second parameter"); } currentToken++; _CallFunction.Parameter3 = ParseExpression(); //index++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.Terminator.ToString()) { ExceptionHandler("';' sign was expected after third parameter"); } parsedStatement = _CallFunction; } else if (listTokens[currentToken].Equals("string") || listTokens[currentToken].Equals("numeric") || listTokens[currentToken].Equals("void")) { DeclareFunction _DeclareFunction = new DeclareFunction(); _DeclareFunction.ReturnType = listTokens[currentToken].ToString(); currentToken++; if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _DeclareFunction.FunctionName = (string)listTokens[currentToken]; } else { ExceptionHandler("function name is expected after return type"); } currentToken++; if (listTokens[currentToken].Equals("var")) { currentToken++; DeclareVariable _DeclareVariable = new DeclareVariable(); if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _DeclareVariable.Identifier = (string)listTokens[currentToken]; } else { ExceptionHandler("variable name was expected after 'var'"); } currentToken++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.EqualTo.ToString()) { ExceptionHandler("= sign was expected after 'var identifier'"); } currentToken++; _DeclareVariable.Expression = ParseExpression(); _DeclareFunction.Parameter1 = _DeclareVariable; } currentToken++; if (listTokens[currentToken].Equals("var")) { currentToken++; DeclareVariable _DeclareVariable = new DeclareVariable(); if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _DeclareVariable.Identifier = (string)listTokens[currentToken]; } else { ExceptionHandler("variable name was expected after 'var'"); } currentToken++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.EqualTo.ToString()) { ExceptionHandler("= sign was expected after 'var identifier'"); } currentToken++; _DeclareVariable.Expression = ParseExpression(); _DeclareFunction.Parameter2 = _DeclareVariable; } currentToken++; if (listTokens[currentToken].Equals("var")) { currentToken++; DeclareVariable _DeclareVariable = new DeclareVariable(); if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _DeclareVariable.Identifier = (string)listTokens[currentToken]; } else { ExceptionHandler("variable name was expected after 'var'"); } currentToken++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.EqualTo.ToString()) { ExceptionHandler("= sign was expected after 'var identifier'"); } currentToken++; _DeclareVariable.Expression = ParseExpression(); _DeclareFunction.Parameter3 = _DeclareVariable; } if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("begin")) { ExceptionHandler("expected 'begin' after input parameters"); } currentToken++; _DeclareFunction.Body = ParseStatement(); parsedStatement = _DeclareFunction; if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("endfunc")) { ExceptionHandler("unterminated function', 'endfunc' expected at the end"); } currentToken++; } else if (listTokens[currentToken].Equals("read")) { currentToken++; ReadInput _ReadInput = new ReadInput(); if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _ReadInput.Identifier = (string)listTokens[currentToken++]; parsedStatement = _ReadInput; } else { ExceptionHandler("variable name is expected after 'read'"); parsedStatement = null; } } // IfThenElse ifThenElse = new IfThenElse(); // RelationalExpression relExpr = new RelationalExpression(); // relExpr.Left = ParseExpression(); // if (listTokens[index] == Scanner.EqualTo) // relExpr.Operand = RelationalOperands.EqualTo; // else if (listTokens[index] == Scanner.LessThan) // relExpr.Operand = RelationalOperands.LessThan; // else if (listTokens[index] == Scanner.GreaterThan) // relExpr.Operand = RelationalOperands.GreaterThan; // else // { // ExceptionHandler("expected relational operand"); // } // index++; // relExpr.Right = ParseExpression(); // ifThenElse.If = relExpr; // index++; // ifThenElse.Then = ParseStatement(); // parsedStatement = ifThenElse; // //index++; else if (listTokens[this.currentToken].Equals("while")) { currentToken++; While _while = new While(); _while.LeftExpression = ParseExpression(); if (listTokens[currentToken].ToString() == Lexer.Tokens.EqualTo.ToString()) { _while.Operand = RelationalOperands.EqualTo; } else if (listTokens[currentToken].ToString() == Lexer.Tokens.LessThan.ToString()) { _while.Operand = RelationalOperands.LessThan; } else if (listTokens[currentToken].ToString() == Lexer.Tokens.GreaterThan.ToString()) { _while.Operand = RelationalOperands.GreaterThan; } currentToken++; _while.RightExpression = ParseExpression(); if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("do")) { ExceptionHandler("expected 'do' after while"); } currentToken++; _while.Body = ParseStatement(); parsedStatement = _while; if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("endwhile")) { ExceptionHandler("unterminated 'while', endwhile expected at the end"); } currentToken++; } else if (listTokens[this.currentToken].Equals("if")) { currentToken++; IfThen _IfThen = new IfThen(); _IfThen.LeftExpression = ParseExpression(); if (listTokens[currentToken].ToString() == Lexer.Tokens.EqualTo.ToString()) { _IfThen.Operand = RelationalOperands.EqualTo; } else if (listTokens[currentToken].ToString() == Lexer.Tokens.LessThan.ToString()) { _IfThen.Operand = RelationalOperands.LessThan; } else if (listTokens[currentToken].ToString() == Lexer.Tokens.GreaterThan.ToString()) { _IfThen.Operand = RelationalOperands.GreaterThan; } currentToken++; _IfThen.RightExpression = ParseExpression(); if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("then")) { ExceptionHandler("expected 'then' after if"); } currentToken++; _IfThen.ThenBody = ParseStatement(); if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("else")) { ExceptionHandler("'else' is expected"); } currentToken++; _IfThen.ElseBody = ParseStatement(); parsedStatement = _IfThen; if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("endif")) { ExceptionHandler("unterminated 'if', endif expected at the end"); } currentToken++; } else if (listTokens[currentToken].Equals("for")) { currentToken++; For _For = new For(); if (currentToken < listTokens.Count && listTokens[currentToken] is string) { _For.Identifier = (string)listTokens[currentToken]; } else { ExceptionHandler("expected identifier after 'for'"); } currentToken++; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.EqualTo.ToString()) { ExceptionHandler("for missing '='"); } currentToken++; _For.From = ParseExpression(); if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("to")) { ExceptionHandler("expected 'to' after for"); } currentToken++; _For.To = ParseExpression(); if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("do")) { ExceptionHandler("expected 'do' after from expression in for loop"); } currentToken++; _For.Body = ParseStatement(); parsedStatement = _For; if (currentToken == listTokens.Count || !listTokens[currentToken].Equals("end")) { ExceptionHandler("unterminated 'for' loop body"); } currentToken++; } else if (listTokens[currentToken] is string) { // assignment Assignment _Assignment = new Assignment(); _Assignment.Identifier = (string)listTokens[currentToken++]; if (currentToken == listTokens.Count || listTokens[currentToken].ToString() != Lexer.Tokens.EqualTo.ToString()) { ExceptionHandler("expected '='"); } currentToken++; _Assignment.Expression = ParseExpression(); parsedStatement = _Assignment; } else { ExceptionHandler("parse error at token " + currentToken + ": " + listTokens[currentToken]); parsedStatement = null; } if (currentToken < listTokens.Count && listTokens[currentToken].ToString() == Lexer.Tokens.Terminator.ToString()) { currentToken++; if (currentToken < listTokens.Count && !listTokens[currentToken].Equals("end") && !listTokens[currentToken].Equals("else") && !listTokens[currentToken].Equals("endif") && !listTokens[currentToken].Equals("endwhile") && !listTokens[currentToken].Equals("endfunc")) { StatementSequence sequence = new StatementSequence(); sequence.Left = parsedStatement; sequence.Right = ParseStatement(); parsedStatement = sequence; } } return(parsedStatement); }
public void TestConformance() { SortedDictionary <long, IDictionary <string, string> > inputData = null; try { inputData = ReadInput.GetInputData(); } catch (EncoderFallbackException e) { Errln(e.ToString()); return; } catch (IOException e) { Errln(e.ToString()); return; } var keyMap = inputData.Keys; foreach (var element in keyMap) { var tempHash = inputData.Get(element); //get all attributes from input data String passfail = (String)tempHash.Get("passfail"); String desc = (String)tempHash.Get("desc"); String type = (String)tempHash.Get("type"); String namebase = (String)tempHash.Get("namebase"); String nameutf8 = (String)tempHash.Get("nameutf8"); String namezone = (String)tempHash.Get("namezone"); String failzone1 = (String)tempHash.Get("failzone1"); String failzone2 = (String)tempHash.Get("failzone2"); //they maybe includes <*> style unicode namebase = StringReplace(namebase); namezone = StringReplace(namezone); String result = null; bool failed = false; if ("toascii".Equals(tempHash.Get("type"))) { //get the result try { //by default STD3 rules are not used, but if the description //includes UseSTD3ASCIIRules, we will set it. if (desc.ToLowerInvariant().IndexOf( "UseSTD3ASCIIRules".ToLowerInvariant()) == -1) { result = IDNA.ConvertIDNToASCII(namebase, IDNA2003Options.AllowUnassigned).ToString(); } else { result = IDNA.ConvertIDNToASCII(namebase, IDNA2003Options.UseSTD3Rules).ToString(); } } catch (StringPrepParseException e2) { //Errln(e2.getMessage()); failed = true; } if ("pass".Equals(passfail)) { if (!namezone.Equals(result)) { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Errln("\t pass fail standard is pass, but failed"); } else { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Logln("\tpassed"); } } if ("fail".Equals(passfail)) { if (failed) { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Logln("passed"); } else { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Errln("\t pass fail standard is fail, but no exception thrown out"); } } } else if ("tounicode".Equals(tempHash.Get("type"))) { try { //by default STD3 rules are not used, but if the description //includes UseSTD3ASCIIRules, we will set it. if (desc.ToLowerInvariant().IndexOf( "UseSTD3ASCIIRules".ToLowerInvariant()) == -1) { result = IDNA.ConvertIDNToUnicode(namebase, IDNA2003Options.AllowUnassigned).ToString(); } else { result = IDNA.ConvertIDNToUnicode(namebase, IDNA2003Options.UseSTD3Rules).ToString(); } } catch (StringPrepParseException e2) { //Errln(e2.getMessage()); failed = true; } if ("pass".Equals(passfail)) { if (!namezone.Equals(result)) { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Errln("\t Did not get the expected result. Expected: " + Prettify(namezone) + " Got: " + Prettify(result)); } else { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Logln("\tpassed"); } } if ("fail".Equals(passfail)) { if (failed || namebase.Equals(result)) { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Logln("\tpassed"); } else { PrintInfo(desc, namebase, nameutf8, namezone, failzone1, failzone2, result, type, passfail); Errln("\t pass fail standard is fail, but no exception thrown out"); } } } else { continue; } } }
// Update is called once per frame void Update() { // Test to see if it works. textBox.text = ReadInput.GetMovement().ToString(); }
/// <summary> /// Reads the line or key. /// </summary> /// <param name="inline">if set to <c>true</c> [inline].</param> /// <returns></returns> // Note: Returns null if user pressed Escape, or the contents of the line if they pressed Enter. public static ConsoleOutput ReadLineOrKey(bool inline = false) { string retString = ""; int curRightPad, curIndex = 0; do { ConsoleKeyInfo readKeyResult = Console.ReadKey(true); // handle Enter if (readKeyResult.Key == ConsoleKey.Enter) { ReadInput?.Invoke(retString); curRightPad = Console.CursorLeft; if (!inline) { Console.WriteLine(); } return(new ConsoleOutput(retString) { CurrentRightPad = curRightPad }); } // handle backspace if (readKeyResult.Key == ConsoleKey.Backspace) { if (curIndex > 0) { retString = retString.Remove(retString.Length - 1); Console.Write(readKeyResult.KeyChar); Console.Write(' '); Console.Write(readKeyResult.KeyChar); --curIndex; } } else if (readKeyResult.Key == ConsoleKey.Delete) { if (retString.Length - curIndex > 0) { // Store current position int curLeftPos = Console.CursorLeft; // Redraw string for (int i = curIndex + 1; i < retString.Length; ++i) { Console.Write(retString[i]); } // Remove last repeated char Console.Write(' '); // Restore position Console.SetCursorPosition(curLeftPos, Console.CursorTop); // Remove string retString = retString.Remove(curIndex, 1); } } else if (readKeyResult.Key == ConsoleKey.RightArrow) { if (curIndex < retString.Length) { ++Console.CursorLeft; ++curIndex; } } else if (readKeyResult.Key == ConsoleKey.LeftArrow) { if (curIndex > 0) { --Console.CursorLeft; --curIndex; } } else if (readKeyResult.Key == ConsoleKey.Insert) { IsInserting = !IsInserting; Console.CursorSize = IsInserting ? 100 : DefaultCursorSize; } #if DEBUG else if (readKeyResult.Key == ConsoleKey.UpArrow) { if (Console.CursorTop > 0) { --Console.CursorTop; } } else if (readKeyResult.Key == ConsoleKey.DownArrow) { if (Console.CursorTop < Console.BufferHeight - 1) { ++Console.CursorTop; } } #endif else // handle all other keypresses { if (IsInserting || curIndex == retString.Length) { retString += readKeyResult.KeyChar; Console.Write(readKeyResult.KeyChar); ++curIndex; } else { // Store char char c = readKeyResult.KeyChar; // Write char at position Console.Write(c); // Store cursor position int curLeftPos = Console.CursorLeft; // Clear console from curIndex to end for (int i = curIndex; i < retString.Length; ++i) { Console.Write(' '); } // Go back Console.SetCursorPosition(curLeftPos, Console.CursorTop); // Write the chars from curIndex to end (with the new appended char) for (int i = curIndex; i < retString.Length; ++i) { Console.Write(retString[i]); } // Restore again Console.SetCursorPosition(curLeftPos, Console.CursorTop); // Store in the string retString = retString.Insert(curIndex, new string(c, 1)); // Sum one to the cur index (we appended one char) ++curIndex; } ReadInput?.Invoke(retString); } if (char.IsControl(readKeyResult.KeyChar) && readKeyResult.Key != ConsoleKey.Enter && readKeyResult.Key != ConsoleKey.Backspace && readKeyResult.Key != ConsoleKey.Tab && readKeyResult.Key != ConsoleKey.Delete && readKeyResult.Key != ConsoleKey.RightArrow && readKeyResult.Key != ConsoleKey.LeftArrow && readKeyResult.Key != ConsoleKey.Insert) { #if DEBUG if (readKeyResult.Key == ConsoleKey.UpArrow || readKeyResult.Key == ConsoleKey.DownArrow) { continue; } #endif ReadKey?.Invoke(readKeyResult); curRightPad = Console.CursorLeft; if (!inline) { Console.WriteLine(); } return(new ConsoleOutput(readKeyResult) { CurrentRightPad = curRightPad }); } }while (true); }
static void Main(string[] args) { /*List<Person> persons = ReadInput.read_csv(@"C:\Users\Hanniel\Desktop\programare orientata pe obiecte\proiecte\poo-projects\Agenda\input\persons.csv"); * Display.DisplayList(persons); * List<Activity> activities = ReadInput.read_activities(@"C:\Users\Hanniel\Desktop\programare orientata pe obiecte\proiecte\poo-projects\Agenda\input\activities.csv"); * Display.DisplayList(activities);*/ string path = @"C:\Users\Hanniel\Desktop\university\programare orientata pe obiecte\proiecte\poo-projects\Agenda\input\agendas.csv"; ReadInput ri = new ReadInput(path); List <Agenda> agendaList = ri.read_agendas(); //create a new person Person newPerson = new Person(); newPerson.lastName = "Perfect"; newPerson.firstName = "Legolas"; newPerson.ID = 3; newPerson.phoneNumber = "07899765"; newPerson.birthDay = "23/03/1810"; Console.WriteLine(newPerson); Console.WriteLine(); //crearea unei Agende si adaugarea la lista de Agende Agenda newAgenda = new Agenda(3, "Agenda 3", newPerson); agendaList.Add(newAgenda); //crearea unei activitati si adaugarea in agenda unei persoane string[] v = new string[] { "117", "pescuit", "la cris", "15/06/2008 08:30", "15/06/2008 12:30" }; Activity newActivity = ReadInput.create_activity(v, new List <Person>()); newActivity.AddParticipants(newPerson); newAgenda.addActivity(newActivity); Display.DisplayList(agendaList); //cautarea unei activitati Activity search = newAgenda.SearchActivityByName("pescuit"); if (search == null) { Console.WriteLine("ACtivity was not found in the agenda"); } else { Console.WriteLine(search); } //stergerea unei activitati DeleteAFromAgenda("Agenda 1", "workout", agendaList); //stergerea unei agende agendaList.Remove(newAgenda); //generarea unui raport cu toate activitatile unei persoane dintr-un anumit interval de timp //new DateTime("15/06/2008 12:30"),n Console.WriteLine(); CultureInfo provider = new CultureInfo("fr-FR"); DateTime startDate = DateTime.ParseExact("15/06/2008 08:30", "g", provider); DateTime finishDate = DateTime.ParseExact("15/06/2008 12:30", "g", provider); List <Activity> list = ActivitiesFound(1, startDate, finishDate, agendaList); Display.DisplayList(list); }