private static string ToString(IReadable readable) { using (var sr = new StreamReader(readable.Open())) { return(sr.ReadToEnd()); } }
public async Task WriteTo(Stream destination, CancellationToken cancel) { using (var source = readable.Open()) { await source.CopyToAsync(destination, 32 * 1024, cancel).ConfigureAwait(false); } }
private static M <double> Transform(IReadable readable, CsvReaderSettings csvReaderSettings) { using (var sr = new StreamReader(readable.Open())) { var csvReader = new CsvReader(csvReaderSettings); var splitted = csvReader.Read(sr).ToArray(); var rows = splitted.Length; int maxCols = 0; if (rows > 0) { maxCols = splitted[0].Length; for (var i = 1; i < rows; i++) { if (splitted[i].Length > maxCols) { maxCols = splitted[i].Length; } } } return(M.Generate <double>(rows, maxCols, (row, col) => { double value; if (row < rows && col < splitted[row].Length && double.TryParse(splitted[row][col], NumberStyles.Any, CultureInfo.InvariantCulture, out value)) { return value; } return 0; })); } }
public static SKBitmap DecodeBitmap( [InputPin(PropertyMode = PropertyMode.Never)] IReadable source ) { using (var stream = source.Open()) { return(SKBitmap.Decode(stream)); } }
private static V <double> Transform(IReadable readable, CsvReaderSettings csvReaderSettings) { using (var sr = new StreamReader(readable.Open())) { var csvReader = new CsvReader(csvReaderSettings); var splitted = csvReader.Read(sr).ToArray(); var rows = splitted[0].Length; var v = V <double> .Generate <double>((row) => { double value; if (row < rows && double.TryParse(splitted[0][row], NumberStyles.Any, CultureInfo.InvariantCulture, out value)) { return(value); } return(0); }, rows); return(v); } }
static void Main() { bool stopProgram = false; string defaultInputPath = Repository.GetAbsolutePath("../../Input Files/"); string defaultOutputPath = Repository.GetAbsolutePath("../../Output Files/"); string file1Type; string file2Type; int granularity; Console.WriteLine("File Difference Analyser"); Console.WriteLine("Type 'diff <file1> <file2>' to view the differences between two files"); Console.WriteLine("By default, characters are analysed. To view word differences, use the '\\w' argument"); Console.WriteLine("To change the default directory type 'setpath <path>' where <path> is rooted at C://"); Console.WriteLine("Type 'help' for a list of commands"); //While the user does not choose to terminate the program while (!stopProgram) { UI.Break(); UserInput input = UI.InterpretUserInput(UI.GetUserInput()); if (input.Error == "") { if (!input.CommandIsNull) { if (input.Command == "diff") { UI.Break(); file1Type = Repository.GetFileExtention(input.Parameters[0]); file2Type = Repository.GetFileExtention(input.Parameters[1]); IReadable file1 = RENAME(file1Type); IReadable file2 = RENAME(file2Type); if (!file1.Open(defaultInputPath + input.Parameters[0])) { Console.WriteLine("Parameter 1: '" + file1.Name + "' could not be opened"); } if (!file2.Open(defaultInputPath + input.Parameters[1])) { Console.WriteLine("Parameter 2: '" + file2.Name + "' could not be opened"); } granularity = input.Arguments.Contains("/l") ? 0 : 2; granularity = input.Arguments.Contains("/w") ? 1 : granularity; IWritable outputFile; if (input.Arguments.Contains("/c")) { outputFile = new CSVFile(); } else if (input.Arguments.Contains("/t")) { outputFile = new TSVFile(); } else { outputFile = new TXTFile(); } outputFile.Create(defaultOutputPath); List <string> file1Content = file1.Read(); List <string> file2Content = file2.Read(); if (file1Content.SequenceEqual(file2Content)) { string[] fileContent = outputFile.CreateDiffForFile(granularity, file1.Name, file2.Name); outputFile.Write(fileContent); Console.WriteLine("The two files were identical."); } else { List <Line> lines = file1.FindDifference(file2.Read(), granularity); string[] fileContent = outputFile.CreateDiffForFile(granularity, file1.Name, file2.Name, lines); UI.DisplayDiffOutput(lines); outputFile.Write(fileContent); } UI.Break(); Console.WriteLine("A summary file was placed inside:"); Console.WriteLine(defaultOutputPath); } else if (input.Command == "inputdir") { UI.Break(); defaultInputPath = UI.MakePathLegal(input.Parameters[0]); Console.WriteLine("The input directory for files has been changed"); } else if (input.Command == "outputdir") { UI.Break(); defaultOutputPath = UI.MakePathLegal(input.Parameters[0]); Console.WriteLine("The output directory for files has been changed"); } else if (input.Command == "showinputdir") { UI.Break(); Console.WriteLine(defaultInputPath); } else if (input.Command == "showoutputdir") { UI.Break(); Console.WriteLine(defaultOutputPath); } else if (input.Command == "help") { UI.Break(); UI.DisplayHelp(); } else if (input.Command == "quit") { stopProgram = true; } else { UI.Break(); Console.WriteLine("'" + input.Command + "' is not a valid command"); Console.WriteLine("Type 'help' to view all commands"); } } } else { UI.Break(); Console.WriteLine(input.Error); } } }