コード例 #1
0
        public List <XMLMovieProperties> GetMoviesFromXml(string[] files)
        {
            try
            {
                BlobStorageService _blobStorageService = new BlobStorageService();

                List <XMLMovieProperties> movieList = new List <XMLMovieProperties>();

                foreach (string file in files)
                {
                    // get xml file data from blob
                    string xmlData = _blobStorageService.GetUploadeXMLFileContent(BlobStorageService.Blob_XMLFileContainer, file);

                    if (string.IsNullOrEmpty(xmlData))
                    {
                        continue;
                    }

                    XmlDocument documnet = new XmlDocument();

                    try
                    {
                        documnet.LoadXml(xmlData);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    var root       = documnet.SelectSingleNode("Movies");
                    var monthNode  = root.SelectSingleNode("Month");
                    var movieNodes = monthNode.SelectNodes("Movie");

                    foreach (XmlNode movieNode in movieNodes)
                    {
                        XMLMovieProperties singleMovie = new XMLMovieProperties();
                        singleMovie.MovieId = Guid.NewGuid().ToString();
                        singleMovie.Month   = monthNode.Attributes["name"].Value;
                        singleMovie.Year    = Convert.ToInt32(root.Attributes["year"].Value);

                        singleMovie.MovieName = movieNode.Attributes["name"].Value;
                        singleMovie.MovieLink = movieNode.Attributes["link"].Value;

                        if (movieNode.Attributes["santaposterlink"] != null)
                        {
                            singleMovie.SantaPosterLink = movieNode.Attributes["santaposterlink"].Value;
                        }
                        else
                        {
                            singleMovie.SantaPosterLink = string.Empty;
                        }

                        if (movieNode.Attributes["saavnsonglink"] != null)
                        {
                            singleMovie.SaavnSongLink = movieNode.Attributes["saavnsonglink"].Value;
                        }
                        else
                        {
                            singleMovie.SaavnSongLink = string.Empty;
                        }

                        var reviewNodes = movieNode.SelectNodes("Review");

                        List <XMLReivewProperties> reviewList = new List <XMLReivewProperties>();

                        foreach (XmlNode reviewNode in reviewNodes)
                        {
                            XMLReivewProperties review = new XMLReivewProperties();

                            review.Name = reviewNode.Attributes["name"].Value;
                            review.Link = reviewNode.Attributes["link"].Value;

                            reviewList.Add(review);
                        }

                        singleMovie.Reviews = reviewList;

                        movieList.Add(singleMovie);
                    }
                }

                return(movieList);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public List<XMLMovieProperties> GetMoviesFromXml(string[] files)
        {
            try
            {
                BlobStorageService _blobStorageService = new BlobStorageService();

                List<XMLMovieProperties> movieList = new List<XMLMovieProperties>();

                foreach (string file in files)
                {
                    // get xml file data from blob
                    string xmlData = _blobStorageService.GetUploadeXMLFileContent(BlobStorageService.Blob_XMLFileContainer, file);

                    if (string.IsNullOrEmpty(xmlData)) continue;

                    XmlDocument documnet = new XmlDocument();

                    try
                    {
                        documnet.LoadXml(xmlData);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    var root = documnet.SelectSingleNode("Movies");
                    var monthNode = root.SelectSingleNode("Month");
                    var movieNodes = monthNode.SelectNodes("Movie");

                    foreach (XmlNode movieNode in movieNodes)
                    {
                        XMLMovieProperties singleMovie = new XMLMovieProperties();
                        singleMovie.MovieId = Guid.NewGuid().ToString();
                        singleMovie.Month = monthNode.Attributes["name"].Value;
                        singleMovie.Year = Convert.ToInt32(root.Attributes["year"].Value);

                        singleMovie.MovieName = movieNode.Attributes["name"].Value;
                        singleMovie.MovieLink = movieNode.Attributes["link"].Value;

                        if (movieNode.Attributes["santaposterlink"] != null)
                            singleMovie.SantaPosterLink = movieNode.Attributes["santaposterlink"].Value;
                        else
                            singleMovie.SantaPosterLink = string.Empty;

                        if (movieNode.Attributes["saavnsonglink"] != null)
                            singleMovie.SaavnSongLink = movieNode.Attributes["saavnsonglink"].Value;
                        else
                            singleMovie.SaavnSongLink = string.Empty;

                        var reviewNodes = movieNode.SelectNodes("Review");

                        List<XMLReivewProperties> reviewList = new List<XMLReivewProperties>();

                        foreach (XmlNode reviewNode in reviewNodes)
                        {
                            XMLReivewProperties review = new XMLReivewProperties();

                            review.Name = reviewNode.Attributes["name"].Value;
                            review.Link = reviewNode.Attributes["link"].Value;

                            reviewList.Add(review);
                        }

                        singleMovie.Reviews = reviewList;

                        movieList.Add(singleMovie);
                    }
                }

                return movieList;
            }
            catch (Exception)
            {
                throw;
            }
        }