/*
         * Method to Generate the SONGS JSON and return the
         * serialized String to the UI.
         */
        public static string generateSongJSON()
        {
            BandsCollection bands = DeserializeBandSchema();

            if (bands != null)
            {
                List <Songs> songs = new List <Songs>();

                foreach (BandJSON band in bands.band)
                {
                    foreach (Songs song in band.Songs)
                    {
                        Songs songDetails = new Songs
                        {
                            BandName = band.BandName,
                            SongName = song.SongName,
                            Rating   = song.Rating,
                            Duration = song.Duration
                        };
                        songs.Add(songDetails);
                    }
                }

                return(JsonConvert.SerializeObject(songs));
            }
            else
            {
                return("");
            }
        }
        private static void CollectionExample()
        {
            Console.WriteLine();
            Console.WriteLine("-----------------------------Collection Example-----------------------------");

            var bandsCollection = new BandsCollection(BandsArray);

            //Custom insert example
            bandsCollection.Insert(0, new Band("Guta", 0, "", ""));
            bandsCollection.Insert(3, new Band("Salam", 0, "", ""));
            bandsCollection.Insert(9, new Band("Susanu", 0, "", ""));

            //Custom item set example
            bandsCollection[3] = new Band("Romeo Fantastik", 0, "", "");

            //Custom remove example
            bandsCollection.RemoveAt(8);

            Console.WriteLine();

            foreach (var bandName in BandNames(bandsCollection))
            {
                Console.WriteLine(bandName);
            }

            //TODO 3: Update bandsCollection.Clear() so it prints the removed items.
        }
        private static void CollectionExample()
        {
            Console.WriteLine();
            Console.WriteLine("=====Example 3 (Collection example)=====");

            var bandsCollection = new BandsCollection(BandsArray);

            //Custom insert example
            bandsCollection.Insert(0, new Band("Band X", 0, "", ""));
            bandsCollection.Insert(3, new Band("Band Y", 0, "", ""));
            bandsCollection.Insert(9, new Band("Band Z", 0, "", ""));

            //Custom item set example
            bandsCollection[3] = new Band("Band W", 0, "", "");

            //Custom remove example
            bandsCollection.RemoveAt(8);

            Console.WriteLine();

            foreach (var bandName in BandNames(bandsCollection))
            {
                Console.WriteLine(bandName);
            }

            //TODO 3: Update bandsCollection.Clear() so it prints the removed items.
        }
        private static void CollectionExample()
        {
            Console.WriteLine();
            Console.WriteLine("-----------------------------Collection Example-----------------------------");

            var bandsCollection = new BandsCollection(BandsArray);

            //Custom insert example
            bandsCollection.Insert(0, new Band("Guta", 0, "", ""));
            bandsCollection.Insert(3, new Band("Salam", 0, "", ""));
            bandsCollection.Insert(9, new Band("Susanu", 0, "", ""));

            //Custom item set example
            bandsCollection[3] = new Band("Romeo Fantastik", 0, "", "");

            //Custom remove example
            bandsCollection.RemoveAt(8);

            Console.WriteLine();

            foreach (var bandName in BandNames(bandsCollection))
            {
                Console.WriteLine(bandName);
            }

            //TODO 3: Update bandsCollection.Clear() so it prints the removed items.
        }
        /*
         * Method to Generate the BAND NAMES JSON and return the
         * serialized String to the UI.
         */
        public static string generateBandNames()
        {
            BandsCollection bands     = DeserializeBandSchema();
            List <string>   bandNames = new List <string>();

            foreach (BandJSON band in bands.band)
            {
                bandNames.Add(band.BandName);
            }

            return(JsonConvert.SerializeObject(bandNames));
        }
        /*
         * Method to Generate the BANDS JSON and return the
         * serialized String to the UI.
         */
        public static string generateBandJSON()
        {
            BandsCollection bands = DeserializeBandSchema();

            if (bands != null)
            {
                return(JsonConvert.SerializeObject(bands));
            }
            else
            {
                return("");
            }
        }
        /*
         * Method to Generate the SONG NAMES JSON and return the
         * serialized String to the UI.
         */
        public static string generateSongNames()
        {
            BandsCollection bands     = DeserializeBandSchema();
            List <string>   songNames = new List <string>();

            foreach (BandJSON band in bands.band)
            {
                foreach (Songs song in band.Songs)
                {
                    songNames.Add(song.SongName);
                }
            }

            return(JsonConvert.SerializeObject(songNames));
        }
        /*
         * Utility Method to deserialize the bands XML Schema and return a c# object
         */
        public static BandsCollection DeserializeBandSchema()
        {
            BandsCollection bands = null;

            XmlSerializer serializer = new XmlSerializer(typeof(BandsCollection));
            WebClient     client     = new WebClient();
            Uri           uri        = HttpContext.Current.Request.Url;
            String        host       = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
            Stream        stream     = client.OpenRead(host + "/BandSchema.xml");
            StreamReader  reader     = new StreamReader(stream);

            bands = (BandsCollection)serializer.Deserialize(reader);

            reader.Close();

            return(bands);
        }
Beispiel #9
0
        public static string SearchBands(string searchString)
        {
            BandsCollection bands         = JsonConvert.DeserializeObject <BandsCollection>(JSONGenerator.generateBandJSON());
            List <BandJSON> searchResults = new List <BandJSON>();

            foreach (BandJSON band in bands.band)
            {
                if (band.BandName.IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    searchResults.Add(band);
                }
            }
            BandsCollection result = new BandsCollection();

            result.band = searchResults;
            return(JsonConvert.SerializeObject(result));
        }