Exemplo n.º 1
0
        static void Main(string[] args)
        {
            OLEDScreen        screen                  = new OLEDScreen(5, 1920, 1080);
            LithiumLonBattery battery                 = new LithiumLonBattery(4000);
            PhoneSpeaker      speaker                 = new PhoneSpeaker(1000, new ConsoleOutput());
            SimCorpMobile     simMobile               = new SimCorpMobile(screen, battery, speaker);
            SamsungHeadset    samsungHeadsetComp      = new SamsungHeadset(300, new ConsoleOutput());
            IPhoneHeadset     iPhoneHeadsetComp       = new IPhoneHeadset(350, new ConsoleOutput());
            IAudioController  samsungHeadset          = (IAudioController)samsungHeadsetComp;
            IAudioController  iPhoneHeadset           = (IAudioController)iPhoneHeadsetComp;
            List <string>     playComponentsMenuItems = new List <string>();

            playComponentsMenuItems.Add("Phone speaker");
            playComponentsMenuItems.Add("Samsung Headset");
            playComponentsMenuItems.Add("iPhone Headset");
            int userPlaybackChoice = 0;

            while (true)
            {
                while (userPlaybackChoice == 0)
                {
                    Console.WriteLine(simMobile.ToString());
                    Console.WriteLine("Please select component (specify index)\n");
                    foreach (string item in playComponentsMenuItems)
                    {
                        Console.Write(playComponentsMenuItems.IndexOf(item) + 1 + ". ");
                        Console.WriteLine(item);
                    }
                    Console.Write("\nYour choice: ");
                    userPlaybackChoice = CheckUserInput(Console.ReadLine(), playComponentsMenuItems);
                }
                switch (userPlaybackChoice)
                {
                case 1:
                    simMobile.Play();
                    break;

                case 2:
                    simMobile.Play(samsungHeadset);
                    break;

                case 3:
                    simMobile.Play(iPhoneHeadset);
                    break;
                }
                userPlaybackChoice = 0;
                Console.ReadKey();
                Console.Clear();
            }
        }
Exemplo n.º 2
0
        private void applyButton_Click(object sender, EventArgs e)
        {
            OLEDScreen     OLEDScreen     = new OLEDScreen(768, 1024);
            LiPoBattery    liPoBattery    = new LiPoBattery(4100, 3.7, 83);
            MultiCoreCPU   multiCoreCPU   = new MultiCoreCPU("SnapDragon", 2.1, 2);
            MessageStorage messageStorage = new MessageStorage("+380971994730");
            SimCorpMobile  scmobile       = new SimCorpMobile(OLEDScreen, liPoBattery, multiCoreCPU, messageStorage);
            WinFormsOutput winFormOutput  = new WinFormsOutput(this);

            listBox.Items.Clear();
            if (radioButtoniPhone.Checked == true)
            {
                scmobile.PlaybackComponent = new iPhoneHeadset(winFormOutput);
            }
            else if (radioButtonSamsung.Checked == true)
            {
                scmobile.PlaybackComponent = new SamsungHeadset(winFormOutput);
            }
            else if (radioButtonNoNameHeadset.Checked == true)
            {
                scmobile.PlaybackComponent = new NoNameHeadset(winFormOutput);
            }
            else if (radioButtonPhoneSpeaker.Checked == true)
            {
                scmobile.PlaybackComponent = new PhoneSpeaker(winFormOutput);
            }
            else
            {
                listBox.Items.Add("Nothing is selected");
            }
            scmobile.Play("Unknown Artist - His Song");
        }
Exemplo n.º 3
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!");
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        public void NoPlaybackComponent()
        {
            //Arrange
            IOutput output = new FakeOutput();
            var     mobile = new SimCorpMobile();

            mobile.Output = output;
            var expect = "Test Output is running";

            //Act
            var actual = mobile.Play(new object());

            //Assert
            Assert.AreEqual(expect, actual);
        }
Exemplo n.º 6
0
        private static void Main()
        {
            Mobile mobile = new SimCorpMobile();

            mobile.Output = new ConsoleOutput();

            mobile.Output.WriteLine(mobile.ToString());

            mobile.SelectPlaybackComponent();
            mobile.Play(new object());
            mobile.SelectChargeComponent();
            mobile.Charge();

            Console.ReadKey();
        }
Exemplo n.º 7
0
        private void bApply_Click(object sender, EventArgs e)
        {
            //=======================================================================================
            //Clear textBox
            tbOutput.Clear();
            //return Selected radiobutton index
            int SelectedRadioButtonIndex = CheckSelectedRadioButton(WinForm);
            //create class with DI
            SimCorpMobile MyMobile = new SimCorpMobile(WinForm);

            //create component class
            MyMobile.PlaybackComponent = MyMobile.PlayBackFactory.Create(SelectedRadioButtonIndex);
            //show playing device in textbox
            MyMobile.Play();
            //=======================================================================================
        }
Exemplo n.º 8
0
        private static void Main()
        {
            var output          = new ConsoleOutput();
            var mobileOptions   = new MobileOptions(output);
            var playbackOptions = mobileOptions.PlaybackOptions;
            var displayOptions  = mobileOptions.DisplayOptions;

            var playbackChoice = playbackOptions[ChooseFromList("playback components", playbackOptions, output)];
            var displayChoice  = displayOptions[ChooseFromList("display component", displayOptions, output)];

            output.WriteLine($"{ playbackChoice.GetName()}, {displayChoice.GetName()} selected.");

            var mobile = new SimCorpMobile {
                PlaybackComponent = playbackChoice,
                DisplayComponent  = displayChoice
            };

            mobile.Play("");
            mobile.Display("");
            Console.ReadLine();
        }