diff --git a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs index 470e39cd23..c45d20b7cc 100644 --- a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs @@ -136,7 +136,7 @@ namespace MediaBrowser.Api.HttpHandlers return null; } - return File.GetLastWriteTime(await GetImagePath().ConfigureAwait(false)); + return File.GetLastWriteTimeUtc(await GetImagePath().ConfigureAwait(false)); } private int? Height diff --git a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs index 38c039275c..bf06cbdb0c 100644 --- a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using MediaBrowser.Common.Net.Handlers; +using MediaBrowser.Common.Plugins; using MediaBrowser.Controller; using MediaBrowser.Model.Plugins; @@ -9,13 +10,39 @@ namespace MediaBrowser.Api.HttpHandlers { public class PluginConfigurationHandler : BaseSerializationHandler { + private BasePlugin _Plugin = null; + private BasePlugin Plugin + { + get + { + if (_Plugin == null) + { + string name = QueryString["assemblyfilename"]; + + _Plugin = Kernel.Instance.Plugins.First(p => p.AssemblyFileName.Equals(name, StringComparison.OrdinalIgnoreCase)); + } + + return _Plugin; + } + } + protected override Task GetObjectToSerialize() { - string name = QueryString["assemblyfilename"]; + return Task.FromResult(Plugin.Configuration); + } - BasePluginConfiguration config = Kernel.Instance.Plugins.First(p => p.AssemblyFileName.Equals(name, StringComparison.OrdinalIgnoreCase)).Configuration; + public override TimeSpan CacheDuration + { + get + { + return TimeSpan.FromDays(7); + } + } - return Task.FromResult(config); + protected override Task GetLastDateModified() + { + return Task.FromResult(Plugin.ConfigurationDateLastModified); } + } } diff --git a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs index 175876b4ca..a26a6daf79 100644 --- a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System; +using System.IO; +using System.Threading.Tasks; using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Controller; using MediaBrowser.Model.Configuration; @@ -11,5 +13,18 @@ namespace MediaBrowser.Api.HttpHandlers { return Task.FromResult(Kernel.Instance.Configuration); } + + public override TimeSpan CacheDuration + { + get + { + return TimeSpan.FromDays(7); + } + } + + protected override Task GetLastDateModified() + { + return Task.FromResult(File.GetLastWriteTimeUtc(Kernel.Instance.ApplicationPaths.SystemConfigurationFilePath)); + } } } diff --git a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs index 19a1e7af7b..2462833ffb 100644 --- a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs @@ -167,7 +167,8 @@ namespace MediaBrowser.Common.Net.Handlers { HttpListenerContext = ctx; - Logger.LogInfo("Http Server received request at: " + ctx.Request.Url.ToString()); + string url = ctx.Request.Url.ToString(); + Logger.LogInfo("Http Server received request at: " + url); Logger.LogInfo("Http Headers: " + string.Join(",", ctx.Request.Headers.AllKeys.Select(k => k + "=" + ctx.Request.Headers[k]))); ctx.Response.AddHeader("Access-Control-Allow-Origin", "*"); @@ -195,10 +196,10 @@ namespace MediaBrowser.Common.Net.Handlers { DateTime ifModifiedSince; - if (DateTime.TryParse(ctx.Request.Headers["If-Modified-Since"].Replace(" GMT", string.Empty), out ifModifiedSince)) + if (DateTime.TryParse(ctx.Request.Headers["If-Modified-Since"], out ifModifiedSince)) { // If the cache hasn't expired yet just return a 304 - if (IsCacheValid(ifModifiedSince, cacheDuration, lastDateModified)) + if (IsCacheValid(ifModifiedSince.ToUniversalTime(), cacheDuration, lastDateModified)) { StatusCode = 304; } @@ -207,6 +208,8 @@ namespace MediaBrowser.Common.Net.Handlers await PrepareResponse().ConfigureAwait(false); + Logger.LogInfo("Responding with status code {0} for url {1}", StatusCode, url); + if (IsResponseValid) { bool compressResponse = ShouldCompressResponse(ctx.Response.ContentType) && ClientSupportsCompression; @@ -295,10 +298,12 @@ namespace MediaBrowser.Common.Net.Handlers private void CacheResponse(HttpListenerResponse response, TimeSpan duration, DateTime? dateModified) { - DateTime lastModified = dateModified ?? DateTime.Now; + DateTime now = DateTime.UtcNow; + + DateTime lastModified = dateModified ?? now; response.Headers[HttpResponseHeader.CacheControl] = "public, max-age=" + Convert.ToInt32(duration.TotalSeconds); - response.Headers[HttpResponseHeader.Expires] = DateTime.Now.Add(duration).ToString("r"); + response.Headers[HttpResponseHeader.Expires] = now.Add(duration).ToString("r"); response.Headers[HttpResponseHeader.LastModified] = lastModified.ToString("r"); } @@ -334,7 +339,7 @@ namespace MediaBrowser.Common.Net.Handlers DateTime cacheExpirationDate = ifModifiedSince.Add(cacheDuration); - if (DateTime.Now < cacheExpirationDate) + if (DateTime.UtcNow < cacheExpirationDate) { return true; } @@ -347,7 +352,7 @@ namespace MediaBrowser.Common.Net.Handlers /// private DateTime NormalizeDateForComparison(DateTime date) { - return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second); + return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Kind); } protected virtual long? GetTotalContentLength() diff --git a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs index 799abea9b4..884e398bfd 100644 --- a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs @@ -108,7 +108,7 @@ namespace MediaBrowser.Common.Net.Handlers if (SourceStream != null) { - value = File.GetLastWriteTime(Path); + value = File.GetLastWriteTimeUtc(Path); } return Task.FromResult(value); diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index c03964e6f7..2b7559c59d 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -83,7 +83,7 @@ namespace MediaBrowser.Common.Plugins { if (File.Exists(ConfigurationFilePath)) { - _ConfigurationDateLastModified = File.GetLastWriteTime(ConfigurationFilePath); + _ConfigurationDateLastModified = File.GetLastWriteTimeUtc(ConfigurationFilePath); } } diff --git a/MediaBrowser.Common/UI/BaseApplication.cs b/MediaBrowser.Common/UI/BaseApplication.cs index c7b2916b57..4cbc57c0d3 100644 --- a/MediaBrowser.Common/UI/BaseApplication.cs +++ b/MediaBrowser.Common/UI/BaseApplication.cs @@ -35,11 +35,11 @@ namespace MediaBrowser.Common.UI try { - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; await Kernel.Init(progress); - Logger.LogInfo("Kernel.Init completed in {0} seconds.", (DateTime.Now - now).TotalSeconds); + Logger.LogInfo("Kernel.Init completed in {0} seconds.", (DateTime.UtcNow - now).TotalSeconds); splash.Close(); this.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose; diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index b9bc7ea757..75069d4d58 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -188,7 +188,7 @@ namespace MediaBrowser.Controller.IO } } - public DateTime CreationTime + public DateTime CreationTimeUtc { get { @@ -196,7 +196,7 @@ namespace MediaBrowser.Controller.IO } } - public DateTime LastAccessTime + public DateTime LastAccessTimeUtc { get { @@ -204,7 +204,7 @@ namespace MediaBrowser.Controller.IO } } - public DateTime LastWriteTime + public DateTime LastWriteTimeUtc { get { @@ -216,7 +216,7 @@ namespace MediaBrowser.Controller.IO { long highBits = filetime.dwHighDateTime; highBits = highBits << 32; - return DateTime.FromFileTime(highBits + (long)filetime.dwLowDateTime); + return DateTime.FromFileTimeUtc(highBits + (long)filetime.dwLowDateTime); } public string Path { get; set; } diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs index 26468c6565..a09f634012 100644 --- a/MediaBrowser.Controller/Library/ItemController.cs +++ b/MediaBrowser.Controller/Library/ItemController.cs @@ -268,8 +268,8 @@ namespace MediaBrowser.Controller.Library Directory.CreateDirectory(path); } - item.DateCreated = Directory.GetCreationTime(path); - item.DateModified = Directory.GetLastAccessTime(path); + item.DateCreated = Directory.GetCreationTimeUtc(path); + item.DateModified = Directory.GetLastWriteTimeUtc(path); ItemResolveEventArgs args = new ItemResolveEventArgs(); args.FileInfo = FileData.GetFileData(path); diff --git a/MediaBrowser.Controller/Providers/AudioInfoProvider.cs b/MediaBrowser.Controller/Providers/AudioInfoProvider.cs index 709589cdb4..355344662c 100644 --- a/MediaBrowser.Controller/Providers/AudioInfoProvider.cs +++ b/MediaBrowser.Controller/Providers/AudioInfoProvider.cs @@ -276,7 +276,7 @@ namespace MediaBrowser.Controller.Providers if (DateTime.TryParse(val, out i)) { - return i; + return i.ToUniversalTime(); } } diff --git a/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs b/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs index 643580b31c..1f5a6fe831 100644 --- a/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs +++ b/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs @@ -88,20 +88,20 @@ namespace MediaBrowser.Controller.Resolvers if (childData != null) { - item.DateCreated = childData.Value.CreationTime; - item.DateModified = childData.Value.LastWriteTime; + item.DateCreated = childData.Value.CreationTimeUtc; + item.DateModified = childData.Value.LastWriteTimeUtc; } else { WIN32_FIND_DATA fileData = FileData.GetFileData(item.Path); - item.DateCreated = fileData.CreationTime; - item.DateModified = fileData.LastWriteTime; + item.DateCreated = fileData.CreationTimeUtc; + item.DateModified = fileData.LastWriteTimeUtc; } } else { - item.DateCreated = args.FileInfo.CreationTime; - item.DateModified = args.FileInfo.LastWriteTime; + item.DateCreated = args.FileInfo.CreationTimeUtc; + item.DateModified = args.FileInfo.LastWriteTimeUtc; } } } diff --git a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs index d5fdf640c8..612ba4c7cb 100644 --- a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs @@ -45,7 +45,7 @@ namespace MediaBrowser.Controller.Xml DateTime added; if (DateTime.TryParse(reader.ReadElementContentAsString() ?? string.Empty, out added)) { - item.DateCreated = added; + item.DateCreated = added.ToUniversalTime(); } break; @@ -232,7 +232,7 @@ namespace MediaBrowser.Controller.Xml if (DateTime.TryParse(firstAired, out airDate) && airDate.Year > 1850) { - item.PremiereDate = airDate; + item.PremiereDate = airDate.ToUniversalTime(); item.ProductionYear = airDate.Year; } } diff --git a/MediaBrowser.Model/Entities/BaseItem.cs b/MediaBrowser.Model/Entities/BaseItem.cs index 808ef5ad89..7751207425 100644 --- a/MediaBrowser.Model/Entities/BaseItem.cs +++ b/MediaBrowser.Model/Entities/BaseItem.cs @@ -131,7 +131,7 @@ namespace MediaBrowser.Model.Entities /// public bool IsRecentlyAdded(User user) { - return (DateTime.Now - DateCreated).TotalDays < user.RecentItemDays; + return (DateTime.UtcNow - DateCreated).TotalDays < user.RecentItemDays; } public void AddPerson(PersonInfo person)