Beispiel #1
0
        public static RadioRecorder FromRecorder(TrunkRecorder.Recorder recorder)
        {
            var radioRecorder = new RadioRecorder();

            radioRecorder.UpdateFromRecorder(recorder);
            return(radioRecorder);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var consoleWriter = new ConsoleWriter();

            consoleWriter.WriteLineWithGreen("Class MobilePhone\n");

            MobilePhone mobilePhone = new MobilePhone(consoleWriter);

            //mobilePhone.Call("+7916291XXXX");
            mobilePhone.MusicSource = "Music in a Social Network";
            //mobilePhone.PlayMusic();
            //mobilePhone.Restart();

            consoleWriter.WriteLineWithGreen("\nClass RadioRecorder\n");

            var radioRecorder = new RadioRecorder(consoleWriter);

            radioRecorder.MusicSource = "FM Radio Channel";
            //radioRecorder.PlayMusic();
            //radioRecorder.RecordingDestination = "Flash Drive";
            //radioRecorder.RecordMusic(TimeSpan.FromSeconds(15));
            //radioRecorder.Restart();

            consoleWriter.WriteLineWithGreen("\nClass VideoPlayer\n");

            var videoPlayer = new VideoPlayer(consoleWriter);

            //videoPlayer.VideoSource = "YouTube";
            //videoPlayer.PlayVideo();
            //videoPlayer.PlayMusic();
            videoPlayer.MusicSource = "Podcast Server";
            //videoPlayer.PlayMusic();
            //videoPlayer.Restart();

            consoleWriter.WriteLine("\n\n");

            IMusicPlayer[] someMusicPlayers =
            {
                mobilePhone,
                radioRecorder,
                videoPlayer
            };

            foreach (IMusicPlayer musicPlayer in someMusicPlayers)
            {
                musicPlayer.PlayMusic();
            }
        }
        private async Task HandleRecordersAsync(List <Recorder> recorders, CancellationToken cancellationToken = default(CancellationToken))
        {
            foreach (var recorder in recorders)
            {
                var radioRecorder = await DbContext.Recorders
                                    .FirstOrDefaultAsync(r => r.RecorderIdentifier == recorder.Id);

                if (radioRecorder == null)
                {
                    radioRecorder = RadioRecorder.FromRecorder(recorder);
                    await DbContext.Recorders.AddAsync(radioRecorder, cancellationToken);
                }
                else
                {
                    radioRecorder.UpdateFromRecorder(recorder);
                }
            }

            await DbContext.SaveChangesAsync();
        }
        private static void Main(string[] args)
        {
            var consoleWriter = new ConsoleWriter();

            consoleWriter.WriteLine("Class MobilePhone\n", ConsoleColor.Green);

            var mobilePhone = new MobilePhone(consoleWriter);

            mobilePhone.Call("+7916291XXXX");
            mobilePhone.MusicSource = "Music in a Social Network";
            mobilePhone.PlayMusic();
            mobilePhone.Restart();

            consoleWriter.WriteLine("\nClass RadioRecorder\n", ConsoleColor.Green);

            var radioRecorder = new RadioRecorder(consoleWriter)
            {
                MusicSource = "FM Radio Channel"
            };

            radioRecorder.PlayMusic();
            radioRecorder.RecordingDestination = "Flash Drive";
            radioRecorder.RecordMusic(TimeSpan.FromSeconds(15));
            radioRecorder.Restart();

            consoleWriter.WriteLine("\nClass VideoPlayer\n", ConsoleColor.Green);

            var videoPlayer = new VideoPlayer(consoleWriter)
            {
                VideoSource = "YouTube"
            };

            videoPlayer.PlayVideo();
            videoPlayer.PlayMusic();
            videoPlayer.MusicSource = "Podcast Server";
            videoPlayer.PlayMusic();
            videoPlayer.Restart();

            consoleWriter.WriteLine("\n\n");
            consoleWriter.ReadKey();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //AbstractMusicPlayer amp = new AbstractMusicPlayer();

            var consoleWriter = new ConsoleWriter();

            //consoleWriter.WriteLineWithGreen("Class MobilePhone\n");

            var mobilePhone = new MobilePhone(consoleWriter);

            //mobilePhone.Call("+7916291XXXX");
            //mobilePhone.MusicSource = "Music in a Social Network";
            //mobilePhone.PlayMusic();
            //mobilePhone.Restart();

            consoleWriter.WriteLineWithGreen("\nClass RadioRecorder\n");

            var radioRecorder = new RadioRecorder(consoleWriter);

            //radioRecorder.MusicSource = "FM Radio Channel";
            //radioRecorder.PlayMusic();
            //radioRecorder.RecordingDestination = "Flash Drive";
            //radioRecorder.RecordMusic(TimeSpan.FromSeconds(15));
            //radioRecorder.Restart();

            consoleWriter.WriteLineWithGreen("\nClass VideoPlayer\n");

            var videoPlayer = new VideoPlayer(consoleWriter);

            //videoPlayer.VideoSource = "YouTube";
            //videoPlayer.PlayVideo();
            //videoPlayer.PlayMusic();
            //videoPlayer.MusicSource = "Podcast Server";
            //videoPlayer.PlayMusic();
            //videoPlayer.Restart();

            consoleWriter.WriteLine("\n\n");


            object[] devices = new object[3];
            devices[0] = mobilePhone;
            devices[1] = radioRecorder;
            devices[2] = videoPlayer;

            foreach (object device in devices)
            {
                if (device is AbstractMusicPlayer)
                {
                    ((AbstractMusicPlayer)device).MusicSource = "Internet";
                    ((AbstractMusicPlayer)device).PlayMusic();
                }

                if (device is ICaller)
                {
                    ((ICaller)device).Call("555-55-55");
                }

                if (device is VideoPlayer)
                {
                    ((VideoPlayer)device).VideoSource = "Internet";
                    ((VideoPlayer)device).PlayVideo();
                }

                if (device is IMusicRecoder)
                {
                    ((IMusicRecoder)device).RecordingDestination = "flash";
                    ((IMusicRecoder)device).RecordMusic(TimeSpan.FromSeconds(10));
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var consoleWriter = new ConsoleWriter();

            var mobilePhone = new MobilePhone(consoleWriter);

            mobilePhone.MusicSource = "Music in a Social Network";

            var radioRecorder = new RadioRecorder(consoleWriter);

            radioRecorder.MusicSource          = "FM Radio Channel";
            radioRecorder.RecordingDestination = "Flash Drive";

            var videoPlayer = new VideoPlayer(consoleWriter);

            videoPlayer.VideoSource = "YouTube";
            videoPlayer.MusicSource = "Podcast Server";

            consoleWriter.WriteLine("\n");

            var devices = new AbstractMusicPlayer[]
            {
                mobilePhone,
                radioRecorder,
                videoPlayer
            };

            // each device will do all the actions it can do according to implemented interfaces
            foreach (object device in devices)
            {
                consoleWriter.WriteLineWithGreen($"\n{device.GetType().Name}");

                if (device is IMusicPlayer && device != null)
                {
                    if (!string.IsNullOrEmpty((device as IMusicPlayer).MusicSource))
                    {
                        (device as IMusicPlayer).PlayMusic();
                    }
                }

                if (device is IVideoPlayer && device != null)
                {
                    if (!string.IsNullOrEmpty((device as IVideoPlayer).VideoSource))
                    {
                        (device as IVideoPlayer).PlayVideo();
                    }
                }

                if (device is IMusicRecorder && device != null)
                {
                    if (!string.IsNullOrEmpty((device as IMusicRecorder).RecordingDestination))
                    {
                        (device as IMusicRecorder).RecordMusic(TimeSpan.FromMinutes(20));
                    }
                }

                if (device is ICaller && device != null)
                {
                    (device as ICaller).Call("+7916291XXXX");
                }

                if (device is IRestartable && device != null)
                {
                    (device as IRestartable).Restart();
                }
            }
        }