public List<string> GetBollywoodHungamaMoviePosterDetails(HtmlNode body, string movieName, ref List<string> posterPath, ref string thumbnailPath) { posterPath = posterPath ?? new List<string>(); thumbnailPath = string.Empty; var aListNode = helper.GetElementWithAttribute(body, "a", "class", "imgthpic"); if (aListNode != null) { var thumbnails = aListNode.Elements("img"); if (thumbnails != null) { //int imageCounter = GetMaxImageCounter(movieName); int imageCounter = new BlobStorageService().GetImageFileCount(BlobStorageService.Blob_ImageContainer, movieName.Replace(" ", "-").ToLower() + "-poster-"); foreach (HtmlNode thumbnail in thumbnails) { if (thumbnail.Attributes["class"] != null && thumbnail.Attributes["class"].Value == "mb10") { string href = thumbnail.Attributes["src"].Value; string newImageName = string.Empty; string newPosterPath = GetNewImageName(movieName, GetFileExtension(href), imageCounter, false, ref newImageName); posterPath.Add(newImageName); DownloadImage(href, newPosterPath); imageCounter++; } } } } return posterPath; }
/// <summary> /// Download image and return it blob url path /// </summary> /// <param name="url"></param> /// <param name="fileName"></param> /// <returns></returns> public static string DownloadImage(string url, string fileName) { string result = string.Empty; try { fileName = fileName + "." + url.Substring(url.LastIndexOf(".") + 1); using (WebClient client = new WebClient()) { byte[] data = client.DownloadData(url); using (Stream stream = new MemoryStream(data)) { result = new BlobStorageService().UploadImageFileOnBlob(BlobStorageService.Blob_NewsImages, fileName, stream); } } } catch (Exception) { //TODO - Log an error message } return result; }
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 ""; } }
protected override string ProcessRequest() { try { BlobStorageService _blobStorageService = new BlobStorageService(); string newsXmlFileBlobPath = _blobStorageService.GetSinglFile(BlobStorageService.Blob_XMLFileContainer, "News.xml"); GetNews(newsXmlFileBlobPath); return "{ \"Status\":\"Ok\",\"Message\" : \"successfully crawl news.\" }"; } catch (Exception ex) { return "{ \"Status\":\"Error\", \"Message\" : \"Error occured.\", \"ActualMessage\" : \"" + ex.Message + "\"}"; } }
public void ProcessRequest(HttpContext context) { string name = context.Request.QueryString["name"]; string type = context.Request.QueryString["type"]; context.Response.AppendHeader("Access-Control-Allow-Origin", "*"); if (!string.IsNullOrEmpty(context.Request.Headers["X-File-Name"])) { try { BlobStorageService _blobStorageService = new BlobStorageService(); string xFileName = context.Request.Headers["X-File-Name"]; string xfileExtention = xFileName.Substring(xFileName.LastIndexOf(".") + 1); if (type == "poster") { int posterCount = _blobStorageService.GetImageFileCount(BlobStorageService.Blob_ImageContainer, name.Replace(" ", "-").ToLower() + "-poster-"); string newPosterName = name.ToLower() + "-poster-" + posterCount + "." + xfileExtention; // upload file on blob string uploadedFile = _blobStorageService.UploadImageFileOnBlob(BlobStorageService.Blob_ImageContainer, newPosterName, context.Request.InputStream); context.Response.Write(jss.Serialize(new { Status = "Ok", Message = "file uploaded successfully", FileUrl = newPosterName })); } else { string fileName = name.Replace(" ", "-").ToLower() + "." + xfileExtention; _blobStorageService.DeleteFileFromBlob(BlobStorageService.Blob_ImageContainer, fileName); string uploadedFile = _blobStorageService.UploadImageFileOnBlob(BlobStorageService.Blob_ImageContainer, fileName, context.Request.InputStream); context.Response.Write(jss.Serialize(new { Status = "Ok", Message = "file uploaded successfully", FileUrl = fileName })); } } catch (Exception ex) { context.Response.StatusCode = 500; context.Response.Write(jss.Serialize(new { Status = "Error", Error = ex.Message, Message = "Sorry! An error occured while uploading image on mooc server" })); } } }
public List<XMLMovieProperties> GetMovieListFromXMLFiles(bool isFromLatest) { try { GenerateXMLFile objGenerateXml = new GenerateXMLFile(); if (isFromLatest) { string fileName = "MovieList-" + DateTime.Now.ToString("MMM-yyyy") + ".xml"; return objGenerateXml.GetMoviesFromXml(new string[] { fileName }); } else { string[] files = new BlobStorageService().GetUploadedFileFromBlob("crawlfiles").ToArray(); return objGenerateXml.GetMoviesFromXml(files); } } catch (Exception) { throw; } }
public IEnumerable<ReviewerEntity> GetAllReviewer(string reviewerName) { try { var reviewerTable = TableStore.Instance.GetTable(TableStore.ReviewerTableName) as ReviewerTable; var allReviewer = reviewerTable.GetAllItems<ReviewerEntity>(); foreach (ReviewerEntity re in allReviewer.Values) { var filePattern = re.ReviewerName.Replace(" ", "-").ToLower(); var file = new BlobStorageService().GetSinglFile(BlobStorageService.Blob_ImageContainer, filePattern); if (!string.IsNullOrEmpty(file)) re.ReviewerImage = file.Substring(file.LastIndexOf("/") + 1); else re.ReviewerImage = "default-movie.jpg"; } //Return only those artists who have associated posters. //Associated poster means those artists are popular. Hence they have associated posters if (string.IsNullOrEmpty(reviewerName)) return allReviewer.Values.OrderBy(a => a.ReviewerName); else return allReviewer.Values.Where(a => a.ReviewerName.ToLower().Trim().Contains(reviewerName)); } catch (Exception ex) { Console.Write(ex.Message); return null; } }
public List<string> GetMoviePosterDetails(HtmlNode body, string movieName, ref List<string> posterPath, ref string thumbnailPath) { posterPath = posterPath ?? new List<string>(); thumbnailPath = string.Empty; bool isThumbnailDownloaded = false; var thumbListNode = helper.GetElementWithAttribute(body, "div", "class", "media_index_thumb_list"); if (thumbListNode != null) { var thumbnails = thumbListNode.Elements("a"); if (thumbnails != null) { //int imageCounter = GetMaxImageCounter(movieName); int imageCounter = new BlobStorageService().GetImageFileCount(BlobStorageService.Blob_ImageContainer, movieName.Replace(" ", "-").ToLower() + "-poster-"); foreach (HtmlNode thumbnail in thumbnails) { if (thumbnail.Attributes["itemprop"] != null && thumbnail.Attributes["itemprop"].Value == "thumbnailUrl") { string href = thumbnail.Attributes["href"].Value; CrawlPosterImagePath("http://imdb.com" + href, movieName, imageCounter, ref isThumbnailDownloaded, ref posterPath, ref thumbnailPath); imageCounter++; } } } } return posterPath; }
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; } }