static void Main(string[] args) { do { try { FileLines fileLines = new FileLines(@"..\..\Program.cs"); foreach (string line in fileLines) { Console.WriteLine(line); } Console.Write("\n\nOne more time\n\n"); foreach (string line in fileLines) { Console.WriteLine(line); } } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press Esc to exit or another button to continue"); } while (Console.ReadKey().Key != ConsoleKey.Escape); }
public void FileLines() { var diagnostic = new FileLines { Maximum = 12 }; Verifier.VerifyAnalyzer(@"TestCases\FileLines12.cs", diagnostic); Verifier.VerifyAnalyzer(@"TestCases\FileLines13.cs", diagnostic); }
static void Main(string[] args) { var fileLines = new FileLines("output.txt"); foreach (var line in fileLines) { Console.WriteLine(line); } }
public static void WriteFile(string filename, FileLines fileLines) { var file = new System.IO.StreamWriter(Docsfolder + "\\" + filename + ".txt"); using (file) { foreach (var fileLine in fileLines) { file.WriteLine(fileLine.Fileline); } } }
private void AddAnalyzerFileLines(ImmutableArray <DiagnosticAnalyzer> .Builder builder) { var analyzer = new FileLines(); if (!AnalyzerIds.Contains(analyzer.SupportedDiagnostics.Single().Id)) { return; } analyzer.Maximum = int.Parse( Parameters[analyzer.SupportedDiagnostics.Single().Id].Single()["maximumFileLocThreshold"], NumberStyles.None, CultureInfo.InvariantCulture); builder.Add(analyzer); }
/// <summary> /// Read the working days file and return a List object with the working days data. If the file needs updating, send the updating or it doesn't exist, write the file.. /// </summary> /// /// <returns>bank holidays list</returns> public List <string> ReadWorkingDaysFile() { Handler = new ClientHandler(); Settings = Handler.Settings(); UpdateDays = int.Parse(Settings.GetSection("other")["BankHolidayUpdateDays"]); if (!Directory.Exists(Directory.GetCurrentDirectory() + @"\Includes") || (!File.Exists(Directory.GetCurrentDirectory() + @"\Includes\bankholidays.json"))) { WorkingDaysWriter writer = new WorkingDaysWriter(); WorkingDaysList = writer.WorkingDayWriter(); return(WorkingDaysList); } else { WorkingDaysList = new List <string>(); FileLines = File.ReadLines(Directory.GetCurrentDirectory() + @"\Includes\bankholidays.json"); LastUpdateDate = DateTime.Parse(FileLines.First()); if ((DateTime.UtcNow.Date - LastUpdateDate).TotalDays >= UpdateDays) { WorkingDaysWriter writer = new WorkingDaysWriter(); WorkingDaysList = writer.WorkingDayWriter(); return(WorkingDaysList); } else { foreach (string Line in FileLines) { WorkingDaysList.Add(Line); } WorkingDaysList.RemoveAt(0); return(WorkingDaysList); } } }
/// <summary> /// Applies the provided FileChange to the file's contents /// </summary> /// <param name="fileChange">The FileChange to apply to the file's contents.</param> public void ApplyChange(FileChange fileChange) { // Break up the change lines string[] changeLines = fileChange.InsertString.Split('\n'); if (fileChange.IsReload) { FileLines.Clear(); FileLines.AddRange(changeLines); } else { // VSCode sometimes likes to give the change start line as (FileLines.Count + 1). // This used to crash EditorServices, but we now treat it as an append. // See https://github.com/PowerShell/vscode-powershell/issues/1283 if (fileChange.Line == FileLines.Count + 1) { foreach (string addedLine in changeLines) { string finalLine = addedLine.TrimEnd('\r'); FileLines.Add(finalLine); } } // Similarly, when lines are deleted from the end of the file, // VSCode likes to give the end line as (FileLines.Count + 1). else if (fileChange.EndLine == FileLines.Count + 1 && string.Empty.Equals(fileChange.InsertString)) { int lineIndex = fileChange.Line - 1; FileLines.RemoveRange(lineIndex, FileLines.Count - lineIndex); } // Otherwise, the change needs to go between existing content else { ValidatePosition(fileChange.Line, fileChange.Offset); ValidatePosition(fileChange.EndLine, fileChange.EndOffset); // Get the first fragment of the first line string firstLineFragment = FileLines[fileChange.Line - 1] .Substring(0, fileChange.Offset - 1); // Get the last fragment of the last line string endLine = FileLines[fileChange.EndLine - 1]; string lastLineFragment = endLine.Substring( fileChange.EndOffset - 1, FileLines[fileChange.EndLine - 1].Length - fileChange.EndOffset + 1); // Remove the old lines for (int i = 0; i <= fileChange.EndLine - fileChange.Line; i++) { FileLines.RemoveAt(fileChange.Line - 1); } // Build and insert the new lines int currentLineNumber = fileChange.Line; for (int changeIndex = 0; changeIndex < changeLines.Length; changeIndex++) { // Since we split the lines above using \n, make sure to // trim the ending \r's off as well. string finalLine = changeLines[changeIndex].TrimEnd('\r'); // Should we add first or last line fragments? if (changeIndex == 0) { // Append the first line fragment finalLine = firstLineFragment + finalLine; } if (changeIndex == changeLines.Length - 1) { // Append the last line fragment finalLine += lastLineFragment; } FileLines.Insert(currentLineNumber - 1, finalLine); currentLineNumber++; } } } // Parse the script again to be up-to-date ParseFileContents(); }
public EmbeddedTextFile(string fileName) { lines = new FileLines(fileName); }
/// <summary> /// Renvoie l'index de la ligne où apparait le keyword passé en argument /// </summary> /// <param name="keyword">string, keyword à identifier</param> /// <returns>index de la ligne du tableau contenant les lignes du fichier texte</returns> /// protected int getLineIndex(string keyword) { return(FileLines.FindIndex(line => line.Contains(keyword))); }