예제 #1
0
        public List <MusicArtist> Search(MusicArtist musicArtist, string path)
        {
            currentDoc = XDocument.Load(@path);
            resList    = new List <MusicArtist>();

            List <XElement> matches = (from value in currentDoc.Descendants("MusicArtist")
                                       where ((musicArtist.Name == String.Empty || musicArtist.Name == value.Attribute("Name").Value) &&
                                              (musicArtist.Genre == String.Empty || musicArtist.Genre == value.Attribute("MajorGenre").Value) &&
                                              (musicArtist.IncomePerYear == String.Empty || musicArtist.IncomePerYear == value.Attribute("IncomePerYear").Value) &&
                                              (musicArtist.Country == String.Empty || musicArtist.Country == value.Attribute("Country").Value) &&
                                              (musicArtist.Band == String.Empty || musicArtist.Band == value.Attribute("ArtistBand").Value) &&
                                              (musicArtist.Activity == String.Empty || musicArtist.Activity == value.Attribute("MusicActivity").Value))
                                       select value).ToList();

            foreach (XElement match in matches)
            {
                MusicArtist artist = new MusicArtist();
                artist.Name          = match.Attribute("Name").Value;
                artist.Genre         = match.Attribute("MajorGenre").Value;
                artist.Country       = match.Attribute("Country").Value;
                artist.IncomePerYear = match.Attribute("IncomePerYear").Value;
                artist.Band          = match.Attribute("ArtistBand").Value;
                artist.Activity      = match.Attribute("MusicActivity").Value;
                resList.Add(artist);
            }
            return(resList);
        }
예제 #2
0
 public bool Compare(MusicArtist temp)
 {
     if (this.Name == temp.Name && this.Genre == temp.Genre && this.Country == temp.Country &&
         this.IncomePerYear == temp.IncomePerYear && this.Band == temp.Band && this.Activity == temp.Activity)
     {
         return(true);
     }
     return(false);
 }
예제 #3
0
        public MusicArtist GetInfo(XmlNode node)
        {
            MusicArtist mA = new MusicArtist();

            mA.Name          = node.Attributes.GetNamedItem("Name").Value;
            mA.Genre         = node.Attributes.GetNamedItem("MajorGenre").Value;
            mA.Country       = node.Attributes.GetNamedItem("Country").Value;
            mA.IncomePerYear = node.Attributes.GetNamedItem("IncomePerYear").Value;
            mA.Band          = node.Attributes.GetNamedItem("ArtistBand").Value;
            mA.Activity      = node.Attributes.GetNamedItem("MusicActivity").Value;

            return(mA);
        }
예제 #4
0
        public List <MusicArtist> Search(MusicArtist musicArtist, string path)
        {
            List <MusicArtist> resList = new List <MusicArtist>();
            XmlReader          reader  = XmlReader.Create(path);

            MusicArtist found = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.Name == "MusicArtist")
                    {
                        found = new MusicArtist();
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.Name == "Name")
                            {
                                found.Name = reader.Value;
                            }
                            if (reader.Name == "MajorGenre")
                            {
                                found.Genre = reader.Value;
                            }
                            if (reader.Name == "Country")
                            {
                                found.Country = reader.Value;
                            }
                            if (reader.Name == "IncomePerYear")
                            {
                                found.IncomePerYear = reader.Value;
                            }
                            if (reader.Name == "ArtistBand")
                            {
                                found.Band = reader.Value;
                            }
                            if (reader.Name == "MusicActivity")
                            {
                                found.Activity = reader.Value;
                            }
                        }
                        resList.Add(found);
                    }
                    break;
                }
            }
            lastRes = Filter(resList, musicArtist);
            return(lastRes);
        }
예제 #5
0
        private void Search()
        {
            resBox.Clear();
            musicArtist = new MusicArtist();
            IStrategy chosenStrategy;

            if (artistBox.Checked)
            {
                musicArtist.Name = artistCmbBox.Text;
            }
            if (genreBox.Checked)
            {
                musicArtist.Genre = genreCmbBox.Text;
            }
            if (countryBox.Checked)
            {
                musicArtist.Country = countryCmbBox.Text;
            }
            if (incomeBox.Checked)
            {
                musicArtist.IncomePerYear = incomeCmbBox.Text;
            }
            if (bandBox.Checked)
            {
                musicArtist.Band = bandCmbBox.Text;
            }
            if (activityBox.Checked)
            {
                musicArtist.Activity = activityCmbBox.Text;
            }

            if (domBtn.Checked)
            {
                chosenStrategy = new DOM();
                List <MusicArtist> resList = chosenStrategy.Search(musicArtist, path);
                ShowResults(resList);
            }
            if (saxBtn.Checked)
            {
                chosenStrategy = new SAX();
                List <MusicArtist> resList = chosenStrategy.Search(musicArtist, path);
                ShowResults(resList);
            }
            if (linqToXmlBtn.Checked)
            {
                chosenStrategy = new LINQtoXML();
                List <MusicArtist> resList = chosenStrategy.Search(musicArtist, path);
                ShowResults(resList);
            }
        }
예제 #6
0
        private List <MusicArtist> Filter(List <MusicArtist> resList, MusicArtist temp)
        {
            List <MusicArtist> newRes = new List <MusicArtist>();

            if (resList != null)
            {
                foreach (MusicArtist artist in resList)
                {
                    if ((temp.Name == artist.Name || temp.Name == String.Empty) &&
                        (temp.Genre == artist.Genre || temp.Genre == String.Empty) &&
                        (temp.Country == artist.Country || temp.Country == String.Empty) &&
                        (temp.IncomePerYear == artist.IncomePerYear || temp.IncomePerYear == String.Empty) &&
                        (temp.Band == artist.Band || temp.Band == String.Empty) &&
                        (temp.Activity == artist.Activity || temp.Activity == String.Empty))
                    {
                        newRes.Add(artist);
                    }
                }
            }
            return(newRes);
        }
예제 #7
0
        public List <MusicArtist> CheckNodes(List <List <MusicArtist> > artists, MusicArtist obj)
        {
            List <MusicArtist> newRes = new List <MusicArtist>();

            foreach (List <MusicArtist> artList in artists)
            {
                foreach (MusicArtist artist in artList)
                {
                    if ((obj.Name == artist.Name || obj.Name == String.Empty) &&
                        (obj.Genre == artist.Genre || obj.Genre == String.Empty) &&
                        (obj.Country == artist.Country || obj.Country == String.Empty) &&
                        (obj.IncomePerYear == artist.IncomePerYear || obj.IncomePerYear == String.Empty) &&
                        (obj.Band == artist.Band || obj.Band == String.Empty) &&
                        (obj.Activity == artist.Activity || obj.Activity == String.Empty))
                    {
                        newRes.Add(artist);
                    }
                }
            }
            return(newRes);
        }
예제 #8
0
        public List <MusicArtist> Search(MusicArtist musicArtist, string path)
        {
            XmlDocument currentDoc = new XmlDocument();

            currentDoc.Load(path);
            List <List <MusicArtist> > resList = new List <List <MusicArtist> >();

            if (musicArtist.Name == String.Empty && musicArtist.Genre == String.Empty && musicArtist.Country == String.Empty &&
                musicArtist.IncomePerYear == String.Empty && musicArtist.Band == String.Empty && musicArtist.Activity == String.Empty)
            {
                return(CatchError(currentDoc));
            }

            if (musicArtist.Name != String.Empty)
            {
                resList.Add(SearchByAttribute("MusicArtist", "Name", musicArtist.Name, currentDoc));
            }
            if (musicArtist.Genre != String.Empty)
            {
                resList.Add(SearchByAttribute("MusicArtist", "MajorGenre", musicArtist.Genre, currentDoc));
            }
            if (musicArtist.Country != String.Empty)
            {
                resList.Add(SearchByAttribute("MusicArtist", "Country", musicArtist.Country, currentDoc));
            }
            if (musicArtist.IncomePerYear != String.Empty)
            {
                resList.Add(SearchByAttribute("MusicArtist", "IncomePerYear", musicArtist.IncomePerYear, currentDoc));
            }
            if (musicArtist.Band != String.Empty)
            {
                resList.Add(SearchByAttribute("MusicArtist", "ArtistBand", musicArtist.Band, currentDoc));
            }
            if (musicArtist.Activity != String.Empty)
            {
                resList.Add(SearchByAttribute("MusicArtist", "MusicActivity", musicArtist.Activity, currentDoc));
            }

            return(FindCrossings(resList, musicArtist));
        }
예제 #9
0
        public List <MusicArtist> FindCrossings(List <List <MusicArtist> > artists, MusicArtist obj)
        {
            List <MusicArtist> resList = new List <MusicArtist>();
            List <MusicArtist> cleared = CheckNodes(artists, obj);

            foreach (MusicArtist temp in cleared)
            {
                bool isIn = false;
                foreach (MusicArtist mA in resList)
                {
                    if (mA.Compare(temp))
                    {
                        isIn = true;
                    }
                }
                if (!isIn)
                {
                    resList.Add(temp);
                }
            }
            return(resList);
        }