Esempio n. 1
0
        static void Main()
        {
            try
            {
                var mediaLibrary = new MediaLibrary(new MediaType[]
                {
                    new Album("Yellow Submarine", "The Beatles"),
                    new Album("The Wall", "Pink Floyd"),
                    new Album("Pet Sounds", "The Beach Boys"),
                    new Book("Moby-Dick", "Herman Melville"),
                    new Movie("Lawrence of Arabia", "David Lean")
                });

                Console.WriteLine("# of items: " + mediaLibrary.NumberOfItems);

                mediaLibrary.DisplayItems();

                // DetectMediaType(mediaLibrary.GetItemAt(0));
                // DetectMediaType(mediaLibrary.GetItemAt(1));
                // DetectMediaType(mediaLibrary.GetItemAt(2));
                // DetectMediaType(mediaLibrary.GetItemAt(3));
                // DetectMediaType(mediaLibrary.GetItemAt(4));

                // Search the media library for an item by calling the 'FindItem()' method.
                MediaType foundItem = mediaLibrary.FindItem("arabia");
                if (foundItem != null)
                {
                    // If an item is found, pass it into a call to the static MediaLibrary 'DisplayItem()' method
                    Console.WriteLine("Item found: ");
                    MediaLibrary.DisplayItem(foundItem);
                }
                else
                {
                    // If an item isn't found, write the message 'Item not found!' to the console
                    Console.WriteLine("Item not found!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
        }
Esempio n. 2
0
        static void Main()
        {
            try {
                MediaLibrary library = new MediaLibrary(MediaRepository.LoadMedia(), "Chris");
                Console.WriteLine($"There are {library.NumberOfItems} items in {library.Name}");
                library.DisplayItems();

                MediaItem search = library.FindItem("Symphony");
                if (search != null)
                {
                    library.DisplayItem(search);
                }
                else
                {
                    Console.WriteLine("MediaItem not found!");
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }