Beispiel #1
0
        private void buttonApplyPlaybackComp_Click(object sender, EventArgs e)
        {
            richTextBoxPlaybackCompInfo.Clear();
            string selectedItem       = comboBoxSelectPlaybackComp.Text;
            var    playableDeviceType = PlaybackDeviceType.None;

            if (selectedItem == "PhoneHeadset")
            {
                playableDeviceType = PlaybackDeviceType.PhoneHeadset;
            }
            else if (selectedItem == "PhoneSpeaker")
            {
                playableDeviceType = PlaybackDeviceType.PhoneSpeaker;
            }

            IOutput winformOutput = new WinFormOutput(richTextBoxPlaybackCompInfo);

            if (playableDeviceType != PlaybackDeviceType.None)
            {
                var mobilePhone    = new SimCorpMobile();
                var playbackDevice = PlaybackDeviceFactory.CreatePlaybackDevice(playableDeviceType, winformOutput);
                mobilePhone.Play(playbackDevice, winformOutput);
            }
            else
            {
                winformOutput.WriteLine("Select PlaybackDeviceType!");
            }
        }
Beispiel #2
0
        static void Main()
        {
            /// Lab1
            var mobilePhone = new SimCorpMobile();

            Console.WriteLine(mobilePhone);

            /// Lab2
            IOutput consoleOutput = new ConsoleOutput();

            consoleOutput.WriteLine("Select playback component(select index):");
            consoleOutput.WriteLine($"{(int)PlaybackDeviceType.PhoneHeadset} - {PlaybackDeviceType.PhoneHeadset.ToString()}");
            consoleOutput.WriteLine($"{(int)PlaybackDeviceType.PhoneSpeaker} - {PlaybackDeviceType.PhoneSpeaker.ToString()}");
            var playableDeviceTypeString = Console.ReadLine();

            try
            {
                var playableDeviceType = CallTryParse(playableDeviceTypeString);
                var playbackDevice     = PlaybackDeviceFactory.CreatePlaybackDevice((PlaybackDeviceType)playableDeviceType, consoleOutput);
                /// Method Injection
                /// Inject the dependency into a single method and generally for the use of that method
                /// It could be useful, where the whole class does not need the dependency, only one method having that dependency
                /// This is the way is rarely used, but it is what we need in this case
                mobilePhone.Play(playbackDevice, consoleOutput);
            }
            catch (ArgumentException ex)
            {
                consoleOutput.WriteLine(ex.Message);
            }

            Console.ReadKey();
        }