예제 #1
0
        /// <summary>
        /// Dışarıdan aldığı parametre değerini önce cache de arıyor.
        /// Bulamazsa eğer veritabanına bakıyor.
        /// Veritabanında da yoksa APIMovies katmanı aracılığıyla apiden çekiyor.
        /// Movie bulunduğu zaman cache tekrar set ediliyor.
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public DTO.Movies getMovie(string title)
        {
            DTO.Movies movie;
            try
            {
                DataCache.ICacheManager cacheManager = new DataCache.CacheManager(_appSettings.dataCache);
                movie = cacheManager.get("Movie_" + title);


                if (movie == null || movie.refID == null)
                {
                    movie = (from a in _appSettings.dbContext.Movies
                             where a.IsDeleted == false && a.Title.Contains(title)
                             select new DTO.Movies()
                    {
                        ID = a.ID,
                        refID = a.refID,
                        Title = a.Title,
                        Year = a.Year,
                        Rated = a.Rated,
                        Rating = a.Rating,
                        Votes = a.Votes,
                        Released = a.Released,
                        Runtime = a.Runtime,
                        Director = a.Director,
                        Writer = a.Writer,
                        Actors = a.Actors,
                        Plot = a.Plot,
                        Language = a.Language,
                        Country = a.Country,
                        Awards = a.Awards,
                        Poster = a.Poster,
                        LastUpdateTime = a.LastUpdateTime,
                    }).FirstOrDefault();

                    if (movie != null)
                    {
                        cacheManager.set("Movie_" + title, movie, 12);
                    }
                }

                if (movie == null || movie.refID == null)
                {
                    APIMovies.IMovie apiMovie = new APIMovies.Movie();
                    movie = apiMovie.getMovie(_appSettings, title);


                    if (movie != null)
                    {
                        #region Add Movie

                        DAO.Movies newmovie = new DAO.Movies();
                        newmovie.refID          = movie.refID;
                        newmovie.Title          = movie.Title;
                        newmovie.Year           = movie.Year;
                        newmovie.Rated          = movie.Rated;
                        newmovie.Rating         = movie.Rating;
                        newmovie.Votes          = movie.Votes;
                        newmovie.Released       = movie.Released;
                        newmovie.Runtime        = movie.Runtime;
                        newmovie.Director       = movie.Director;
                        newmovie.Writer         = movie.Writer;
                        newmovie.Actors         = movie.Actors;
                        newmovie.Plot           = movie.Plot;
                        newmovie.Language       = movie.Language;
                        newmovie.Country        = movie.Country;
                        newmovie.Awards         = movie.Awards;
                        newmovie.Poster         = movie.Poster;
                        newmovie.LastUpdateTime = DateTime.Now;
                        newmovie.DeletedTime    = DateTime.Now;
                        _appSettings.dbContext.Movies.Add(newmovie);
                        _appSettings.dbContext.SaveChanges();

                        #endregion

                        cacheManager.set("Movie_" + title, movie, 12);
                    }
                }

                return(movie);
            }
            catch (Exception ex)
            {
                _logger.add(_appSettings.logConfigFile, "Error:" + ex.InnerException);

                return(new DTO.Movies());
            }
        }
예제 #2
0
 public void Get()
 {
     DataCache.ICacheManager cacheManager = new DataCache.CacheManager(appSettings.dataCache);
     cacheManager.clear();
 }