/// <summary> /// Reads a line from the instance CSV /// </summary> /// <returns>The fields in a List, ordered left-to-right in the order parsed, or null if: a) there is no more data, or /// b) the EOF string was encountered, or c) MaxRows were read /// </returns> public override List <string> ReadLine() { string InputLine; List <string> Fields = null; while ((InputLine = NextLine()) != null) { ++TotLinesRead; TotBytesRead += InputLine.Length + 2; // CRLF if (SkipLines != 0) { if (++LinesSkippedSoFar <= SkipLines) { continue; } } if (RowsProcessed++ >= MaxRows) { break; } if (HasEOFStr && InputLine.StartsWith(EOFStr)) { break; } Fields = Parser.SplitLine(InputLine, RemoveEmbeddedTabs); break; } return(Fields); }
//--------------------------------------------------------------------- private void CompareDatasetAndFile(IDataset dataset, string filename) { FileLineReader file = OpenFile(filename); InputLine inputLine = new InputLine(file); InputVar <string> LandisData = new InputVar <string>(Landis.Data.InputVarName); inputLine.ReadVar(LandisData); int expectedIndex = 0; foreach (IEcoregion ecoregion in dataset) { Assert.AreEqual(expectedIndex, ecoregion.Index); expectedIndex++; Assert.IsTrue(inputLine.GetNext()); currentLine = new StringReader(inputLine.ToString()); Assert.AreEqual(ReadValue <bool>(), ecoregion.Active); Assert.AreEqual(ReadValue <byte>(), ecoregion.MapCode); Assert.AreEqual(ReadValue <string>(), ecoregion.Name); Assert.AreEqual(ReadValue <string>(), ecoregion.Description); } Assert.IsFalse(inputLine.GetNext()); file.Close(); }
/// <summary> /// Gets the data points. /// </summary> /// <param name="inputLine">The line.</param> /// <returns></returns> public override IEnumerable <DataPoint> GetDataPoints(InputLine inputLine) { //check line var lines = inputLine.Line.Split('|'); if (lines.Length > 0) { //Set data string symbol = String.Empty; //Get data string data; if (lines.Length == 2) { data = lines[1]; } else { symbol = lines[1]; data = lines[2]; } //convert return(_binanceDataFeed.ParseData(data, symbol)); } else { _log.Warn($"Cannot parse data from line as it is incorrect"); return(new DataPoint[0]); } }
async Task SendResult() { InputLine tmp = line; line = new InputLine(); await Callback(tmp).ConfigureAwait(false); }
public override void PartOne() { const int size = 256; var nums = Enumerable.Range(0, size).Repeat(2).ToArray(); var current = 0; var skip = 0; foreach (var length in InputLine.Csv().Ints()) { new Span <int>(nums, current, length).Reverse(); if (current + length > size) { Array.Copy(nums, size, nums, 0, current + length - size); Array.Copy(nums, current, nums, current + size, size - current); } else { Array.Copy(nums, current, nums, current + size, length); } current = (current + length + skip) % size; skip++; } var result = nums[0] * nums[1]; WriteLn(result); }
static void Main(string[] args) { StreamReader read = new StreamReader("In0303.txt"); StreamWriter write = new StreamWriter("Out0303.txt"); List <Edge> EdgeList = new List <Edge>(); string InputLine; int TopNum = 0, EdgeNum = 0, TopCounter = 0; if ((InputLine = read.ReadLine()) != null) { string[] tmp = InputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); TopNum = int.Parse(tmp[0]); EdgeNum = int.Parse(tmp[1]); } while ((InputLine = read.ReadLine()) != null) { TopCounter++; string[] tmp = InputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < tmp.Length; i++) { Edge edge = new Edge(); edge.top1 = TopCounter; edge.top2 = int.Parse(tmp[i++]); edge.weight = int.Parse(tmp[i]); EdgeList.Add(edge); } } KruskalAlgorithm algor = new KruskalAlgorithm(); algor.Answer(TopNum, EdgeNum, EdgeList, write); read.Close(); write.Close(); }
void Return_InBlock() { if (InputLine == "") { ProcessInput(blockText); blockText = ""; inBlock = false; } else { blockText += "\n" + InputLine; string whiteSpace = null; if (auto_indent) { System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^(\s+).*"); whiteSpace = r.Replace(InputLine, "$1"); if (InputLine.EndsWith(BlockStart)) { whiteSpace += "\t"; } } Prompt(true, true); if (auto_indent) { InputLine += whiteSpace; } } }
//--------------------------------------------------------------------- private void CompareDatasetAndFile(ISpeciesDataset dataset, string filename) { FileLineReader file = OpenFile(filename); InputLine inputLine = new InputLine(file); InputVar <string> LandisData = new InputVar <string>(Landis.Data.InputVarName); inputLine.ReadVar(LandisData); int expectedIndex = 0; foreach (ISpecies species in dataset) { Assert.AreEqual(expectedIndex, species.Index); expectedIndex++; Assert.IsTrue(inputLine.GetNext()); currentLine = new StringReader(inputLine.ToString()); Assert.AreEqual(ReadValue <string>(), species.Name); Assert.AreEqual(ReadValue <int>(), species.Longevity); Assert.AreEqual(ReadValue <int>(), species.Maturity); Assert.AreEqual(ReadValue <byte>(), species.ShadeTolerance); Assert.AreEqual(ReadValue <byte>(), species.FireTolerance); Assert.AreEqual(ReadEffectiveSeedDist(), species.EffectiveSeedDist); Assert.AreEqual(ReadValue <int>(), species.MaxSeedDist); Assert.AreEqual(ReadValue <float>(), species.VegReprodProb); Assert.AreEqual(ReadValue <int>(), species.MinSproutAge); Assert.AreEqual(ReadValue <int>(), species.MaxSproutAge); Assert.AreEqual(ReadValue <PostFireRegeneration>(), species.PostFireRegeneration); } Assert.IsFalse(inputLine.GetNext()); file.Close(); }
public History(Rect Bounds, InputLine ALink, int AHistoryId) : base(Bounds) { Options |= OptionFlags.ofPostProcess; EventMask |= EventMasks.evBroadcast; Link = ALink; HistoryId = AHistoryId; }
private static bool ProcessDumpFile() { string[] InputLines; List <string> OutputList; Console.Write("Reading file \"" + _InputFileName + "\"..."); try { InputLines = File.ReadAllLines(_InputFileName); } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("The input file \"" + _InputFileName + "\" cannot be read. " + ex.Message); return(false); } Console.WriteLine(" Done!"); OutputList = new List <string>(); bool OkToProcessLine = false; Console.Write("Processing dump file..."); foreach (string InputLine in InputLines) { if (InputLine.StartsWith("******* ") == true) { OkToProcessLine = true; } else if (OkToProcessLine == true) { if (InputLine.Contains("$ =") == true || InputLine.Contains("$ =") == true) { OutputList.Add(InputLine); } } } Console.WriteLine(" Done!"); OutputList.Sort(); // Sort the list // Custom code to add to the end OutputList.Add("charset 2"); OutputList.Add("*=$c000"); Console.Write("Writing file \"" + _OutputFileName + "\"..."); try { File.WriteAllLines(_OutputFileName, OutputList); } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("The output file \"" + _OutputFileName + "\" cannot be written. " + ex.Message); return(false); } Console.WriteLine(" Done!"); return(true); }
/// <summary> /// Reads a line from the file, splits it according to the file format, and returns the fields as a List of strings /// </summary> /// <exception cref="InvalidOperationException">if the file does not have a consistent format</exception> /// <returns>the fields as a List of strings</returns> public override List <string> ReadLine() { if (!IsParseable) { throw new InvalidOperationException("Attempt to read from a file that does not exhibit a consistent format"); } string InputLine; List <string> Fields = null; while ((InputLine = Rdr.ReadLine()) != null) { ++TotLinesRead; TotBytesRead += InputLine.Length + 2; // CRLF if (SkipLines != 0) { if (++LinesSkippedSoFar <= SkipLines) { continue; } } if (RowsProcessed++ >= MaxRows) { break; } if (HasEOFStr && InputLine.StartsWith(EOFStr)) { break; } Fields = ParseLine(InputLine.Replace("\t", TabReplacementString).TrimEnd()); break; } return(Fields); }
public void MatchName_AtEnd() { InputLine line = MakeInputLine(null); AssertLineAtEnd(line); TryMatchName(line, "expected.variable.name"); }
public void GoodFile() { const string filename = "GoodFile.txt"; IParameterDataset dataset; try { reader = OpenFile(filename); dataset = parser.Parse(reader); } finally { reader.Close(); } try { // Now that we know the data file is properly formatted, read // data from it and compare it against parameter dataset. reader = OpenFile(filename); inputLine = new InputLine(reader); Assert.AreEqual(parser.LandisDataValue, ReadInputVar <string>("LandisData")); CheckPercentageTable("CohortBiomassReductions", dataset.CohortReductions, "DeadPoolReductions"); CheckPercentageTable("DeadPoolReductions", dataset.PoolReductions, null); } finally { inputLine = null; reader.Close(); } }
public static Option Login() { ConsoleWriter.ClearScreen(); var lines = File.ReadAllLines(@"UI/maps/3b.Login.txt"); var loginText = TextEditor.Add.DrawablesAt(lines, 0); TextEditor.Center.AllUnitsInXDir(loginText, Console.WindowWidth); TextEditor.Center.InYDir(loginText, Console.WindowHeight); ConsoleWriter.TryAppend(loginText); ConsoleWriter.Update(); var colons = loginText.FindAll(x => x.Chars == ":"); var nameLine = new InputLine(colons[0], 50, ForegroundColor); var accountName = nameLine.GetInputString(false); var passwordLine = new InputLine(colons[1], 50, ForegroundColor); var password = passwordLine.GetInputString(true); LineTools.ClearAt((nameLine.X, nameLine.Y), accountName); LineTools.ClearAt((passwordLine.X, passwordLine.Y), password); ConsoleWriter.ClearScreen(); Console.SetCursorPosition(Console.WindowWidth / 2 - 10, Console.WindowHeight / 2 - 3); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Validating login..."); _account = DatabaseManagement.AccountManagement.ValidateLogin(accountName, password); return(_account != null ? Option.Account : Option.Start); }
public void Callback(SteamUGCRequestUGCDetailsResult_t param, bool bIOFailure) { GameEvents.Twice_Second.UnregWithEvent(SteamUGCRequest); string Description = param.m_details.m_rgchDescription; if (!string.IsNullOrEmpty(Description)) { using (StringReader Reader = new StringReader(Description)) { string InputLine; System.Version LatestVersion = null; while ((InputLine = Reader.ReadLine()) != null) { if (InputLine.StartsWith("Mod latest version ")) { LatestVersion = System.Version.Parse(InputLine.Remove(0, 18)); break; } } if (LatestVersion != null && ModVersion.CompareTo(LatestVersion) == -1) { ModProblemOverwrite(ModName, MyModDirPath + "UpdateText", "New version released! v" + LatestVersion, false); } } } }
static void Main() { string InputPath = @"C:\Users\....\Desktop\CP Class\Assignment 2\Asgn2InputFile.txt"; string OutputPath = @"C:\Users\....\Desktop\CP Class\Assignment 2\Payroll.txt"; using (StreamReader sr = new StreamReader(InputPath)) using (StreamWriter sw = new StreamWriter(OutputPath)) { sw.Write("NAME".PadRight(11)); sw.Write("HOURS WORKED ".PadRight(23)); sw.Write("PAY RATE".PadRight(20)); sw.Write("OVERTIME".PadRight(27)); sw.WriteLine(); // input line string InputLine; while ((InputLine = sr.ReadLine()) != null) { // parse input line var First = InputLine.Substring(0, 5); var Last = InputLine.Substring(0, 11); var Pay = double.Parse(InputLine.Substring(31, 5)); var Hours = int.Parse(InputLine.Substring(16, 2)); var OverT = int.Parse(InputLine.Substring(29, 1)); // var Earnings = (Hours * Pay); var Gross = Earnings + (OverT * (Pay * 1.5)); sw.Write(First.PadRight(11)); //Error Code occurs here sw.WriteLine(Last.PadRight(11)); // sw.Write(Earnings.ToString().PadLeft(10) + " @ " + Gross.ToString("C").PadRight(9)); sw.WriteLine(Earnings.ToString("C").PadLeft(17)); sw.WriteLine(); //Total += Earnings; } } }
public void MatchOptName_AtEnd() { InputLine line = MakeInputLine(null); AssertLineAtEnd(line); Assert.IsFalse(line.MatchOptionalName("expected.variable.name")); }
public void ReadOptVar_MissingReqdVar() { InputLine line = MakeInputLine("NotIntOrStrVar"); Assert.IsFalse(line.ReadOptionalVar(strVar)); TryReadVar(line, intVar); }
private void InsertNewLine() { ClearLastInputCommand(); var initalText = String.Empty; var currentLine = CurrentLine; if (currentLineOffset < currentLine.ContentLength) { var removeLength = currentLine.ContentLength - currentLineOffset; initalText = currentLine.content.ToString(currentLineOffset, removeLength); currentLine.content.Remove(currentLineOffset, removeLength); currentLine.ClearTokenCache(); } var line = new InputLine(manager.GetPrompt()); lines.Insert(++currentLineIndex, line); currentLineOffset = 0; if (initalText.Length > 0) { var idx = currentLineOffset; line.InsertLine(ref idx, initalText, 0, initalText.Length); } } // proc InsertNewLine
public void ReadStrVar_AtEnd() { InputLine line = MakeInputLine(null); AssertLineAtEnd(line); TryReadVar(line, strVar); }
public List <Point> Parse() { try { List <Point> Outcome = new List <Point>(); using (StreamReader StreamReader = new StreamReader(Filepath)) { string InputLine; string[] FormatInput = new string [2]; double X, Y; while ((InputLine = StreamReader.ReadLine()) != null) { FormatInput = InputLine.Split(','); if (FormatInput.Length == 2) { Double.TryParse(FormatInput[0], out X); Double.TryParse(FormatInput[1], out Y); Outcome.Add(new Point(X, Y)); } } } return(Outcome); } catch (Exception CaughtException) { Console.WriteLine("The file could not be read:"); Console.WriteLine(CaughtException.Message); return(new List <Point>()); } }
public override void PartTwo() { var blocks = InputLine.Tabbed().Ints().ToArray(); var(_, cycle) = Algorithms.FindCyclePeriod(blocks, arr => arr.ToCsv(), Redistribute); WriteLn(cycle); }
public static void Throw(InputLine inputLine, string errorFormat, params object[] values) { var message = Utility.FormatCurrentCulture("Syntax error on line {0}: {1}: '{2}'", inputLine.LineNumber, Utility.FormatCurrentCulture(errorFormat, values), inputLine.Text); throw new SyntaxException(message, inputLine); }
//--------------------------------------------------------------------- private void AssertLineHasValue(InputLine line, int lineNumber, string varName) { Assert.IsTrue(line); Assert.AreEqual(lineNumber, line.Number); Assert.AreEqual(varName, line.VariableName); }
public void NullInput() { InputLine line = MakeInputLine(null); Assert.AreEqual("", line.ToString()); AssertLineAtEnd(line); AssertNoMoreLines(line); }
public void MatchOptName_ExtraText() { string varName = "Optional-Variable-Name"; InputLine line = MakeInputLine(varName + " \t some extra text\n"); AssertLineHasValue(line, 1, varName); TryMatchOptName(line, varName); }
public override void PartTwo() { var half = InputLine.Length / 2; var captcha = new CircularBuffer <int>(InputLine.Digits().ToArray()); var result = captcha.Select((d, i) => d == captcha[i + half] ? d : 0).Sum(); WriteLn(result); }
public void MatchOptName_LongExtraText() { string varName = "Optional-Variable-Name"; InputLine line = MakeInputLine(varName + " " + longExtraText); AssertLineHasValue(line, 1, varName); TryMatchOptName(line, varName); }
public void MatchName_WrongName() { string varName = "Variable-Name"; InputLine line = MakeInputLine(varName); AssertLineHasValue(line, 1, varName); TryMatchName(line, "expected.variable.name"); }
public Day4() { var input = InputLine.Split('-').Ints().ToArray(); Lower = input[0]; Upper = input[1]; Part = 2; }
public static void Throw( InputLine inputLine, string errorFormat, params object[] values ) { var message = Utility.FormatCurrentCulture( "Syntax error on line {0}: {1}: '{2}'", inputLine.LineNumber, Utility.FormatCurrentCulture( errorFormat, values ), inputLine.Text ); throw new SyntaxException( message, inputLine ); }
private SyntaxException( string message, InputLine inputLine ) : base(message) { _inputLine = inputLine; }
protected override string PreprocessLine( InputLine inputLine ) { return string.Format("div.{0}", inputLine.NormalizedText); }
protected virtual string PreprocessLine(InputLine inputLine) { return inputLine.NormalizedText; }