public GetAllMovies ( ) : MovieEntity>.IDictionary |
||
return | MovieEntity>.IDictionary |
private static void UpdateCache(MovieEntity movie) { // Remove movie from Cache var movieKey = CacheConstants.MovieInfoJson + movie.UniqueName; var isPreviouslyCached = CacheManager.Exists(movieKey); CacheManager.Remove(movieKey); var tableMgr = new TableManager(); // Cache if previously cached or movie is upcoming/current Task.Run(() => { if (isPreviouslyCached || movie.State == "upcoming" || movie.State == "now playing") { MovieInfoController.GetMovieInfo(movie.UniqueName); } }); // Update more Cache Task.Run(() => { // Update cache for AllMovies // Note: We are not updating CacheConstants.AllMovieEntitiesSortedByName here // because typically the name of the movie does not changes as often CacheManager.Remove(CacheConstants.AllMovieEntities); tableMgr.GetAllMovies(); // Update current movies Task.Run(() => { CacheManager.Remove(CacheConstants.UpcomingMovieEntities); var movies = tableMgr.GetCurrentMovies(); }); // Update upcoming movies Task.Run(() => { CacheManager.Remove(CacheConstants.NowPlayingMovieEntities); var movies = tableMgr.GetUpcomingMovies(); }); }); }
// get : api/GetCastByType?t={type=[all, actor, director, music director etc]}&l={limit/count eg 5,10,100 so on default 100} protected override string ProcessRequest() { JavaScriptSerializer json = new JavaScriptSerializer(); try { var tblMgr = new TableManager(); var qpParam = HttpUtility.ParseQueryString(this.Request.RequestUri.Query); string type = "all"; int limit = 100; if (!string.IsNullOrEmpty(qpParam["t"])) { type = qpParam["t"].ToString().ToLower(); } if (!string.IsNullOrEmpty(qpParam["l"])) { limit = Convert.ToInt32(qpParam["l"].ToString()); } if (tempCast == null || tempCast.Count == 0) { var movies = tblMgr.GetAllMovies(); foreach (var movie in movies) { List<Cast> castList = json.Deserialize(movie.Value.Cast, typeof(List<Cast>)) as List<Cast>; if (castList != null) { foreach (var cast in castList) { if (!tempCast.Exists(c => c.name == cast.name)) { tempCast.Add(cast); } } } } } if (type == "all") { var actor = (from u in tempCast where u.role.ToLower() == "actor" || u.role.ToLower() == "actress" select u).Distinct().Take(limit); var directors = (from u in tempCast where u.role.ToLower() == "director" select u).Distinct().Take(limit); var musicDirectors = (from u in tempCast where u.role.ToLower() == "music director" select u).Distinct().Take(limit); return json.Serialize(new { Status = "Ok", Actor = actor, Director = directors, MusicDirector = musicDirectors }); } else if (type == "actor") { var actor = (from u in tempCast where u.role.ToLower() == "actor" || u.role.ToLower() == "actress" select u).Distinct().Take(limit); return json.Serialize(new { Status = "Ok", Actor = actor }); } else if (type == "director") { var directors = (from u in tempCast where u.role.ToLower() == "director" select u).Distinct().Take(limit); return json.Serialize(new { Status = "Ok", Director = directors }); } else if (type == "musicdirector") { var musicDirectors = (from u in tempCast where u.role.ToLower() == "music director" select u).Distinct().Take(limit); return json.Serialize(new { Status = "Ok", MusicDirector = musicDirectors }); } } catch (Exception ex) { return json.Serialize(new { Status = "Error", UserMessage = "Unable to get movie cast", ActualError = ex.Message }); } return json.Serialize(new { Status = "Error", UserMessage = "Query string is empty." }); }
private void BuildMovieIndex() { TableManager tblMgr = new TableManager(); JavaScriptSerializer json = new JavaScriptSerializer(); IDictionary<string, MovieEntity> movies = tblMgr.GetAllMovies(); string posterUrl = string.Empty; foreach (MovieEntity movie in movies.Values) { List<String> posters = json.Deserialize(movie.Posters, typeof(List<String>)) as List<String>; List<APIRole.UDT.Cast> casts = json.Deserialize(movie.Cast, typeof(List<APIRole.UDT.Cast>)) as List<APIRole.UDT.Cast>; List<string> actors = new List<string>(); List<string> critics = new List<string>(); MovieSearchData movieSearchIndex = new MovieSearchData(); IDictionary<string, ReviewEntity> reviews = tblMgr.GetReviewsByMovieId(movie.MovieId); if (posters != null && posters.Count > 0) { posterUrl = posters[posters.Count - 1]; } if (reviews != null) { foreach (ReviewEntity review in reviews.Values) { if (!string.IsNullOrEmpty(review.ReviewerName)) critics.Add(review.ReviewerName); } } if (casts != null) { foreach (var actor in casts) { // actor, director, music, producer string role = actor.role.ToLower(); string characterName = string.IsNullOrEmpty(actor.charactername) ? string.Empty : actor.charactername; // Check if artist is already present in the list for some other role. // If yes, skip it. Also if the actor name is missing then skip the artist if (actors.Contains(actor.name) || string.IsNullOrEmpty(actor.name) || actor.name == "null") continue; // If we want to showcase main artists and not all, keep the following switch... case. switch (role) { case "actor": actors.Add(actor.name); break; case "producer": // some times producer are listed as line producer etc. // We are not interested in those artists as of now?! Hence skipping it if (characterName == role) { actors.Add(actor.name); } break; case "music": case "director": // Main music director and movie director does not have associated character name. // Where as other side directors have associated character name as associate director, assitant director. // Skipping such cases. if (string.IsNullOrEmpty(characterName)) { actors.Add(actor.name); } break; } } } movieSearchIndex.Id = movie.RowKey; movieSearchIndex.Title = movie.Name; movieSearchIndex.Type = movie.Genre; // Selected poster url movieSearchIndex.TitleImageURL = posterUrl; movieSearchIndex.UniqueName = movie.UniqueName; movieSearchIndex.Description = json.Serialize(actors); movieSearchIndex.Critics = json.Serialize(critics); movieSearchIndex.Link = movie.UniqueName; LuceneSearch.AddUpdateLuceneIndex(movieSearchIndex); } }