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; } }
public string CreatingFile(XMLMovieProperties objMovie) { try { if (objMovie == null) { return(null); } BlobStorageService _blobStorageService = new BlobStorageService(); XmlDocument documnet = new XmlDocument(); string fileName = "MovieList-" + objMovie.Month.Substring(0, 3) + "-" + objMovie.Year.ToString() + ".xml"; string existFileContent = _blobStorageService.GetUploadeXMLFileContent(BlobStorageService.Blob_XMLFileContainer, fileName); if (!string.IsNullOrEmpty(existFileContent)) { documnet.LoadXml(existFileContent); var oldMonth = documnet.SelectSingleNode("Movies/Month[@name='" + objMovie.Month + "']"); var oldMovie = oldMonth.SelectSingleNode("Movie[@name='" + objMovie.MovieName + "']"); if (oldMovie == null) { oldMonth.AppendChild(AddMovieNode(documnet, objMovie)); } else { oldMonth.RemoveChild(oldMovie); oldMonth.AppendChild(AddMovieNode(documnet, objMovie)); } } else { XmlNode root = documnet.CreateNode(XmlNodeType.Element, "Movies", ""); XmlAttribute movieYear = documnet.CreateAttribute("year"); movieYear.Value = objMovie.Year.ToString(); root.Attributes.Append(movieYear); XmlNode month = documnet.CreateNode(XmlNodeType.Element, "Month", ""); XmlAttribute monthName = documnet.CreateAttribute("name"); monthName.Value = objMovie.Month.ToString(); month.Attributes.Append(monthName); month.AppendChild(AddMovieNode(documnet, objMovie)); root.AppendChild(month); documnet.AppendChild(root); } _blobStorageService.UploadXMLFileOnBlob(BlobStorageService.Blob_XMLFileContainer, fileName, documnet.OuterXml); return(documnet.OuterXml); //return fileName; } catch (Exception ex) { Console.Write(ex.Message); return(""); } }