public void SetUp()
 {
     pathToFile        = Environment.CurrentDirectory + "\\Source\\Class.cs";
     asyncReader       = new AsyncFileReader();
     sourceCode        = asyncReader.Read(pathToFile).Result;
     templateGenerator = new TemplateClassGenerator();
     sourceRoot        = CSharpSyntaxTree.ParseText(sourceCode).GetRoot();
 }
 public void SetUp()
 {
     pathToFile      = Environment.CurrentDirectory + "\\Result\\Test.cs";
     pathToDirectory = Environment.CurrentDirectory + "\\Result";
     asyncReader     = new AsyncFileReader();
     asyncWriter     = new AsyncFileWriter(pathToDirectory);
     fileName        = "Test.cs";
     testString      = "Write and read test!";
     template        = new TestClassTemplate(fileName, testString);
 }
Example #3
0
        public async Task TestFileReader()
        {
            var reader = new AsyncFileReader(@"D:\work\SchoneData_filtered.xml");

            var    cts     = new CancellationTokenSource();
            string content = await reader.Read(cts.Token).ConfigureAwait(false);

            cts.Cancel();
            Assert.IsNotEmpty(content);
        }
Example #4
0
        public void SetUp()
        {
            pathToFile  = Environment.CurrentDirectory + "\\SourceCodeFiles\\Class.cs";
            asyncReader = new AsyncFileReader();
            string sourceCode = asyncReader.Read(pathToFile).Result;

            syntaxProcessor     = new SyntaxProcessor();
            syntaxProcessResult = syntaxProcessor.Process(sourceCode);

            SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(sourceCode);

            root = syntaxTree.GetRoot();
        }
Example #5
0
        static async Task Main(string[] args)
        {
            // highest seat ID in the source data
            // convert "FBFBFB" notation to binary
            var seats = await AsyncFileReader.ReadLines("data.txt")
                        .Select(Seat.FromString)
                        .ToListAsync();

            var maxSeatID = seats.Max(s => s.SeatID);

            Console.WriteLine("Max seatID is {0}", maxSeatID);

            // find the unoccupied seats
            var allSeats = Enumerable.Range(0, maxSeatID)
                           .ToDictionary(n => n, n => seats.SingleOrDefault(s => s.SeatID == n));

            Console.WriteLine("Missing seats:");
            foreach (var index in allSeats.Where(kvp => kvp.Value == null))
            {
                Console.WriteLine(index.Key);
            }
        }
Example #6
0
        private static void Main(string[] args)
        {
            string path = "ExampleFile.txt";
            Random random = new Random();
            byte[] writtenBytes = new byte[1000000];
            for (int i = 0; i < writtenBytes.Length; ++i)
            {
                writtenBytes[i] = (byte)('A' + (i % 7));
            }

            AsyncFileWriter writer = new AsyncFileWriter(99999);
            writer.WriteAllBytesAsync(path, writtenBytes).Wait();
            Console.WriteLine("Wrote {0} bytes.", writtenBytes.Length);

            AsyncFileReader reader = new AsyncFileReader(100001);
            Task<byte[]> task = reader.ReadAllBytesAsync(path);
            byte[] readBytes = task.Result;
            Console.WriteLine("Read {0} bytes.", readBytes.Length);
            Console.WriteLine("First 30 bytes: " + Encoding.ASCII.GetString(readBytes, 0, 30));
            Console.WriteLine("Last 30 bytes: " + Encoding.ASCII.GetString(readBytes, readBytes.Length - 30, 30));

            if (writtenBytes.Length != readBytes.Length)
            {
                throw new InvalidOperationException("Lengths do not match.");
            }

            for (int i = 0; i < readBytes.Length; ++i)
            {
                if (writtenBytes[i] != readBytes[i])
                {
                    throw new InvalidOperationException("Mismatching byte values at index " + i);
                }
            }

            Console.WriteLine("All byte values match!");
        }