From e2dcddc5ac43846baea0f9b1a0fc62844dd9ee1d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 23 Mar 2013 22:45:00 -0400 Subject: made compression and caching available to plugin api endpoints --- MediaBrowser.Api/BaseApiService.cs | 69 +++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.Api/BaseApiService.cs') diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 133f22bcd..8fcef654d 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -1,11 +1,10 @@ -using System.Collections.Generic; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Connectivity; using MediaBrowser.Model.Logging; -using MediaBrowser.Server.Implementations.HttpServer; using ServiceStack.Common.Web; using ServiceStack.ServiceHost; using System; +using System.Collections.Generic; namespace MediaBrowser.Api { @@ -13,8 +12,70 @@ namespace MediaBrowser.Api /// Class BaseApiService /// [RequestFilter] - public class BaseApiService : BaseRestService + public class BaseApiService : IHasResultFactory, IRestfulService { + /// + /// Gets or sets the logger. + /// + /// The logger. + public ILogger Logger { get; set; } + + /// + /// Gets or sets the HTTP result factory. + /// + /// The HTTP result factory. + public IHttpResultFactory ResultFactory { get; set; } + + /// + /// Gets or sets the request context. + /// + /// The request context. + public IRequestContext RequestContext { get; set; } + + /// + /// To the optimized result. + /// + /// + /// The result. + /// System.Object. + protected object ToOptimizedResult(T result) + where T : class + { + return ResultFactory.GetOptimizedResult(RequestContext, result); + } + + /// + /// To the optimized result using cache. + /// + /// + /// The cache key. + /// The last date modified. + /// Duration of the cache. + /// The factory fn. + /// System.Object. + /// cacheKey + protected object ToOptimizedResultUsingCache(Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func factoryFn) + where T : class + { + return ResultFactory.GetOptimizedResultUsingCache(RequestContext, cacheKey, lastDateModified, cacheDuration, factoryFn); + } + + /// + /// To the cached result. + /// + /// + /// The cache key. + /// The last date modified. + /// Duration of the cache. + /// The factory fn. + /// Type of the content. + /// System.Object. + /// cacheKey + protected object ToCachedResult(Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func factoryFn, string contentType) + where T : class + { + return ResultFactory.GetCachedResult(RequestContext, cacheKey, lastDateModified, cacheDuration, factoryFn, contentType); + } } /// -- cgit v1.2.3