コード例 #1
0
ファイル: Program.cs プロジェクト: qctran/CSharpPractice
 /// <summary>
 /// This method will go through all sample data from the testDevice.
 /// </summary>
 /// <param name="dataProc"></param>
 /// <param name="tempProc"></param>
 private static void ShowAllData(DataProcessor dataProc, TemperatureProcessor tempProc)
 {
     try
     {
         Console.WriteLine("Press [ESC] to exit.");
         do
         {
             var data = dataProc.Read();
             tempProc.PrintTemperature(data);
         } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
     }
     catch (Exception e)
     {
         Console.WriteLine($"{e.Message}\r\n{e.StackTrace}");
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: qctran/CSharpPractice
        static void Main()
        {
            // Create an output object to where we want the output to.
            // Console or file...
            var output = new ConsoleDisplay();

            // We can create a Fahrenheit calculator and inject that to the
            // TemperatureProcessor if we want to convert to F degree.
            var calculator = new CelsiusCalculator();

            // Create a testDevice instance that return fake data.
            var factory = new DeviceFactory();
            var device  = factory.GetDevice(true); // True to get simulator data

            // Inject an output object so the Validator can either write
            // to console or file.
            var validator = new Validator(output);

            var dataProc = new DataProcessor(device);
            var tempProc = new TemperatureProcessor(calculator, validator, output);

            ShowAllData(dataProc, tempProc);
        }