static void Main(string[] args)
        {
            string filePath        = @"c:\temp\text.txt";
            char   separatorObject = ' ';

            ReadingMethodology <int>         threadMethodology     = new ReadUsingThreads();
            ReadingMethodology <int>         threadPoolMethodology = new ReadUsingThreadPool();
            ReadingMethodology <int>         tasksMethodology      = new ReadUsingTasks();
            ReadingMethodology <Task <int> > asyncAwaitMethodology = new ReadUsingAsyncAwait();

            MyFileReader <int>         mfr  = new MyFileReader <int>(filePath, separatorObject);
            MyFileReader <Task <int> > mfr1 = new MyFileReader <Task <int> >(filePath, separatorObject);

            Console.WriteLine("Using threads...");
            int count = mfr.ReadFileBy(threadMethodology);

            Console.WriteLine("Final Result = " + count);

            Console.WriteLine("Using threadpool...");
            count = mfr.ReadFileBy(threadPoolMethodology);
            Console.WriteLine("Final Result = " + count);

            Console.WriteLine("Using tasks...");
            count = mfr.ReadFileBy(tasksMethodology);
            Console.WriteLine("Final Result = " + count);

            Console.WriteLine("Using async await...");
            Task <int> result = mfr1.ReadFileBy(asyncAwaitMethodology);

            Console.WriteLine("Final Result = " + result.Result);

            Console.Read();
        }
예제 #2
0
        public static void Main(string[] args)
        {
            /*
             * Create an instance of the LogicContoller class,
             * give it a new instance of the MyObject class,
             * then call the RunLogic method on the instance of
             * the LogicController class
             */
            var myObject        = MyObjectFactory.GenerateMyObject();
            var logicController = new LogicController(myObject);

            logicController.RunLogic();

            /*
             * Create an instance of the FileReader class;
             * Parse the contents of the medicationAttempt1.json;
             * Create a new instance of the LogicController and pass
             * it the parsed medication object;
             * Call the RunLogic method of the LogicController
             */
            var fileReader  = new MyFileReader();
            var fileContent = string.Empty;

            // Only run the logic if we could read the file
            if (fileReader.TryParseFile("medicationAttempt1.json", out fileContent))
            {
                var parsedMedication    = JsonConvert.DeserializeObject <Medication>(fileContent);
                var medsLogicController = new LogicController(parsedMedication);
                medsLogicController.RunLogic();
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            //Read file
            string       sampleFileName = "First.txt";
            MyFileReader myFileReader   = new MyFileReader(sampleFileName);
            string       text           = myFileReader.ReadFile();

            //Make tokens
            Token[] tokens = new LexicalAnalysis().ProcessTextAndGenerateTokens(text);
            tokens.ToList().ForEach(t => Console.WriteLine(t.ToString()));
            Console.WriteLine("--------------------------------------------------------------------\n\n");

            //Parse syntax analysis phase
            SyntaxAnalysis       syntaxAnalysis       = new SyntaxAnalysis(tokens);
            SyntaxAnalysisResult syntaxAnalysisResult = syntaxAnalysis.Parse();

            if (!syntaxAnalysisResult.SyntaxParsed)
            {
                Console.WriteLine(syntaxAnalysisResult.Exception.Message);
            }
            else
            {
                Console.WriteLine("Syntax Analysis phase passed");
            }



            Console.Read();
        }
예제 #4
0
        private static void ViewInHex(Object fileName)
        {
            _workerStarted = true;
            byte[] bytes;
            using (MyFileReader reader = new MyFileReader((String)fileName))
            {
                bytes = reader.ReadContents(20);
            }  // Using block calls Dispose() for us here.

            if (_printToConsole)
            {
                // Print up to 20 bytes.
                int printNBytes = Math.Min(20, bytes.Length);
                Console.WriteLine("First {0} bytes of {1} in hex", printNBytes, fileName);
                for (int i = 0; i < printNBytes; i++)
                {
                    Console.Write("{0:x} ", bytes[i]);
                }
                Console.WriteLine();
            }
        }