public T Get <T>(string path)
 {
     lock (syncLock)
     {
         // Get data from cache
         var cacheRes = Cache.Get(path);
         // If not null, deserialize to object and compare if its time to update from third party or to return cached version
         if (cacheRes != null)
         {
             // Deserialize xml from db
             Response <T> deserialized = Xml.Deserialize <Response <T> >(cacheRes);
             // Compare xml from db cached untill with current time
             int compare = DateTime.Compare(DateTime.UtcNow, deserialized.CachedUntil);
             // If cacheduntill is later than current time, return cached info
             if (compare <= 0)
             {
                 return(deserialized.Result);
             }
         }
         // If no cache, or its time to update current cache - Get third party xml
         var reqRes = Requester.Get(path);
         // Save it to cache
         Cache.Set(path, reqRes);
         // Desearialize
         Response <T> deserialized2 = Xml.Deserialize <Response <T> >(reqRes);
         // Return it to user
         return(deserialized2.Result);
     }
 }
Пример #2
0
        /// <summary>
        /// Get current showing movies of Galaxy cinema
        /// Ref: https://www.galaxycine.vn/dat-ve/phap-su-mu-ai-chet-gio-tay
        /// </summary>
        /// <returns>List of current showing movie of Galaxy cinema with status and message</returns>
        public async Task <MovieListResult> GetShowingMovies()
        {
            // Handle request exception
            try
            {
                var response = await _requester.Get <ShowAndComingModel>($"{_domain}/api/movie/showAndComming");

                return(new MovieListResult
                {
                    Success = true,
                    Data = response.MovieShowing
                           .Select(x => Mapper.MapToMovie(x))
                           .ToList()
                });
            }
            catch (Exception e)
            {
                return(new MovieListResult
                {
                    Success = false,
                    Message = e.Message
                });
            }
        }