From b50f78e5da6f3fdfc59e577ca61b88771da7d211 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 12 Jul 2012 02:55:27 -0400 Subject: Initial check-in --- MediaBrowser.Model/Configuration/Configuration.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 MediaBrowser.Model/Configuration/Configuration.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Model/Configuration/Configuration.cs b/MediaBrowser.Model/Configuration/Configuration.cs new file mode 100644 index 0000000000..c2aa737280 --- /dev/null +++ b/MediaBrowser.Model/Configuration/Configuration.cs @@ -0,0 +1,17 @@ +using MediaBrowser.Common.Logging; + +namespace MediaBrowser.Model.Configuration +{ + public class Configuration + { + public string ImagesByNamePath { get; set; } + public int HttpServerPortNumber { get; set; } + public LogSeverity LogSeverity { get; set; } + + public Configuration() + { + HttpServerPortNumber = 8096; + LogSeverity = Common.Logging.LogSeverity.Info; + } + } +} -- cgit v1.2.3 From baedafbeb92db3ddf434f038984970bf0a6ac0c1 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sun, 15 Jul 2012 16:27:07 -0400 Subject: Switched to service stack json. Added more api enhancements. --- MediaBrowser.Api/HttpHandlers/ItemHandler.cs | 16 +- MediaBrowser.Common/Json/JsonSerializer.cs | 70 +++---- MediaBrowser.Common/Logging/BaseLogger.cs | 1 + MediaBrowser.Common/Logging/LogRow.cs | 1 + MediaBrowser.Common/Logging/LogSeverity.cs | 18 -- MediaBrowser.Common/MediaBrowser.Common.csproj | 11 +- MediaBrowser.Common/Model/DictionaryBaseItem.cs | 227 +++++++++++++++++++++ MediaBrowser.Common/Net/Handlers/JsonHandler.cs | 2 +- MediaBrowser.Common/Plugins/BasePlugin.cs | 2 +- MediaBrowser.Common/packages.config | 1 - MediaBrowser.Controller/Kernel.cs | 2 +- .../MediaBrowser.Controller.csproj | 4 - MediaBrowser.Controller/UserController.cs | 4 +- MediaBrowser.Controller/packages.config | 1 - MediaBrowser.Model/Configuration/Configuration.cs | 4 +- MediaBrowser.Model/Entities/BaseItem.cs | 88 +++++--- MediaBrowser.Model/Entities/Folder.cs | 18 +- MediaBrowser.Model/Logging/LogSeverity.cs | 18 ++ MediaBrowser.Model/MediaBrowser.Model.csproj | 14 +- MediaBrowser.Model/packages.config | 4 - MediaBrowser.Program/MediaBrowser.Program.csproj | 4 + MediaBrowser.Program/Program.cs | 1 + MediaBrowser.TV/Entities/Episode.cs | 2 +- MediaBrowser.TV/Entities/Season.cs | 9 +- MediaBrowser.TV/MediaBrowser.TV.csproj | 8 +- MediaBrowser.TV/Metadata/EpisodeXmlParser.cs | 11 +- MediaBrowser.TV/Resolvers/SeriesResolver.cs | 1 - MediaBrowser.TV/packages.config | 4 - 28 files changed, 387 insertions(+), 159 deletions(-) delete mode 100644 MediaBrowser.Common/Logging/LogSeverity.cs create mode 100644 MediaBrowser.Common/Model/DictionaryBaseItem.cs create mode 100644 MediaBrowser.Model/Logging/LogSeverity.cs delete mode 100644 MediaBrowser.Model/packages.config delete mode 100644 MediaBrowser.TV/packages.config (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs index 5571588c89..7b4b02b630 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Net; using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Model.Entities; +using MediaBrowser.Common.Json; namespace MediaBrowser.Api.HttpHandlers { @@ -21,24 +22,19 @@ namespace MediaBrowser.Api.HttpHandlers public static object GetSerializationObject(BaseItem item, bool includeChildren) { - Folder folder = item as Folder; - - if (includeChildren && folder != null) + if (includeChildren && item.IsFolder) { + Folder folder = item as Folder; + return new { BaseItem = item, - Children = folder.Children, - Type = item.GetType().Name + Children = folder.Children }; } else { - return new - { - BaseItem = item, - Type = item.GetType().Name - }; + return item; } } diff --git a/MediaBrowser.Common/Json/JsonSerializer.cs b/MediaBrowser.Common/Json/JsonSerializer.cs index 903482fc87..55663357ab 100644 --- a/MediaBrowser.Common/Json/JsonSerializer.cs +++ b/MediaBrowser.Common/Json/JsonSerializer.cs @@ -1,55 +1,55 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; +using System.IO; namespace MediaBrowser.Common.Json { public class JsonSerializer { - public static void Serialize(T o, Stream stream) + public static void SerializeToStream(T o, Stream stream) { - using (StreamWriter streamWriter = new StreamWriter(stream)) - { - using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(streamWriter)) - { - var settings = new Newtonsoft.Json.JsonSerializerSettings() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore - }; - - Newtonsoft.Json.JsonSerializer.Create(settings).Serialize(writer, o); - } - } + Configure(); + + ServiceStack.Text.JsonSerializer.SerializeToStream(o, stream); } - public static void Serialize(T o, string file) + public static void SerializeToFile(T o, string file) { + Configure(); + using (StreamWriter streamWriter = new StreamWriter(file)) { - using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(streamWriter)) - { - var settings = new Newtonsoft.Json.JsonSerializerSettings() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore - }; - - Newtonsoft.Json.JsonSerializer.Create(settings).Serialize(writer, o); - } + ServiceStack.Text.JsonSerializer.SerializeToWriter(o, streamWriter); } } - public static T Deserialize(string file) + public static T DeserializeFromFile(string file) { - using (StreamReader streamReader = new StreamReader(file)) + Configure(); + + using (Stream stream = File.OpenRead(file)) { - using (Newtonsoft.Json.JsonTextReader reader = new Newtonsoft.Json.JsonTextReader(streamReader)) - { - return Newtonsoft.Json.JsonSerializer.Create(new Newtonsoft.Json.JsonSerializerSettings() { }).Deserialize(reader); - } + return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); } } + + public static T DeserializeFromStream(Stream stream) + { + Configure(); + + return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); + } + + public static T DeserializeFromString(string data) + { + Configure(); + + return ServiceStack.Text.JsonSerializer.DeserializeFromString(data); + } + + private static void Configure() + { + ServiceStack.Text.JsConfig.ExcludeTypeInfo = true; + ServiceStack.Text.JsConfig.IncludeNullValues = false; + ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601; + } } } diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs index 51c6632d56..407c8baa76 100644 --- a/MediaBrowser.Common/Logging/BaseLogger.cs +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Text; using System.Threading; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Logging { diff --git a/MediaBrowser.Common/Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs index 39c69eb454..d1e234250c 100644 --- a/MediaBrowser.Common/Logging/LogRow.cs +++ b/MediaBrowser.Common/Logging/LogRow.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Logging { diff --git a/MediaBrowser.Common/Logging/LogSeverity.cs b/MediaBrowser.Common/Logging/LogSeverity.cs deleted file mode 100644 index b9578522e5..0000000000 --- a/MediaBrowser.Common/Logging/LogSeverity.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Logging -{ - [Flags] - public enum LogSeverity - { - None = 0, - Debug = 1, - Info = 2, - Warning = 4, - Error = 8 - } -} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 3c7f0ff045..8ee14d3a98 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -30,9 +30,6 @@ 4 - - ..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll - ..\packages\ServiceStack.Text.3.8.5\lib\net35\ServiceStack.Text.dll @@ -50,6 +47,7 @@ + @@ -63,7 +61,6 @@ - @@ -71,6 +68,12 @@ + + + {9b1ddd79-5134-4df3-ace3-d1957a7350d8} + MediaBrowser.Model + + - + - + + + + + - - + - @@ -46,7 +45,6 @@ - diff --git a/MediaBrowser.Net/CollectionExtensions.cs b/MediaBrowser.Net/CollectionExtensions.cs deleted file mode 100644 index a6b59904f3..0000000000 --- a/MediaBrowser.Net/CollectionExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; - -namespace MediaBrowser.Net -{ - public static class CollectionExtensions - { - public static IDictionary> ToDictionary(this NameValueCollection source) - { - return source.AllKeys.ToDictionary>(key => key, source.GetValues); - } - } -} \ No newline at end of file diff --git a/MediaBrowser.Net/Handlers/BaseEmbeddedResourceHandler.cs b/MediaBrowser.Net/Handlers/BaseEmbeddedResourceHandler.cs deleted file mode 100644 index d7f579d05a..0000000000 --- a/MediaBrowser.Net/Handlers/BaseEmbeddedResourceHandler.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.IO; - -namespace MediaBrowser.Net.Handlers -{ - public abstract class BaseEmbeddedResourceHandler : BaseHandler - { - public BaseEmbeddedResourceHandler(string resourcePath) - : base() - { - ResourcePath = resourcePath; - } - - protected string ResourcePath { get; set; } - - public override string ContentType - { - get - { - string extension = Path.GetExtension(ResourcePath); - - if (extension.EndsWith("jpeg", StringComparison.OrdinalIgnoreCase) || extension.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)) - { - return "image/jpeg"; - } - else if (extension.EndsWith("png", StringComparison.OrdinalIgnoreCase)) - { - return "image/png"; - } - else if (extension.EndsWith("ico", StringComparison.OrdinalIgnoreCase)) - { - return "image/ico"; - } - else if (extension.EndsWith("js", StringComparison.OrdinalIgnoreCase)) - { - return "application/x-javascript"; - } - else if (extension.EndsWith("css", StringComparison.OrdinalIgnoreCase)) - { - return "text/css"; - } - else if (extension.EndsWith("html", StringComparison.OrdinalIgnoreCase)) - { - return "text/html; charset=utf-8"; - } - - return "text/plain; charset=utf-8"; - } - } - - protected override void WriteResponseToOutputStream(Stream stream) - { - GetEmbeddedResourceStream().CopyTo(stream); - } - - protected abstract Stream GetEmbeddedResourceStream(); - } -} diff --git a/MediaBrowser.Net/Handlers/BaseHandler.cs b/MediaBrowser.Net/Handlers/BaseHandler.cs deleted file mode 100644 index 7a2bcffe97..0000000000 --- a/MediaBrowser.Net/Handlers/BaseHandler.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.IO; -using System.IO.Compression; - -namespace MediaBrowser.Net.Handlers -{ - public abstract class BaseHandler - { - /// - /// Response headers - /// - public IDictionary Headers = new Dictionary(); - - /// - /// The action to write the response to the output stream - /// - public Action WriteStream { get; set; } - - /// - /// The original RequestContext - /// - public RequestContext RequestContext { get; set; } - - /// - /// The original QueryString - /// - protected NameValueCollection QueryString - { - get - { - return RequestContext.Request.QueryString; - } - } - - /// - /// Gets the MIME type to include in the response headers - /// - public abstract string ContentType { get; } - - /// - /// Gets the status code to include in the response headers - /// - public virtual int StatusCode - { - get - { - return 200; - } - } - - /// - /// Gets the cache duration to include in the response headers - /// - public virtual TimeSpan CacheDuration - { - get - { - return TimeSpan.FromTicks(0); - } - } - - /// - /// Gets the last date modified of the content being returned, if this can be determined. - /// This will be used to invalidate the cache, so it's not needed if CacheDuration is 0. - /// - public virtual DateTime? LastDateModified - { - get - { - return null; - } - } - - public virtual bool GzipResponse - { - get - { - return true; - } - } - - public BaseHandler() - { - WriteStream = s => - { - WriteReponse(s); - s.Close(); - }; - } - - private void WriteReponse(Stream stream) - { - if (GzipResponse) - { - using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Compress, false)) - { - WriteResponseToOutputStream(gzipStream); - } - } - else - { - WriteResponseToOutputStream(stream); - } - } - - protected abstract void WriteResponseToOutputStream(Stream stream); - - } -} \ No newline at end of file diff --git a/MediaBrowser.Net/Handlers/BaseJsonHandler.cs b/MediaBrowser.Net/Handlers/BaseJsonHandler.cs deleted file mode 100644 index 725b89c32e..0000000000 --- a/MediaBrowser.Net/Handlers/BaseJsonHandler.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace MediaBrowser.Net.Handlers -{ - public abstract class BaseJsonHandler : BaseHandler - { - public override string ContentType - { - get { return "application/json"; } - } - } -} diff --git a/MediaBrowser.Net/HttpServer.cs b/MediaBrowser.Net/HttpServer.cs deleted file mode 100644 index aa24538d05..0000000000 --- a/MediaBrowser.Net/HttpServer.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Net; -using System.Reactive.Linq; - -namespace MediaBrowser.Net -{ - public class HttpServer : IObservable, IDisposable - { - private readonly HttpListener listener; - private readonly IObservable stream; - - public HttpServer(string url) - { - listener = new HttpListener(); - listener.Prefixes.Add(url); - listener.Start(); - stream = ObservableHttpContext(); - } - - private IObservable ObservableHttpContext() - { - return Observable.Create(obs => - Observable.FromAsyncPattern(listener.BeginGetContext, - listener.EndGetContext)() - .Select(c => new RequestContext(c)) - .Subscribe(obs)) - .Repeat() - .Retry() - .Publish() - .RefCount(); - } - public void Dispose() - { - listener.Stop(); - } - - public IDisposable Subscribe(IObserver observer) - { - return stream.Subscribe(observer); - } - } -} \ No newline at end of file diff --git a/MediaBrowser.Net/MediaBrowser.Net.csproj b/MediaBrowser.Net/MediaBrowser.Net.csproj deleted file mode 100644 index 6f1b7cccfe..0000000000 --- a/MediaBrowser.Net/MediaBrowser.Net.csproj +++ /dev/null @@ -1,66 +0,0 @@ - - - - - Debug - AnyCPU - {5DA08D1C-0D52-4B1B-AA66-E4A171D938F6} - Library - Properties - MediaBrowser.Net - MediaBrowser.Net - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - ..\packages\Rx-Main.1.0.11226\lib\Net4\System.Reactive.dll - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MediaBrowser.Net/Properties/AssemblyInfo.cs b/MediaBrowser.Net/Properties/AssemblyInfo.cs deleted file mode 100644 index 00964b6a26..0000000000 --- a/MediaBrowser.Net/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MediaBrowser.Net")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.Net")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("eacc40b5-e24e-4467-8000-f40874048d45")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Net/Request.cs b/MediaBrowser.Net/Request.cs deleted file mode 100644 index 43f854233e..0000000000 --- a/MediaBrowser.Net/Request.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Net -{ - public class Request - { - public string HttpMethod { get; set; } - public IDictionary> Headers { get; set; } - public Stream InputStream { get; set; } - public string RawUrl { get; set; } - public int ContentLength - { - get { return int.Parse(Headers["Content-Length"].First()); } - } - } -} \ No newline at end of file diff --git a/MediaBrowser.Net/RequestContext.cs b/MediaBrowser.Net/RequestContext.cs deleted file mode 100644 index 4c1350701c..0000000000 --- a/MediaBrowser.Net/RequestContext.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Linq; -using System.Net; -using MediaBrowser.Net.Handlers; - -namespace MediaBrowser.Net -{ - public class RequestContext - { - public HttpListenerRequest Request { get; private set; } - public HttpListenerResponse Response { get; private set; } - - public string LocalPath - { - get - { - return Request.Url.LocalPath; - } - } - - public RequestContext(HttpListenerContext context) - { - Response = context.Response; - Request = context.Request; - } - - public void Respond(BaseHandler handler) - { - Response.AddHeader("Access-Control-Allow-Origin", "*"); - - Response.KeepAlive = true; - - foreach (var header in handler.Headers) - { - Response.AddHeader(header.Key, header.Value); - } - - int statusCode = handler.StatusCode; - Response.ContentType = handler.ContentType; - - TimeSpan cacheDuration = handler.CacheDuration; - - if (Request.Headers.AllKeys.Contains("If-Modified-Since")) - { - DateTime ifModifiedSince; - - if (DateTime.TryParse(Request.Headers["If-Modified-Since"].Replace(" GMT", string.Empty), out ifModifiedSince)) - { - // If the cache hasn't expired yet just return a 304 - if (IsCacheValid(ifModifiedSince, cacheDuration, handler.LastDateModified)) - { - statusCode = 304; - } - } - } - - Response.SendChunked = true; - Response.StatusCode = statusCode; - - if (statusCode != 304) - { - if (handler.GzipResponse) - { - Response.AddHeader("Content-Encoding", "gzip"); - } - - if (cacheDuration.Ticks > 0) - { - CacheResponse(Response, cacheDuration, handler.LastDateModified); - } - handler.WriteStream(Response.OutputStream); - } - else - { - Response.OutputStream.Flush(); - Response.OutputStream.Close(); - } - } - - private void CacheResponse(HttpListenerResponse response, TimeSpan duration, DateTime? dateModified) - { - DateTime lastModified = dateModified ?? DateTime.Now; - - response.Headers[HttpResponseHeader.CacheControl] = "Public"; - response.Headers[HttpResponseHeader.Expires] = DateTime.Now.Add(duration).ToString("r"); - response.Headers[HttpResponseHeader.LastModified] = lastModified.ToString("r"); - } - - private bool IsCacheValid(DateTime ifModifiedSince, TimeSpan cacheDuration, DateTime? dateModified) - { - if (dateModified.HasValue) - { - DateTime lastModified = NormalizeDateForComparison(dateModified.Value); - ifModifiedSince = NormalizeDateForComparison(ifModifiedSince); - - return lastModified <= ifModifiedSince; - } - - DateTime cacheExpirationDate = ifModifiedSince.Add(cacheDuration); - - if (DateTime.Now < cacheExpirationDate) - { - return true; - } - - return false; - } - - /// - /// When the browser sends the IfModifiedDate, it's precision is limited to seconds, so this will account for that - /// - private DateTime NormalizeDateForComparison(DateTime date) - { - return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second); - } - - } -} \ No newline at end of file diff --git a/MediaBrowser.Net/StreamExtensions.cs b/MediaBrowser.Net/StreamExtensions.cs deleted file mode 100644 index b4925cc7fd..0000000000 --- a/MediaBrowser.Net/StreamExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.IO; -using System.Reactive.Linq; - -namespace MediaBrowser.Net -{ - public static class StreamExtensions - { - public static IObservable ReadBytes(this Stream stream, int count) - { - var buffer = new byte[count]; - return Observable.FromAsyncPattern((cb, state) => stream.BeginRead(buffer, 0, count, cb, state), ar => - { - stream.EndRead(ar); - return buffer; - })(); - } - } -} \ No newline at end of file diff --git a/MediaBrowser.Net/packages.config b/MediaBrowser.Net/packages.config deleted file mode 100644 index 47102a263f..0000000000 --- a/MediaBrowser.Net/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/MediaBrowser.Program/App.config b/MediaBrowser.Program/App.config index 04df0f820e..5aff9b3508 100644 --- a/MediaBrowser.Program/App.config +++ b/MediaBrowser.Program/App.config @@ -1,7 +1,7 @@  - + diff --git a/MediaBrowser.Program/Program.cs b/MediaBrowser.Program/Program.cs index 1933ad1260..ff7ad002f3 100644 --- a/MediaBrowser.Program/Program.cs +++ b/MediaBrowser.Program/Program.cs @@ -1,6 +1,4 @@ using System; -using System.Configuration; -using System.IO; using MediaBrowser.Controller; namespace MediaBrowser.Program @@ -18,24 +16,7 @@ namespace MediaBrowser.Program Console.WriteLine("Loading"); - string installDir = ConfigurationManager.AppSettings["DataPath"]; - - if (!Path.IsPathRooted(installDir)) - { - string path = System.Reflection.Assembly.GetExecutingAssembly().Location; - path = Path.GetDirectoryName(path); - - installDir = Path.Combine(path, installDir); - - installDir = Path.GetFullPath(installDir); - } - - if (!Directory.Exists(installDir)) - { - Directory.CreateDirectory(installDir); - } - - Kernel kernel = new Kernel(installDir); + Kernel kernel = new Kernel(); kernel.Init(); diff --git a/MediaBrowser.sln b/MediaBrowser.sln index 23e78b42f9..6f94baf31d 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -21,8 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Common", "Medi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Model", "MediaBrowser.Model\MediaBrowser.Model.csproj", "{7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Net", "MediaBrowser.Net\MediaBrowser.Net.csproj", "{5DA08D1C-0D52-4B1B-AA66-E4A171D938F6}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,10 +43,6 @@ Global {5758B2C7-949A-421D-B268-70A950CF8741}.Debug|Any CPU.Build.0 = Debug|Any CPU {5758B2C7-949A-421D-B268-70A950CF8741}.Release|Any CPU.ActiveCfg = Release|Any CPU {5758B2C7-949A-421D-B268-70A950CF8741}.Release|Any CPU.Build.0 = Release|Any CPU - {5DA08D1C-0D52-4B1B-AA66-E4A171D938F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5DA08D1C-0D52-4B1B-AA66-E4A171D938F6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5DA08D1C-0D52-4B1B-AA66-E4A171D938F6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5DA08D1C-0D52-4B1B-AA66-E4A171D938F6}.Release|Any CPU.Build.0 = Release|Any CPU {78AEA637-AF42-4F43-8E2B-0F2F0E2931F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {78AEA637-AF42-4F43-8E2B-0F2F0E2931F3}.Debug|Any CPU.Build.0 = Debug|Any CPU {78AEA637-AF42-4F43-8E2B-0F2F0E2931F3}.Release|Any CPU.ActiveCfg = Release|Any CPU -- cgit v1.2.3 From 84af205572e6ab9ca3e10f6de33cbce278e01335 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Tue, 24 Jul 2012 10:54:34 -0400 Subject: Added new api handlers to get plugin information --- MediaBrowser.Api/HttpHandlers/MediaHandler.cs | 101 --------------------- .../HttpHandlers/PluginConfigurationHandler.cs | 19 ++++ MediaBrowser.Api/HttpHandlers/PluginsHandler.cs | 37 ++++++++ MediaBrowser.Api/MediaBrowser.Api.csproj | 3 +- MediaBrowser.Api/Plugin.cs | 22 +++-- MediaBrowser.Api/Properties/AssemblyInfo.cs | 2 +- .../Configuration/UserConfiguration.cs | 21 ----- MediaBrowser.Common/MediaBrowser.Common.csproj | 2 - MediaBrowser.Common/Plugins/BasePlugin.cs | 88 ++++++++++++++---- .../Plugins/BasePluginConfiguration.cs | 13 --- MediaBrowser.Common/Plugins/PluginController.cs | 38 ++++++-- .../MediaBrowser.Configuration.csproj | 4 + MediaBrowser.Configuration/Plugin.cs | 6 +- .../Properties/AssemblyInfo.cs | 2 +- .../Configuration/ServerConfiguration.cs | 1 + .../Configuration/ServerConfigurationController.cs | 5 +- MediaBrowser.Controller/Kernel.cs | 2 +- MediaBrowser.HtmlBrowser/Plugin.cs | 16 ++-- .../Properties/AssemblyInfo.cs | 2 +- .../MediaBrowser.InternetProviders.csproj | 4 + MediaBrowser.InternetProviders/Plugin.cs | 9 +- .../PluginConfiguration.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../Configuration/UserConfiguration.cs | 16 ++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 3 + .../Plugins/BasePluginConfiguration.cs | 18 ++++ MediaBrowser.Model/Plugins/PluginInfo.cs | 17 ++++ MediaBrowser.Movies/Plugin.cs | 10 +- MediaBrowser.Movies/Properties/AssemblyInfo.cs | 2 +- MediaBrowser.TV/Plugin.cs | 15 ++- MediaBrowser.TV/Properties/AssemblyInfo.cs | 2 +- 31 files changed, 280 insertions(+), 204 deletions(-) delete mode 100644 MediaBrowser.Api/HttpHandlers/MediaHandler.cs create mode 100644 MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs create mode 100644 MediaBrowser.Api/HttpHandlers/PluginsHandler.cs delete mode 100644 MediaBrowser.Common/Configuration/UserConfiguration.cs delete mode 100644 MediaBrowser.Common/Plugins/BasePluginConfiguration.cs create mode 100644 MediaBrowser.Model/Configuration/UserConfiguration.cs create mode 100644 MediaBrowser.Model/Plugins/BasePluginConfiguration.cs create mode 100644 MediaBrowser.Model/Plugins/PluginInfo.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/HttpHandlers/MediaHandler.cs b/MediaBrowser.Api/HttpHandlers/MediaHandler.cs deleted file mode 100644 index 73f8de7d82..0000000000 --- a/MediaBrowser.Api/HttpHandlers/MediaHandler.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.IO; -using MediaBrowser.Common.Net.Handlers; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - class MediaHandler : BaseHandler - { - private string _MediaPath = string.Empty; - private string MediaPath - { - get - { - if (string.IsNullOrEmpty(_MediaPath)) - { - _MediaPath = GetMediaPath(); - } - - return _MediaPath; - } - } - - private string GetMediaPath() - { - string path = QueryString["path"] ?? string.Empty; - - if (!string.IsNullOrEmpty(path)) - { - return path; - } - - BaseItem item = ApiService.GetItemById(QueryString["id"]); - - return item.Path; - } - - public override bool GzipResponse - { - get - { - return false; - } - } - - public override string ContentType - { - get - { - // http://www.codingcereal.com/2011/10/an-array-of-45-video-mime-types/ - - string extension = Path.GetExtension(MediaPath); - - if (extension.EndsWith("mkv", StringComparison.OrdinalIgnoreCase)) - { - return "video/x-matroska"; - } - else if (extension.EndsWith("avi", StringComparison.OrdinalIgnoreCase)) - { - return "video/avi"; - } - else if (extension.EndsWith("wmv", StringComparison.OrdinalIgnoreCase)) - { - return "video/wmv"; - } - else if (extension.EndsWith("m4v", StringComparison.OrdinalIgnoreCase)) - { - return "video/m4v"; - } - else if (extension.EndsWith("flv", StringComparison.OrdinalIgnoreCase)) - { - return "video/flv"; - } - else if (extension.EndsWith("mov", StringComparison.OrdinalIgnoreCase)) - { - return "video/quicktime"; - } - else if (extension.EndsWith("mp4", StringComparison.OrdinalIgnoreCase)) - { - return "video/mp4"; - } - - return "video/x-matroska"; - } - } - - protected override void WriteResponseToOutputStream(Stream stream) - { - try - { - using (Stream input = File.OpenRead(MediaPath)) - { - input.CopyTo(stream); - } - } - catch - { - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs new file mode 100644 index 0000000000..9e5657e3c2 --- /dev/null +++ b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs @@ -0,0 +1,19 @@ +using System; +using System.Linq; +using MediaBrowser.Controller; + +namespace MediaBrowser.Api.HttpHandlers +{ + public class PluginConfigurationHandler : JsonHandler + { + protected override object ObjectToSerialize + { + get + { + string pluginName = QueryString["name"]; + + return Kernel.Instance.PluginController.Plugins.First(p => p.Name.Equals(pluginName, StringComparison.OrdinalIgnoreCase)).Configuration; + } + } + } +} diff --git a/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs new file mode 100644 index 0000000000..a558da163d --- /dev/null +++ b/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs @@ -0,0 +1,37 @@ +using System.Linq; +using MediaBrowser.Controller; +using MediaBrowser.Model.Plugins; + +namespace MediaBrowser.Api.HttpHandlers +{ + /// + /// Provides information about installed plugins + /// + public class PluginsHandler : JsonHandler + { + protected override object ObjectToSerialize + { + get + { + var plugins = Kernel.Instance.PluginController.Plugins.Select(p => + { + return new PluginInfo() + { + Path = p.Path, + Name = p.Name, + Enabled = p.Enabled, + DownloadToUI = p.DownloadToUI, + Version = p.Version + }; + }); + + if (QueryString["uionly"] == "1") + { + plugins = plugins.Where(p => p.DownloadToUI); + } + + return plugins; + } + } + } +} diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index a803cb73a4..25889f9837 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -54,13 +54,14 @@ + + - diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index 6c2e9df7ec..6ced7a704a 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -5,12 +5,18 @@ using MediaBrowser.Common.Net; using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Common.Plugins; using MediaBrowser.Controller; +using MediaBrowser.Model.Plugins; namespace MediaBrowser.Api { - public class Plugin : BasePlugin + public class Plugin : BaseGenericPlugin { - protected override void InitInternal() + public override string Name + { + get { return "WebAPI"; } + } + + public override void InitInServer() { var httpServer = Kernel.Instance.HttpServer; @@ -43,10 +49,6 @@ namespace MediaBrowser.Api { handler = new UsersHandler(); } - else if (localPath.EndsWith("/api/media", StringComparison.OrdinalIgnoreCase)) - { - handler = new MediaHandler(); - } else if (localPath.EndsWith("/api/genre", StringComparison.OrdinalIgnoreCase)) { handler = new GenreHandler(); @@ -75,6 +77,14 @@ namespace MediaBrowser.Api { handler = new UserConfigurationHandler(); } + else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase)) + { + handler = new PluginsHandler(); + } + else if (localPath.EndsWith("/api/pluginconfiguration", StringComparison.OrdinalIgnoreCase)) + { + handler = new PluginConfigurationHandler(); + } if (handler != null) { diff --git a/MediaBrowser.Api/Properties/AssemblyInfo.cs b/MediaBrowser.Api/Properties/AssemblyInfo.cs index 0a7a85dc66..bd747ea7da 100644 --- a/MediaBrowser.Api/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Api/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Common/Configuration/UserConfiguration.cs b/MediaBrowser.Common/Configuration/UserConfiguration.cs deleted file mode 100644 index 0cdc810a6a..0000000000 --- a/MediaBrowser.Common/Configuration/UserConfiguration.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Configuration -{ - /// - /// This holds settings that can be personalized on a per-user, per-device basis. - /// - public class UserConfiguration - { - public int RecentItemDays { get; set; } - - public UserConfiguration() - { - RecentItemDays = 14; - } - } -} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 01d89d0f55..f7a223f1f5 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -49,7 +49,6 @@ - @@ -63,7 +62,6 @@ - diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index be72dabca3..7fdb2583ee 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -1,49 +1,97 @@ -using System.IO; +using System; +using System.IO; using MediaBrowser.Common.Json; +using MediaBrowser.Model.Plugins; namespace MediaBrowser.Common.Plugins { - public abstract class BasePlugin : IPlugin + /// + /// Provides a BasePlugin with generics, allowing for strongly typed configuration access. + /// + public abstract class BaseGenericPlugin : BasePlugin where TConfigurationType : BasePluginConfiguration, new() { + public new TConfigurationType Configuration + { + get + { + return base.Configuration as TConfigurationType; + } + set + { + base.Configuration = value; + } + } + + public override void ReloadConfiguration() + { + if (!File.Exists(ConfigurationPath)) + { + Configuration = new TConfigurationType(); + } + else + { + Configuration = JsonSerializer.DeserializeFromFile(ConfigurationPath); + Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationPath); + } + } + } + + /// + /// Provides a common base class for all plugins + /// + public abstract class BasePlugin + { + public abstract string Name { get; } public string Path { get; set; } - public TConfigurationType Configuration { get; private set; } + public Version Version { get; set; } - private string ConfigurationPath + public BasePluginConfiguration Configuration { get; protected set; } + + protected string ConfigurationPath { get { return System.IO.Path.Combine(Path, "config.js"); } } - - public void Init() - { - Configuration = GetConfiguration(); - if (Configuration.Enabled) + public bool Enabled + { + get { - InitInternal(); + return Configuration.Enabled; } } - protected abstract void InitInternal(); + public DateTime ConfigurationDateLastModified + { + get + { + return Configuration.DateLastModified; + } + } - private TConfigurationType GetConfiguration() + /// + /// Returns true or false indicating if the plugin should be downloaded and run within the UI. + /// + public virtual bool DownloadToUI { - if (!File.Exists(ConfigurationPath)) + get { - return new TConfigurationType(); + return false; } + } - return JsonSerializer.DeserializeFromFile(ConfigurationPath); + public abstract void ReloadConfiguration(); + + public virtual void InitInServer() + { } - } - public interface IPlugin - { - string Path { get; set; } + public virtual void InitInUI() + { + } - void Init(); } } diff --git a/MediaBrowser.Common/Plugins/BasePluginConfiguration.cs b/MediaBrowser.Common/Plugins/BasePluginConfiguration.cs deleted file mode 100644 index d3e47c84a4..0000000000 --- a/MediaBrowser.Common/Plugins/BasePluginConfiguration.cs +++ /dev/null @@ -1,13 +0,0 @@ - -namespace MediaBrowser.Common.Plugins -{ - public class BasePluginConfiguration - { - public bool Enabled { get; set; } - - public BasePluginConfiguration() - { - Enabled = true; - } - } -} diff --git a/MediaBrowser.Common/Plugins/PluginController.cs b/MediaBrowser.Common/Plugins/PluginController.cs index 1f83d485b0..c26275436b 100644 --- a/MediaBrowser.Common/Plugins/PluginController.cs +++ b/MediaBrowser.Common/Plugins/PluginController.cs @@ -18,7 +18,7 @@ namespace MediaBrowser.Common.Plugins /// /// Gets the list of currently loaded plugins /// - public IEnumerable Plugins { get; private set; } + public IEnumerable Plugins { get; private set; } /// /// Initializes the controller @@ -32,7 +32,21 @@ namespace MediaBrowser.Common.Plugins Parallel.For(0, Plugins.Count(), i => { - Plugins.ElementAt(i).Init(); + var plugin = Plugins.ElementAt(i); + + plugin.ReloadConfiguration(); + + if (plugin.Enabled) + { + if (context == KernelContext.Server) + { + plugin.InitInServer(); + } + else + { + plugin.InitInUI(); + } + } }); } @@ -40,18 +54,18 @@ namespace MediaBrowser.Common.Plugins /// Gets all plugins within PluginsPath /// /// - private IEnumerable GetAllPlugins() + private IEnumerable GetAllPlugins() { if (!Directory.Exists(PluginsPath)) { Directory.CreateDirectory(PluginsPath); } - List plugins = new List(); + List plugins = new List(); foreach (string folder in Directory.GetDirectories(PluginsPath, "*", SearchOption.TopDirectoryOnly)) { - IPlugin plugin = GetPluginFromDirectory(folder); + BasePlugin plugin = GetPluginFromDirectory(folder); plugin.Path = folder; @@ -64,7 +78,7 @@ namespace MediaBrowser.Common.Plugins return plugins; } - private IPlugin GetPluginFromDirectory(string path) + private BasePlugin GetPluginFromDirectory(string path) { string dll = Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly).FirstOrDefault(); @@ -76,18 +90,22 @@ namespace MediaBrowser.Common.Plugins return null; } - private IPlugin GetPluginFromDll(string path) + private BasePlugin GetPluginFromDll(string path) { return GetPluginFromDll(Assembly.Load(File.ReadAllBytes(path))); } - private IPlugin GetPluginFromDll(Assembly assembly) + private BasePlugin GetPluginFromDll(Assembly assembly) { - var plugin = assembly.GetTypes().Where(type => typeof(IPlugin).IsAssignableFrom(type)).FirstOrDefault(); + var plugin = assembly.GetTypes().Where(type => typeof(BasePlugin).IsAssignableFrom(type)).FirstOrDefault(); if (plugin != null) { - return plugin.GetConstructor(Type.EmptyTypes).Invoke(null) as IPlugin; + BasePlugin instance = plugin.GetConstructor(Type.EmptyTypes).Invoke(null) as BasePlugin; + + instance.Version = assembly.GetName().Version; + + return instance; } return null; diff --git a/MediaBrowser.Configuration/MediaBrowser.Configuration.csproj b/MediaBrowser.Configuration/MediaBrowser.Configuration.csproj index b94672537b..98b179f355 100644 --- a/MediaBrowser.Configuration/MediaBrowser.Configuration.csproj +++ b/MediaBrowser.Configuration/MediaBrowser.Configuration.csproj @@ -55,6 +55,10 @@ {17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2} MediaBrowser.Controller + + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} + MediaBrowser.Model + diff --git a/MediaBrowser.Configuration/Plugin.cs b/MediaBrowser.Configuration/Plugin.cs index a16ad064b4..f88dc7a4ca 100644 --- a/MediaBrowser.Configuration/Plugin.cs +++ b/MediaBrowser.Configuration/Plugin.cs @@ -1,11 +1,13 @@ using MediaBrowser.Common.Plugins; +using MediaBrowser.Model.Plugins; namespace MediaBrowser.Configuration { - public class Plugin : BasePlugin + public class Plugin : BaseGenericPlugin { - protected override void InitInternal() + public override string Name { + get { return "Web-based Configuration"; } } } } diff --git a/MediaBrowser.Configuration/Properties/AssemblyInfo.cs b/MediaBrowser.Configuration/Properties/AssemblyInfo.cs index 5212f26db7..919388d51d 100644 --- a/MediaBrowser.Configuration/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Configuration/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs index 73727b393f..818c69eed2 100644 --- a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; namespace MediaBrowser.Controller.Configuration { diff --git a/MediaBrowser.Controller/Configuration/ServerConfigurationController.cs b/MediaBrowser.Controller/Configuration/ServerConfigurationController.cs index 6f262a32e8..76c3cc43ce 100644 --- a/MediaBrowser.Controller/Configuration/ServerConfigurationController.cs +++ b/MediaBrowser.Controller/Configuration/ServerConfigurationController.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; namespace MediaBrowser.Controller.Configuration { diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 468e7ab2f4..8b2688da74 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -5,13 +5,13 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Kernel; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Events; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Users; diff --git a/MediaBrowser.HtmlBrowser/Plugin.cs b/MediaBrowser.HtmlBrowser/Plugin.cs index b8296492fb..57e2886f93 100644 --- a/MediaBrowser.HtmlBrowser/Plugin.cs +++ b/MediaBrowser.HtmlBrowser/Plugin.cs @@ -1,15 +1,17 @@ -using System; -using System.Reactive.Linq; -using MediaBrowser.Common.Net.Handlers; -using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.Plugins; using MediaBrowser.Controller; -using MediaBrowser.HtmlBrowser.Handlers; +using MediaBrowser.Model.Plugins; namespace MediaBrowser.HtmlBrowser { - public class Plugin : BasePlugin + public class Plugin : BaseGenericPlugin { - protected override void InitInternal() + public override string Name + { + get { return "Html Library Browser"; } + } + + public override void InitInServer() { var httpServer = Kernel.Instance.HttpServer; diff --git a/MediaBrowser.HtmlBrowser/Properties/AssemblyInfo.cs b/MediaBrowser.HtmlBrowser/Properties/AssemblyInfo.cs index b65ea6f779..538756b974 100644 --- a/MediaBrowser.HtmlBrowser/Properties/AssemblyInfo.cs +++ b/MediaBrowser.HtmlBrowser/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.InternetProviders/MediaBrowser.InternetProviders.csproj b/MediaBrowser.InternetProviders/MediaBrowser.InternetProviders.csproj index 3b88a5b56b..c37218f851 100644 --- a/MediaBrowser.InternetProviders/MediaBrowser.InternetProviders.csproj +++ b/MediaBrowser.InternetProviders/MediaBrowser.InternetProviders.csproj @@ -52,6 +52,10 @@ {17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2} MediaBrowser.Controller + + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} + MediaBrowser.Model + {92b9f802-4415-438f-90e1-44602135ea41} MediaBrowser.Movies diff --git a/MediaBrowser.InternetProviders/Plugin.cs b/MediaBrowser.InternetProviders/Plugin.cs index c7b981aed0..837b698311 100644 --- a/MediaBrowser.InternetProviders/Plugin.cs +++ b/MediaBrowser.InternetProviders/Plugin.cs @@ -2,9 +2,14 @@ namespace MediaBrowser.InternetProviders { - public class Plugin : BasePlugin + public class Plugin : BaseGenericPlugin { - protected override void InitInternal() + public override string Name + { + get { return "Internet Providers"; } + } + + public override void InitInServer() { } } diff --git a/MediaBrowser.InternetProviders/PluginConfiguration.cs b/MediaBrowser.InternetProviders/PluginConfiguration.cs index abd189f2a2..bf9c04b724 100644 --- a/MediaBrowser.InternetProviders/PluginConfiguration.cs +++ b/MediaBrowser.InternetProviders/PluginConfiguration.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Plugins; +using MediaBrowser.Model.Plugins; namespace MediaBrowser.InternetProviders { diff --git a/MediaBrowser.InternetProviders/Properties/AssemblyInfo.cs b/MediaBrowser.InternetProviders/Properties/AssemblyInfo.cs index 859fc6ef9a..ff041feccd 100644 --- a/MediaBrowser.InternetProviders/Properties/AssemblyInfo.cs +++ b/MediaBrowser.InternetProviders/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.cs new file mode 100644 index 0000000000..5616f6dd60 --- /dev/null +++ b/MediaBrowser.Model/Configuration/UserConfiguration.cs @@ -0,0 +1,16 @@ + +namespace MediaBrowser.Model.Configuration +{ + /// + /// This holds settings that can be personalized on a per-user, per-device basis. + /// + public class UserConfiguration + { + public int RecentItemDays { get; set; } + + public UserConfiguration() + { + RecentItemDays = 14; + } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index b41b54c0bf..ceb58163ab 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -35,6 +35,7 @@ + @@ -45,6 +46,8 @@ + + diff --git a/MediaBrowser.Model/Plugins/BasePluginConfiguration.cs b/MediaBrowser.Model/Plugins/BasePluginConfiguration.cs new file mode 100644 index 0000000000..7881de598b --- /dev/null +++ b/MediaBrowser.Model/Plugins/BasePluginConfiguration.cs @@ -0,0 +1,18 @@ +using System; +using System.Runtime.Serialization; + +namespace MediaBrowser.Model.Plugins +{ + public class BasePluginConfiguration + { + public bool Enabled { get; set; } + + [IgnoreDataMember] + public DateTime DateLastModified { get; set; } + + public BasePluginConfiguration() + { + Enabled = true; + } + } +} diff --git a/MediaBrowser.Model/Plugins/PluginInfo.cs b/MediaBrowser.Model/Plugins/PluginInfo.cs new file mode 100644 index 0000000000..e08128fd7b --- /dev/null +++ b/MediaBrowser.Model/Plugins/PluginInfo.cs @@ -0,0 +1,17 @@ +using System; + +namespace MediaBrowser.Model.Plugins +{ + /// + /// This is a serializable stub class that is used by the api to provide information about installed plugins. + /// + public class PluginInfo + { + public string Name { get; set; } + public string Path { get; set; } + public bool Enabled { get; set; } + public bool DownloadToUI { get; set; } + public DateTime ConfigurationDateLastModified { get; set; } + public Version Version { get; set; } + } +} diff --git a/MediaBrowser.Movies/Plugin.cs b/MediaBrowser.Movies/Plugin.cs index df80dfaa8d..54e8279b21 100644 --- a/MediaBrowser.Movies/Plugin.cs +++ b/MediaBrowser.Movies/Plugin.cs @@ -1,13 +1,19 @@ using MediaBrowser.Common.Plugins; using MediaBrowser.Controller; +using MediaBrowser.Model.Plugins; using MediaBrowser.Movies.Entities; using MediaBrowser.Movies.Resolvers; namespace MediaBrowser.Movies { - public class Plugin : BasePlugin + public class Plugin : BaseGenericPlugin { - protected override void InitInternal() + public override string Name + { + get { return "Movies"; } + } + + public override void InitInServer() { Kernel.Instance.AddBaseItemType(); Kernel.Instance.AddBaseItemType(); diff --git a/MediaBrowser.Movies/Properties/AssemblyInfo.cs b/MediaBrowser.Movies/Properties/AssemblyInfo.cs index bc9c6b006a..351928efc2 100644 --- a/MediaBrowser.Movies/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Movies/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.TV/Plugin.cs b/MediaBrowser.TV/Plugin.cs index d003b04f6c..e68e737401 100644 --- a/MediaBrowser.TV/Plugin.cs +++ b/MediaBrowser.TV/Plugin.cs @@ -1,16 +1,21 @@ -using MediaBrowser.Common.Plugins; +using System; +using MediaBrowser.Common.Plugins; using MediaBrowser.Controller; using MediaBrowser.Controller.Events; -using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Plugins; using MediaBrowser.TV.Entities; using MediaBrowser.TV.Resolvers; -using System; namespace MediaBrowser.TV { - public class Plugin : BasePlugin + public class Plugin : BaseGenericPlugin { - protected override void InitInternal() + public override string Name + { + get { return "TV"; } + } + + public override void InitInServer() { Kernel.Instance.AddBaseItemType(); Kernel.Instance.AddBaseItemType(); diff --git a/MediaBrowser.TV/Properties/AssemblyInfo.cs b/MediaBrowser.TV/Properties/AssemblyInfo.cs index d92a7f5762..ebc70e3a2e 100644 --- a/MediaBrowser.TV/Properties/AssemblyInfo.cs +++ b/MediaBrowser.TV/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")] -- cgit v1.2.3 From 77669562743d725273ecd52677a6521aa0db7949 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Mon, 30 Jul 2012 09:44:28 -0400 Subject: Extracted Logging into a separate, portable class library --- .../Configuration/BaseApplicationConfiguration.cs | 19 ---- MediaBrowser.Common/Kernel/BaseKernel.cs | 69 +++++++++--- MediaBrowser.Common/Logging/BaseLogger.cs | 80 -------------- MediaBrowser.Common/Logging/FileLogger.cs | 55 ---------- MediaBrowser.Common/Logging/LogRow.cs | 118 --------------------- MediaBrowser.Common/Logging/LogSeverity.cs | 14 --- MediaBrowser.Common/Logging/Logger.cs | 34 ------ MediaBrowser.Common/MediaBrowser.Common.csproj | 11 +- MediaBrowser.Common/Progress/TaskProgress.cs | 19 ---- .../Configuration/ServerConfiguration.cs | 1 - MediaBrowser.Logging/BaseLogger.cs | 76 +++++++++++++ MediaBrowser.Logging/LogRow.cs | 40 +++++++ MediaBrowser.Logging/LogSeverity.cs | 14 +++ MediaBrowser.Logging/Logger.cs | 34 ++++++ MediaBrowser.Logging/MediaBrowser.Logging.csproj | 53 +++++++++ MediaBrowser.Logging/Properties/AssemblyInfo.cs | 30 ++++++ MediaBrowser.Logging/StreamLogger.cs | 32 ++++++ .../Configuration/BaseApplicationConfiguration.cs | 19 ++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 8 +- MediaBrowser.Model/Progress/TaskProgress.cs | 19 ++++ MediaBrowser.Program/Program.cs | 4 +- MediaBrowser.sln | 6 ++ 22 files changed, 393 insertions(+), 362 deletions(-) delete mode 100644 MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs delete mode 100644 MediaBrowser.Common/Logging/BaseLogger.cs delete mode 100644 MediaBrowser.Common/Logging/FileLogger.cs delete mode 100644 MediaBrowser.Common/Logging/LogRow.cs delete mode 100644 MediaBrowser.Common/Logging/LogSeverity.cs delete mode 100644 MediaBrowser.Common/Logging/Logger.cs delete mode 100644 MediaBrowser.Common/Progress/TaskProgress.cs create mode 100644 MediaBrowser.Logging/BaseLogger.cs create mode 100644 MediaBrowser.Logging/LogRow.cs create mode 100644 MediaBrowser.Logging/LogSeverity.cs create mode 100644 MediaBrowser.Logging/Logger.cs create mode 100644 MediaBrowser.Logging/MediaBrowser.Logging.csproj create mode 100644 MediaBrowser.Logging/Properties/AssemblyInfo.cs create mode 100644 MediaBrowser.Logging/StreamLogger.cs create mode 100644 MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs create mode 100644 MediaBrowser.Model/Progress/TaskProgress.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs deleted file mode 100644 index 7ed782bdb1..0000000000 --- a/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs +++ /dev/null @@ -1,19 +0,0 @@ -using MediaBrowser.Common.Logging; - -namespace MediaBrowser.Common.Configuration -{ - /// - /// Serves as a common base class for the Server and UI application Configurations - /// - public class BaseApplicationConfiguration - { - public LogSeverity LogSeverity { get; set; } - public int HttpServerPortNumber { get; set; } - - public BaseApplicationConfiguration() - { - LogSeverity = LogSeverity.Info; - HttpServerPortNumber = 8096; - } - } -} diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 09bb67218f..f997aea5dd 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -6,12 +6,12 @@ using System.Configuration; using System.IO; using System.Linq; using System.Reflection; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; using MediaBrowser.Common.Json; -using MediaBrowser.Common.Logging; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; -using MediaBrowser.Common.Progress; +using MediaBrowser.Model.Progress; +using MediaBrowser.Logging; namespace MediaBrowser.Common.Kernel { @@ -48,6 +48,22 @@ namespace MediaBrowser.Common.Kernel } } + /// + /// Gets the path to the log directory + /// + private string LogDirectoryPath + { + get + { + return Path.Combine(ProgramDataPath, "logs"); + } + } + + /// + /// Gets or sets the path to the current log file + /// + private string LogFilePath { get; set; } + /// /// Gets the current configuration /// @@ -73,12 +89,12 @@ namespace MediaBrowser.Common.Kernel public BaseKernel() { ProgramDataPath = GetProgramDataPath(); - - Logger.LoggerInstance = new FileLogger(Path.Combine(ProgramDataPath, "Logs")); } public virtual void Init(IProgress progress) { + ReloadLogger(); + ReloadConfiguration(); ReloadHttpServer(); @@ -86,6 +102,24 @@ namespace MediaBrowser.Common.Kernel ReloadComposableParts(); } + private void ReloadLogger() + { + DisposeLogger(); + + if (!Directory.Exists(LogDirectoryPath)) + { + Directory.CreateDirectory(LogDirectoryPath); + } + + DateTime now = DateTime.Now; + + LogFilePath = Path.Combine(LogDirectoryPath, now.ToString("dMyyyy") + "-" + now.Ticks + ".log"); + + FileStream fs = new FileStream(LogFilePath, FileMode.Append, FileAccess.Write, FileShare.Read); + + Logger.LoggerInstance = new StreamLogger(fs); + } + /// /// Uses MEF to locate plugins /// Subclasses can use this to locate types within plugins @@ -213,14 +247,6 @@ namespace MediaBrowser.Common.Kernel HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/"); } - private void DisposeHttpServer() - { - if (HttpServer != null) - { - HttpServer.Dispose(); - } - } - /// /// This snippet will allow any plugin to reference another /// @@ -244,6 +270,23 @@ namespace MediaBrowser.Common.Kernel public void Dispose() { DisposeHttpServer(); + DisposeLogger(); + } + + private void DisposeHttpServer() + { + if (HttpServer != null) + { + HttpServer.Dispose(); + } + } + + private void DisposeLogger() + { + if (Logger.LoggerInstance != null) + { + Logger.LoggerInstance.Dispose(); + } } } } diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs deleted file mode 100644 index 51c6632d56..0000000000 --- a/MediaBrowser.Common/Logging/BaseLogger.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Diagnostics; -using System.Text; -using System.Threading; - -namespace MediaBrowser.Common.Logging -{ - public abstract class BaseLogger - { - public LogSeverity LogSeverity { get; set; } - - public void LogInfo(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Info, paramList); - } - - public void LogDebugInfo(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Debug, paramList); - } - - public void LogError(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Error, paramList); - } - - public void LogException(string message, Exception exception, params object[] paramList) - { - StringBuilder builder = new StringBuilder(); - - if (exception != null) - { - var trace = new StackTrace(exception, true); - builder.AppendFormat("Exception. Type={0} Msg={1} Src={2} Method={5} Line={6} Col={7}{4}StackTrace={4}{3}", - exception.GetType().FullName, - exception.Message, - exception.Source, - exception.StackTrace, - Environment.NewLine, - trace.GetFrame(0).GetMethod().Name, - trace.GetFrame(0).GetFileLineNumber(), - trace.GetFrame(0).GetFileColumnNumber()); - } - - StackFrame frame = new StackFrame(1); - - message = string.Format(message, paramList); - - LogError(string.Format("{0} ( {1} )", message, builder)); - } - - public void LogWarning(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Warning, paramList); - } - - private void LogEntry(string message, LogSeverity severity, params object[] paramList) - { - if (severity < LogSeverity) return; - - message = string.Format(message, paramList); - - Thread currentThread = Thread.CurrentThread; - - LogRow row = new LogRow() - { - Severity = severity, - Message = message, - Category = string.Empty, - ThreadId = currentThread.ManagedThreadId, - ThreadName = currentThread.Name, - Time = DateTime.Now - }; - - LogEntry(row); - } - - protected abstract void LogEntry(LogRow row); - } -} diff --git a/MediaBrowser.Common/Logging/FileLogger.cs b/MediaBrowser.Common/Logging/FileLogger.cs deleted file mode 100644 index 33c64b1391..0000000000 --- a/MediaBrowser.Common/Logging/FileLogger.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.IO; -using System.Text; - -namespace MediaBrowser.Common.Logging -{ - public class FileLogger : BaseLogger, IDisposable - { - private string LogDirectory { get; set; } - private string CurrentLogFile { get; set; } - - private FileStream FileStream { get; set; } - - public FileLogger(string logDirectory) - { - LogDirectory = logDirectory; - } - - private void EnsureStream() - { - if (FileStream == null) - { - if (!Directory.Exists(LogDirectory)) - { - Directory.CreateDirectory(LogDirectory); - } - - DateTime now = DateTime.Now; - - CurrentLogFile = Path.Combine(LogDirectory, now.ToString("dMyyyy") + "-" + now.Ticks + ".log"); - - FileStream = new FileStream(CurrentLogFile, FileMode.Append, FileAccess.Write, FileShare.Read); - } - } - - protected override void LogEntry(LogRow row) - { - EnsureStream(); - - byte[] bytes = new UTF8Encoding().GetBytes(row.ToString() + Environment.NewLine); - - FileStream.Write(bytes, 0, bytes.Length); - - FileStream.Flush(); - } - - public void Dispose() - { - if (FileStream != null) - { - FileStream.Dispose(); - } - } - } -} diff --git a/MediaBrowser.Common/Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs deleted file mode 100644 index 39c69eb454..0000000000 --- a/MediaBrowser.Common/Logging/LogRow.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace MediaBrowser.Common.Logging -{ - public struct LogRow - { - - const string TimePattern = "h:mm:ss.fff tt d/M/yyyy"; - - - public LogSeverity Severity { get; set; } - public string Message { get; set; } - public string Category { get; set; } - public int ThreadId { get; set; } - public string ThreadName { get; set; } - public DateTime Time { get; set; } - - public string ShortMessage - { - get - { - var message = Message; - if (message.Length > 120) - { - message = Message.Substring(0, 120).Replace(Environment.NewLine, " ") + " ... "; - } - return message; - } - } - - public string FullDescription - { - get - { - StringBuilder sb = new StringBuilder(); - sb.AppendFormat("Time: {0}", Time); - sb.AppendLine(); - sb.AppendFormat("Thread Id: {0} {1}", ThreadId, ThreadName); - sb.AppendLine(); - sb.AppendLine(Message); - return sb.ToString(); - } - } - - public override string ToString() - { - StringBuilder builder = new StringBuilder(); - builder.Append(Time.ToString(TimePattern)) - .Append(" , ") - .Append(Enum.GetName(typeof(LogSeverity), Severity)) - .Append(" , ") - .Append(Encode(Message)) - .Append(" , ") - .Append(Encode(Category)) - .Append(" , ") - .Append(ThreadId) - .Append(" , ") - .Append(Encode(ThreadName)); - return builder.ToString(); - } - - private string Encode(string str) - { - return (str ?? "").Replace(",", ",,").Replace(Environment.NewLine, " [n] "); - } - - public static LogRow FromString(string message) - { - var split = splitString(message); - return new LogRow() - { - Time = DateTime.ParseExact(split[0], TimePattern, null), - Severity = (LogSeverity)Enum.Parse(typeof(LogSeverity), split[1]), - Message = split[2], - Category = split[3], - ThreadId = int.Parse(split[4]), - ThreadName = split[5] - }; - } - - static string[] splitString(string message) - { - List items = new List(); - bool gotComma = false; - - StringBuilder currentItem = new StringBuilder(); - - foreach (var chr in message) - { - - if (chr == ',' && gotComma) - { - gotComma = false; - currentItem.Append(','); - } - else if (chr == ',') - { - gotComma = true; - } - else if (gotComma) - { - items.Add(currentItem.ToString().Replace(" [n] ", Environment.NewLine).Trim()); - currentItem = new StringBuilder(); - gotComma = false; - } - else - { - currentItem.Append(chr); - } - - } - items.Add(currentItem.ToString().Replace("[n]", Environment.NewLine).Trim()); - return items.ToArray(); - } - } -} diff --git a/MediaBrowser.Common/Logging/LogSeverity.cs b/MediaBrowser.Common/Logging/LogSeverity.cs deleted file mode 100644 index 2abab1a448..0000000000 --- a/MediaBrowser.Common/Logging/LogSeverity.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace MediaBrowser.Common.Logging -{ - [Flags] - public enum LogSeverity - { - None = 0, - Debug = 1, - Info = 2, - Warning = 4, - Error = 8 - } -} diff --git a/MediaBrowser.Common/Logging/Logger.cs b/MediaBrowser.Common/Logging/Logger.cs deleted file mode 100644 index d1ae9b8f35..0000000000 --- a/MediaBrowser.Common/Logging/Logger.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; - -namespace MediaBrowser.Common.Logging -{ - public static class Logger - { - public static BaseLogger LoggerInstance { get; set; } - - public static void LogInfo(string message, params object[] paramList) - { - LoggerInstance.LogInfo(message, paramList); - } - - public static void LogDebugInfo(string message, params object[] paramList) - { - LoggerInstance.LogDebugInfo(message, paramList); - } - - public static void LogError(string message, params object[] paramList) - { - LoggerInstance.LogError(message, paramList); - } - - public static void LogException(string message, Exception ex, params object[] paramList) - { - LoggerInstance.LogException(message, ex, paramList); - } - - public static void LogWarning(string message, params object[] paramList) - { - LoggerInstance.LogWarning(message, paramList); - } - } -} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 53a1c71215..bf9d17b78c 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -48,12 +48,10 @@ - - @@ -62,18 +60,17 @@ - - - - - + + {37032b77-fe2e-4ec5-b7e4-baf634443578} + MediaBrowser.Logging + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} MediaBrowser.Model diff --git a/MediaBrowser.Common/Progress/TaskProgress.cs b/MediaBrowser.Common/Progress/TaskProgress.cs deleted file mode 100644 index 78e817397a..0000000000 --- a/MediaBrowser.Common/Progress/TaskProgress.cs +++ /dev/null @@ -1,19 +0,0 @@ - -namespace MediaBrowser.Common.Progress -{ - /// - /// Represents a generic progress class that can be used with IProgress - /// - public class TaskProgress - { - /// - /// Gets or sets the current completion percentage - /// - public decimal PercentComplete { get; set; } - - /// - /// Gets or sets a description of the actions currently executing - /// - public string Description { get; set; } - } -} diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs index 56f3a854fa..e6f794595b 100644 --- a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using MediaBrowser.Common.Configuration; using MediaBrowser.Model.Configuration; namespace MediaBrowser.Controller.Configuration diff --git a/MediaBrowser.Logging/BaseLogger.cs b/MediaBrowser.Logging/BaseLogger.cs new file mode 100644 index 0000000000..d73b473930 --- /dev/null +++ b/MediaBrowser.Logging/BaseLogger.cs @@ -0,0 +1,76 @@ +using System; +using System.Text; +using System.Threading; + +namespace MediaBrowser.Logging +{ + public abstract class BaseLogger : IDisposable + { + public LogSeverity LogSeverity { get; set; } + + public void LogInfo(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Info, paramList); + } + + public void LogDebugInfo(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Debug, paramList); + } + + public void LogError(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Error, paramList); + } + + public void LogException(string message, Exception exception, params object[] paramList) + { + StringBuilder builder = new StringBuilder(); + + if (exception != null) + { + builder.AppendFormat("Exception. Type={0} Msg={1} StackTrace={3}{2}", + exception.GetType().FullName, + exception.Message, + exception.StackTrace, + Environment.NewLine); + } + + message = string.Format(message, paramList); + + LogError(string.Format("{0} ( {1} )", message, builder)); + } + + public void LogWarning(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Warning, paramList); + } + + private void LogEntry(string message, LogSeverity severity, params object[] paramList) + { + if (severity < LogSeverity) return; + + message = string.Format(message, paramList); + + Thread currentThread = Thread.CurrentThread; + + LogRow row = new LogRow() + { + Severity = severity, + Message = message, + Category = string.Empty, + ThreadId = currentThread.ManagedThreadId, + //ThreadName = currentThread.Name, + Time = DateTime.Now + }; + + LogEntry(row); + } + + public virtual void Dispose() + { + } + + protected abstract void LogEntry(LogRow row); + } +} diff --git a/MediaBrowser.Logging/LogRow.cs b/MediaBrowser.Logging/LogRow.cs new file mode 100644 index 0000000000..da699035a2 --- /dev/null +++ b/MediaBrowser.Logging/LogRow.cs @@ -0,0 +1,40 @@ +using System; +using System.Text; + +namespace MediaBrowser.Logging +{ + public struct LogRow + { + const string TimePattern = "h:mm:ss.fff tt d/M/yyyy"; + + public LogSeverity Severity { get; set; } + public string Message { get; set; } + public string Category { get; set; } + public int ThreadId { get; set; } + public string ThreadName { get; set; } + public DateTime Time { get; set; } + + public override string ToString() + { + StringBuilder builder = new StringBuilder(); + builder.Append(Time.ToString(TimePattern)) + .Append(" , ") + .Append(Enum.GetName(typeof(LogSeverity), Severity)) + .Append(" , ") + .Append(Encode(Message)) + .Append(" , ") + .Append(Encode(Category)) + .Append(" , ") + .Append(ThreadId) + .Append(" , ") + .Append(Encode(ThreadName)); + + return builder.ToString(); + } + + private string Encode(string str) + { + return (str ?? "").Replace(",", ",,").Replace(Environment.NewLine, " [n] "); + } + } +} diff --git a/MediaBrowser.Logging/LogSeverity.cs b/MediaBrowser.Logging/LogSeverity.cs new file mode 100644 index 0000000000..70c4f6304b --- /dev/null +++ b/MediaBrowser.Logging/LogSeverity.cs @@ -0,0 +1,14 @@ +using System; + +namespace MediaBrowser.Logging +{ + [Flags] + public enum LogSeverity + { + None = 0, + Debug = 1, + Info = 2, + Warning = 4, + Error = 8 + } +} diff --git a/MediaBrowser.Logging/Logger.cs b/MediaBrowser.Logging/Logger.cs new file mode 100644 index 0000000000..db46010a41 --- /dev/null +++ b/MediaBrowser.Logging/Logger.cs @@ -0,0 +1,34 @@ +using System; + +namespace MediaBrowser.Logging +{ + public static class Logger + { + public static BaseLogger LoggerInstance { get; set; } + + public static void LogInfo(string message, params object[] paramList) + { + LoggerInstance.LogInfo(message, paramList); + } + + public static void LogDebugInfo(string message, params object[] paramList) + { + LoggerInstance.LogDebugInfo(message, paramList); + } + + public static void LogError(string message, params object[] paramList) + { + LoggerInstance.LogError(message, paramList); + } + + public static void LogException(string message, Exception ex, params object[] paramList) + { + LoggerInstance.LogException(message, ex, paramList); + } + + public static void LogWarning(string message, params object[] paramList) + { + LoggerInstance.LogWarning(message, paramList); + } + } +} diff --git a/MediaBrowser.Logging/MediaBrowser.Logging.csproj b/MediaBrowser.Logging/MediaBrowser.Logging.csproj new file mode 100644 index 0000000000..39840f71fd --- /dev/null +++ b/MediaBrowser.Logging/MediaBrowser.Logging.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {37032B77-FE2E-4EC5-B7E4-BAF634443578} + Library + Properties + MediaBrowser.Logging + MediaBrowser.Logging + v4.0 + Profile95 + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MediaBrowser.Logging/Properties/AssemblyInfo.cs b/MediaBrowser.Logging/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..fa0d3817d2 --- /dev/null +++ b/MediaBrowser.Logging/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using System.Resources; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MediaBrowser.Logging")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MediaBrowser.Logging")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Logging/StreamLogger.cs b/MediaBrowser.Logging/StreamLogger.cs new file mode 100644 index 0000000000..f1a16c7ad1 --- /dev/null +++ b/MediaBrowser.Logging/StreamLogger.cs @@ -0,0 +1,32 @@ +using System; +using System.IO; +using System.Text; + +namespace MediaBrowser.Logging +{ + public class StreamLogger : BaseLogger + { + private Stream Stream { get; set; } + + public StreamLogger(Stream stream) + : base() + { + Stream = stream; + } + + protected override void LogEntry(LogRow row) + { + byte[] bytes = new UTF8Encoding().GetBytes(row.ToString() + Environment.NewLine); + + Stream.Write(bytes, 0, bytes.Length); + Stream.Flush(); + } + + public override void Dispose() + { + base.Dispose(); + + Stream.Dispose(); + } + } +} diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs new file mode 100644 index 0000000000..2511377c15 --- /dev/null +++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs @@ -0,0 +1,19 @@ +using MediaBrowser.Logging; + +namespace MediaBrowser.Model.Configuration +{ + /// + /// Serves as a common base class for the Server and UI application Configurations + /// + public class BaseApplicationConfiguration + { + public LogSeverity LogSeverity { get; set; } + public int HttpServerPortNumber { get; set; } + + public BaseApplicationConfiguration() + { + LogSeverity = LogSeverity.Info; + HttpServerPortNumber = 8096; + } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index ceb58163ab..9338b3884e 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -10,7 +10,7 @@ MediaBrowser.Model MediaBrowser.Model v4.0 - Profile4 + Profile95 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -33,8 +33,13 @@ + + {37032b77-fe2e-4ec5-b7e4-baf634443578} + MediaBrowser.Logging + + @@ -48,6 +53,7 @@ + diff --git a/MediaBrowser.Model/Progress/TaskProgress.cs b/MediaBrowser.Model/Progress/TaskProgress.cs new file mode 100644 index 0000000000..1bf135029b --- /dev/null +++ b/MediaBrowser.Model/Progress/TaskProgress.cs @@ -0,0 +1,19 @@ + +namespace MediaBrowser.Model.Progress +{ + /// + /// Represents a generic progress class that can be used with IProgress + /// + public class TaskProgress + { + /// + /// Gets or sets the current completion percentage + /// + public decimal PercentComplete { get; set; } + + /// + /// Gets or sets a description of the actions currently executing + /// + public string Description { get; set; } + } +} diff --git a/MediaBrowser.Program/Program.cs b/MediaBrowser.Program/Program.cs index a951ec7dba..fff4c9f16c 100644 --- a/MediaBrowser.Program/Program.cs +++ b/MediaBrowser.Program/Program.cs @@ -1,6 +1,6 @@ using System; using MediaBrowser.Controller; -using MediaBrowser.Common.Progress; +using MediaBrowser.Model.Progress; namespace MediaBrowser.Program { @@ -28,6 +28,8 @@ namespace MediaBrowser.Program Console.WriteLine("Press Enter to quit."); Console.ReadLine(); + + kernel.Dispose(); } } } diff --git a/MediaBrowser.sln b/MediaBrowser.sln index 6f94baf31d..bebbc61afd 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Common", "Medi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Model", "MediaBrowser.Model\MediaBrowser.Model.csproj", "{7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Logging", "MediaBrowser.Logging\MediaBrowser.Logging.csproj", "{37032B77-FE2E-4EC5-B7E4-BAF634443578}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,6 +37,10 @@ Global {32DFC600-CD2F-4B2D-B39A-3B4C6C32F9B4}.Debug|Any CPU.Build.0 = Debug|Any CPU {32DFC600-CD2F-4B2D-B39A-3B4C6C32F9B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {32DFC600-CD2F-4B2D-B39A-3B4C6C32F9B4}.Release|Any CPU.Build.0 = Release|Any CPU + {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Release|Any CPU.Build.0 = Release|Any CPU {4FD51AC5-2C16-4308-A993-C3A84F3B4582}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4FD51AC5-2C16-4308-A993-C3A84F3B4582}.Debug|Any CPU.Build.0 = Debug|Any CPU {4FD51AC5-2C16-4308-A993-C3A84F3B4582}.Release|Any CPU.ActiveCfg = Release|Any CPU -- cgit v1.2.3 From d4c75e39748679e7c039cb1eae4ad7232e2fe2b6 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Mon, 30 Jul 2012 23:38:00 -0400 Subject: Fixed some project fragmentation that came from efforts to go portable --- MediaBrowser.Api/HttpHandlers/JsonHandler.cs | 3 +- .../Configuration/BaseApplicationConfiguration.cs | 19 ++++++ MediaBrowser.Common/Json/JsonSerializer.cs | 14 +--- MediaBrowser.Common/Kernel/BaseKernel.cs | 16 +++-- MediaBrowser.Common/Logging/BaseLogger.cs | 76 ++++++++++++++++++++++ MediaBrowser.Common/Logging/LogRow.cs | 40 ++++++++++++ MediaBrowser.Common/Logging/LogSeverity.cs | 14 ++++ MediaBrowser.Common/Logging/Logger.cs | 34 ++++++++++ MediaBrowser.Common/Logging/StreamLogger.cs | 33 ++++++++++ MediaBrowser.Common/MediaBrowser.Common.csproj | 10 +-- MediaBrowser.Common/Plugins/BasePlugin.cs | 30 ++++----- .../Configuration/ServerConfiguration.cs | 1 + MediaBrowser.Controller/UserController.cs | 2 +- MediaBrowser.Controller/Xml/BaseItemXmlParser.cs | 4 +- MediaBrowser.Logging/BaseLogger.cs | 76 ---------------------- MediaBrowser.Logging/LogRow.cs | 40 ------------ MediaBrowser.Logging/LogSeverity.cs | 14 ---- MediaBrowser.Logging/Logger.cs | 34 ---------- MediaBrowser.Logging/MediaBrowser.Logging.csproj | 53 --------------- MediaBrowser.Logging/Properties/AssemblyInfo.cs | 30 --------- MediaBrowser.Logging/StreamLogger.cs | 35 ---------- .../Configuration/BaseApplicationConfiguration.cs | 19 ------ MediaBrowser.Model/Entities/BaseItem.cs | 2 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 10 +-- MediaBrowser.TV/Metadata/SeriesXmlParser.cs | 2 +- MediaBrowser.sln | 6 -- 26 files changed, 256 insertions(+), 361 deletions(-) create mode 100644 MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs create mode 100644 MediaBrowser.Common/Logging/BaseLogger.cs create mode 100644 MediaBrowser.Common/Logging/LogRow.cs create mode 100644 MediaBrowser.Common/Logging/LogSeverity.cs create mode 100644 MediaBrowser.Common/Logging/Logger.cs create mode 100644 MediaBrowser.Common/Logging/StreamLogger.cs delete mode 100644 MediaBrowser.Logging/BaseLogger.cs delete mode 100644 MediaBrowser.Logging/LogRow.cs delete mode 100644 MediaBrowser.Logging/LogSeverity.cs delete mode 100644 MediaBrowser.Logging/Logger.cs delete mode 100644 MediaBrowser.Logging/MediaBrowser.Logging.csproj delete mode 100644 MediaBrowser.Logging/Properties/AssemblyInfo.cs delete mode 100644 MediaBrowser.Logging/StreamLogger.cs delete mode 100644 MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/HttpHandlers/JsonHandler.cs b/MediaBrowser.Api/HttpHandlers/JsonHandler.cs index a891d7d68d..90502a0c5f 100644 --- a/MediaBrowser.Api/HttpHandlers/JsonHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/JsonHandler.cs @@ -1,6 +1,7 @@ using System.IO; -using MediaBrowser.Common.Json; using MediaBrowser.Common.Net.Handlers; +using MediaBrowser.Controller; +using MediaBrowser.Common.Json; namespace MediaBrowser.Api.HttpHandlers { diff --git a/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs new file mode 100644 index 0000000000..7ed782bdb1 --- /dev/null +++ b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs @@ -0,0 +1,19 @@ +using MediaBrowser.Common.Logging; + +namespace MediaBrowser.Common.Configuration +{ + /// + /// Serves as a common base class for the Server and UI application Configurations + /// + public class BaseApplicationConfiguration + { + public LogSeverity LogSeverity { get; set; } + public int HttpServerPortNumber { get; set; } + + public BaseApplicationConfiguration() + { + LogSeverity = LogSeverity.Info; + HttpServerPortNumber = 8096; + } + } +} diff --git a/MediaBrowser.Common/Json/JsonSerializer.cs b/MediaBrowser.Common/Json/JsonSerializer.cs index b7db1d9006..8e132c1528 100644 --- a/MediaBrowser.Common/Json/JsonSerializer.cs +++ b/MediaBrowser.Common/Json/JsonSerializer.cs @@ -7,15 +7,11 @@ namespace MediaBrowser.Common.Json { public static void SerializeToStream(T obj, Stream stream) { - Configure(); - ServiceStack.Text.JsonSerializer.SerializeToStream(obj, stream); } public static void SerializeToFile(T obj, string file) { - Configure(); - using (StreamWriter streamWriter = new StreamWriter(file)) { ServiceStack.Text.JsonSerializer.SerializeToWriter(obj, streamWriter); @@ -24,8 +20,6 @@ namespace MediaBrowser.Common.Json public static object DeserializeFromFile(Type type, string file) { - Configure(); - using (Stream stream = File.OpenRead(file)) { return ServiceStack.Text.JsonSerializer.DeserializeFromStream(type, stream); @@ -34,8 +28,6 @@ namespace MediaBrowser.Common.Json public static T DeserializeFromFile(string file) { - Configure(); - using (Stream stream = File.OpenRead(file)) { return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); @@ -44,19 +36,15 @@ namespace MediaBrowser.Common.Json public static T DeserializeFromStream(Stream stream) { - Configure(); - return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); } public static T DeserializeFromString(string data) { - Configure(); - return ServiceStack.Text.JsonSerializer.DeserializeFromString(data); } - private static void Configure() + public static void Configure() { ServiceStack.Text.JsConfig.ExcludeTypeInfo = true; ServiceStack.Text.JsConfig.IncludeNullValues = false; diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 820d94831a..0fdc1f8131 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -6,12 +6,12 @@ using System.Configuration; using System.IO; using System.Linq; using System.Reflection; -using MediaBrowser.Common.Json; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Logging; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; -using MediaBrowser.Logging; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Progress; +using MediaBrowser.Common.Json; namespace MediaBrowser.Common.Kernel { @@ -93,19 +93,21 @@ namespace MediaBrowser.Common.Kernel public virtual void Init(IProgress progress) { + JsonSerializer.Configure(); + ReloadLogger(); ReloadConfiguration(); ReloadHttpServer(); - + ReloadComposableParts(); } private void ReloadLogger() { DisposeLogger(); - + if (!Directory.Exists(LogDirectoryPath)) { Directory.CreateDirectory(LogDirectoryPath); @@ -115,8 +117,8 @@ namespace MediaBrowser.Common.Kernel LogFilePath = Path.Combine(LogDirectoryPath, now.ToString("dMyyyy") + "-" + now.Ticks + ".log"); - FileStream fs = new FileStream(LogFilePath, FileMode.Append, FileAccess.Write, FileShare.Read); - + FileStream fs = new FileStream(LogFilePath, FileMode.Append, FileAccess.Write, FileShare.Read); + Logger.LoggerInstance = new StreamLogger(fs); } diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs new file mode 100644 index 0000000000..04c3b80977 --- /dev/null +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -0,0 +1,76 @@ +using System; +using System.Text; +using System.Threading; + +namespace MediaBrowser.Common.Logging +{ + public abstract class BaseLogger : IDisposable + { + public LogSeverity LogSeverity { get; set; } + + public void LogInfo(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Info, paramList); + } + + public void LogDebugInfo(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Debug, paramList); + } + + public void LogError(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Error, paramList); + } + + public void LogException(string message, Exception exception, params object[] paramList) + { + StringBuilder builder = new StringBuilder(); + + if (exception != null) + { + builder.AppendFormat("Exception. Type={0} Msg={1} StackTrace={3}{2}", + exception.GetType().FullName, + exception.Message, + exception.StackTrace, + Environment.NewLine); + } + + message = string.Format(message, paramList); + + LogError(string.Format("{0} ( {1} )", message, builder)); + } + + public void LogWarning(string message, params object[] paramList) + { + LogEntry(message, LogSeverity.Warning, paramList); + } + + private void LogEntry(string message, LogSeverity severity, params object[] paramList) + { + if (severity < LogSeverity) return; + + message = string.Format(message, paramList); + + Thread currentThread = Thread.CurrentThread; + + LogRow row = new LogRow() + { + Severity = severity, + Message = message, + Category = string.Empty, + ThreadId = currentThread.ManagedThreadId, + //ThreadName = currentThread.Name, + Time = DateTime.Now + }; + + LogEntry(row); + } + + public virtual void Dispose() + { + } + + protected abstract void LogEntry(LogRow row); + } +} diff --git a/MediaBrowser.Common/Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs new file mode 100644 index 0000000000..fda7142632 --- /dev/null +++ b/MediaBrowser.Common/Logging/LogRow.cs @@ -0,0 +1,40 @@ +using System; +using System.Text; + +namespace MediaBrowser.Common.Logging +{ + public struct LogRow + { + const string TimePattern = "h:mm:ss.fff tt d/M/yyyy"; + + public LogSeverity Severity { get; set; } + public string Message { get; set; } + public string Category { get; set; } + public int ThreadId { get; set; } + public string ThreadName { get; set; } + public DateTime Time { get; set; } + + public override string ToString() + { + StringBuilder builder = new StringBuilder(); + builder.Append(Time.ToString(TimePattern)) + .Append(" , ") + .Append(Enum.GetName(typeof(LogSeverity), Severity)) + .Append(" , ") + .Append(Encode(Message)) + .Append(" , ") + .Append(Encode(Category)) + .Append(" , ") + .Append(ThreadId) + .Append(" , ") + .Append(Encode(ThreadName)); + + return builder.ToString(); + } + + private string Encode(string str) + { + return (str ?? "").Replace(",", ",,").Replace(Environment.NewLine, " [n] "); + } + } +} diff --git a/MediaBrowser.Common/Logging/LogSeverity.cs b/MediaBrowser.Common/Logging/LogSeverity.cs new file mode 100644 index 0000000000..2abab1a448 --- /dev/null +++ b/MediaBrowser.Common/Logging/LogSeverity.cs @@ -0,0 +1,14 @@ +using System; + +namespace MediaBrowser.Common.Logging +{ + [Flags] + public enum LogSeverity + { + None = 0, + Debug = 1, + Info = 2, + Warning = 4, + Error = 8 + } +} diff --git a/MediaBrowser.Common/Logging/Logger.cs b/MediaBrowser.Common/Logging/Logger.cs new file mode 100644 index 0000000000..d1ae9b8f35 --- /dev/null +++ b/MediaBrowser.Common/Logging/Logger.cs @@ -0,0 +1,34 @@ +using System; + +namespace MediaBrowser.Common.Logging +{ + public static class Logger + { + public static BaseLogger LoggerInstance { get; set; } + + public static void LogInfo(string message, params object[] paramList) + { + LoggerInstance.LogInfo(message, paramList); + } + + public static void LogDebugInfo(string message, params object[] paramList) + { + LoggerInstance.LogDebugInfo(message, paramList); + } + + public static void LogError(string message, params object[] paramList) + { + LoggerInstance.LogError(message, paramList); + } + + public static void LogException(string message, Exception ex, params object[] paramList) + { + LoggerInstance.LogException(message, ex, paramList); + } + + public static void LogWarning(string message, params object[] paramList) + { + LoggerInstance.LogWarning(message, paramList); + } + } +} diff --git a/MediaBrowser.Common/Logging/StreamLogger.cs b/MediaBrowser.Common/Logging/StreamLogger.cs new file mode 100644 index 0000000000..058c7e69c5 --- /dev/null +++ b/MediaBrowser.Common/Logging/StreamLogger.cs @@ -0,0 +1,33 @@ +using System; +using System.IO; +using System.Text; + +namespace MediaBrowser.Common.Logging +{ + /// + /// Provides a Logger that can write to any Stream + /// + public class StreamLogger : BaseLogger + { + private Stream Stream { get; set; } + + public StreamLogger(Stream stream) + : base() + { + Stream = stream; + } + + protected override void LogEntry(LogRow row) + { + byte[] bytes = new UTF8Encoding().GetBytes(row.ToString() + Environment.NewLine); + Stream.Write(bytes, 0, bytes.Length); + Stream.Flush(); + } + + public override void Dispose() + { + base.Dispose(); + Stream.Dispose(); + } + } +} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index bf9d17b78c..8c8146cdcb 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -48,10 +48,16 @@ + + + + + + @@ -67,10 +73,6 @@ - - {37032b77-fe2e-4ec5-b7e4-baf634443578} - MediaBrowser.Logging - {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} MediaBrowser.Model diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 61ecffc758..98b6120f7e 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -1,8 +1,8 @@ using System; using System.IO; -using MediaBrowser.Common.Json; -using MediaBrowser.Model.Plugins; using MediaBrowser.Common.Kernel; +using MediaBrowser.Model.Plugins; +using MediaBrowser.Common.Json; namespace MediaBrowser.Common.Plugins { @@ -100,19 +100,6 @@ namespace MediaBrowser.Common.Plugins } } - public void ReloadConfiguration() - { - if (!File.Exists(ConfigurationPath)) - { - Configuration = Activator.CreateInstance(ConfigurationType) as BasePluginConfiguration; - } - else - { - Configuration = JsonSerializer.DeserializeFromFile(ConfigurationType, ConfigurationPath) as BasePluginConfiguration; - Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationPath); - } - } - /// /// Starts the plugin. /// @@ -126,5 +113,18 @@ namespace MediaBrowser.Common.Plugins public virtual void Dispose() { } + + public void ReloadConfiguration() + { + if (!File.Exists(ConfigurationPath)) + { + Configuration = Activator.CreateInstance(ConfigurationType) as BasePluginConfiguration; + } + else + { + Configuration = JsonSerializer.DeserializeFromFile(ConfigurationType, ConfigurationPath) as BasePluginConfiguration; + Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationPath); + } + } } } diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs index e6f794595b..56f3a854fa 100644 --- a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using MediaBrowser.Common.Configuration; using MediaBrowser.Model.Configuration; namespace MediaBrowser.Controller.Configuration diff --git a/MediaBrowser.Controller/UserController.cs b/MediaBrowser.Controller/UserController.cs index 7fac4392e4..c53397a31b 100644 --- a/MediaBrowser.Controller/UserController.cs +++ b/MediaBrowser.Controller/UserController.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.IO; -using MediaBrowser.Common.Json; using MediaBrowser.Model.Users; +using MediaBrowser.Common.Json; namespace MediaBrowser.Controller { diff --git a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs index ed8afd5a70..d3a7c3bd74 100644 --- a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs @@ -384,14 +384,14 @@ namespace MediaBrowser.Controller.Xml break; case "Duration": - item.RunTimeInSeconds = reader.ReadIntSafe() * 60; + item.RunTimeInMilliseconds = reader.ReadIntSafe() * 60000; break; case "DurationSeconds": int seconds = reader.ReadIntSafe(); if (seconds > 0) { - item.RunTimeInSeconds = seconds; + item.RunTimeInMilliseconds = seconds * 1000; } break; diff --git a/MediaBrowser.Logging/BaseLogger.cs b/MediaBrowser.Logging/BaseLogger.cs deleted file mode 100644 index d73b473930..0000000000 --- a/MediaBrowser.Logging/BaseLogger.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Text; -using System.Threading; - -namespace MediaBrowser.Logging -{ - public abstract class BaseLogger : IDisposable - { - public LogSeverity LogSeverity { get; set; } - - public void LogInfo(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Info, paramList); - } - - public void LogDebugInfo(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Debug, paramList); - } - - public void LogError(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Error, paramList); - } - - public void LogException(string message, Exception exception, params object[] paramList) - { - StringBuilder builder = new StringBuilder(); - - if (exception != null) - { - builder.AppendFormat("Exception. Type={0} Msg={1} StackTrace={3}{2}", - exception.GetType().FullName, - exception.Message, - exception.StackTrace, - Environment.NewLine); - } - - message = string.Format(message, paramList); - - LogError(string.Format("{0} ( {1} )", message, builder)); - } - - public void LogWarning(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Warning, paramList); - } - - private void LogEntry(string message, LogSeverity severity, params object[] paramList) - { - if (severity < LogSeverity) return; - - message = string.Format(message, paramList); - - Thread currentThread = Thread.CurrentThread; - - LogRow row = new LogRow() - { - Severity = severity, - Message = message, - Category = string.Empty, - ThreadId = currentThread.ManagedThreadId, - //ThreadName = currentThread.Name, - Time = DateTime.Now - }; - - LogEntry(row); - } - - public virtual void Dispose() - { - } - - protected abstract void LogEntry(LogRow row); - } -} diff --git a/MediaBrowser.Logging/LogRow.cs b/MediaBrowser.Logging/LogRow.cs deleted file mode 100644 index da699035a2..0000000000 --- a/MediaBrowser.Logging/LogRow.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Text; - -namespace MediaBrowser.Logging -{ - public struct LogRow - { - const string TimePattern = "h:mm:ss.fff tt d/M/yyyy"; - - public LogSeverity Severity { get; set; } - public string Message { get; set; } - public string Category { get; set; } - public int ThreadId { get; set; } - public string ThreadName { get; set; } - public DateTime Time { get; set; } - - public override string ToString() - { - StringBuilder builder = new StringBuilder(); - builder.Append(Time.ToString(TimePattern)) - .Append(" , ") - .Append(Enum.GetName(typeof(LogSeverity), Severity)) - .Append(" , ") - .Append(Encode(Message)) - .Append(" , ") - .Append(Encode(Category)) - .Append(" , ") - .Append(ThreadId) - .Append(" , ") - .Append(Encode(ThreadName)); - - return builder.ToString(); - } - - private string Encode(string str) - { - return (str ?? "").Replace(",", ",,").Replace(Environment.NewLine, " [n] "); - } - } -} diff --git a/MediaBrowser.Logging/LogSeverity.cs b/MediaBrowser.Logging/LogSeverity.cs deleted file mode 100644 index 70c4f6304b..0000000000 --- a/MediaBrowser.Logging/LogSeverity.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace MediaBrowser.Logging -{ - [Flags] - public enum LogSeverity - { - None = 0, - Debug = 1, - Info = 2, - Warning = 4, - Error = 8 - } -} diff --git a/MediaBrowser.Logging/Logger.cs b/MediaBrowser.Logging/Logger.cs deleted file mode 100644 index db46010a41..0000000000 --- a/MediaBrowser.Logging/Logger.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; - -namespace MediaBrowser.Logging -{ - public static class Logger - { - public static BaseLogger LoggerInstance { get; set; } - - public static void LogInfo(string message, params object[] paramList) - { - LoggerInstance.LogInfo(message, paramList); - } - - public static void LogDebugInfo(string message, params object[] paramList) - { - LoggerInstance.LogDebugInfo(message, paramList); - } - - public static void LogError(string message, params object[] paramList) - { - LoggerInstance.LogError(message, paramList); - } - - public static void LogException(string message, Exception ex, params object[] paramList) - { - LoggerInstance.LogException(message, ex, paramList); - } - - public static void LogWarning(string message, params object[] paramList) - { - LoggerInstance.LogWarning(message, paramList); - } - } -} diff --git a/MediaBrowser.Logging/MediaBrowser.Logging.csproj b/MediaBrowser.Logging/MediaBrowser.Logging.csproj deleted file mode 100644 index 39840f71fd..0000000000 --- a/MediaBrowser.Logging/MediaBrowser.Logging.csproj +++ /dev/null @@ -1,53 +0,0 @@ - - - - - Debug - AnyCPU - {37032B77-FE2E-4EC5-B7E4-BAF634443578} - Library - Properties - MediaBrowser.Logging - MediaBrowser.Logging - v4.0 - Profile95 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MediaBrowser.Logging/Properties/AssemblyInfo.cs b/MediaBrowser.Logging/Properties/AssemblyInfo.cs deleted file mode 100644 index fa0d3817d2..0000000000 --- a/MediaBrowser.Logging/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MediaBrowser.Logging")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.Logging")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Logging/StreamLogger.cs b/MediaBrowser.Logging/StreamLogger.cs deleted file mode 100644 index c4ad7b80f6..0000000000 --- a/MediaBrowser.Logging/StreamLogger.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.IO; -using System.Text; - -namespace MediaBrowser.Logging -{ - /// - /// Provides a Logger that can write to any Stream - /// - public class StreamLogger : BaseLogger - { - private Stream Stream { get; set; } - - public StreamLogger(Stream stream) - : base() - { - Stream = stream; - } - - protected override void LogEntry(LogRow row) - { - byte[] bytes = new UTF8Encoding().GetBytes(row.ToString() + Environment.NewLine); - - Stream.Write(bytes, 0, bytes.Length); - Stream.Flush(); - } - - public override void Dispose() - { - base.Dispose(); - - Stream.Dispose(); - } - } -} diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs deleted file mode 100644 index 2511377c15..0000000000 --- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs +++ /dev/null @@ -1,19 +0,0 @@ -using MediaBrowser.Logging; - -namespace MediaBrowser.Model.Configuration -{ - /// - /// Serves as a common base class for the Server and UI application Configurations - /// - public class BaseApplicationConfiguration - { - public LogSeverity LogSeverity { get; set; } - public int HttpServerPortNumber { get; set; } - - public BaseApplicationConfiguration() - { - LogSeverity = LogSeverity.Info; - HttpServerPortNumber = 8096; - } - } -} diff --git a/MediaBrowser.Model/Entities/BaseItem.cs b/MediaBrowser.Model/Entities/BaseItem.cs index 8a1ded03b9..6f346a1dd5 100644 --- a/MediaBrowser.Model/Entities/BaseItem.cs +++ b/MediaBrowser.Model/Entities/BaseItem.cs @@ -51,7 +51,7 @@ namespace MediaBrowser.Model.Entities public string DisplayMediaType { get; set; } public float? UserRating { get; set; } - public int? RunTimeInSeconds { get; set; } + public int? RunTimeInMilliseconds { get; set; } public string AspectRatio { get; set; } public int? ProductionYear { get; set; } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 0157fcbf85..9485692d4b 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -10,7 +10,7 @@ MediaBrowser.Model MediaBrowser.Model v4.0 - Profile95 + Profile4 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -32,14 +32,6 @@ 4 - - - {37032b77-fe2e-4ec5-b7e4-baf634443578} - MediaBrowser.Logging - - - - diff --git a/MediaBrowser.TV/Metadata/SeriesXmlParser.cs b/MediaBrowser.TV/Metadata/SeriesXmlParser.cs index d36e7ff4be..ecee288cc8 100644 --- a/MediaBrowser.TV/Metadata/SeriesXmlParser.cs +++ b/MediaBrowser.TV/Metadata/SeriesXmlParser.cs @@ -66,7 +66,7 @@ namespace MediaBrowser.TV.Metadata int runtime; if (int.TryParse(text.Split(' ')[0], out runtime)) { - item.RunTimeInSeconds = runtime * 60; + item.RunTimeInMilliseconds = runtime * 60000; } } break; diff --git a/MediaBrowser.sln b/MediaBrowser.sln index bebbc61afd..6f94baf31d 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -21,8 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Common", "Medi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Model", "MediaBrowser.Model\MediaBrowser.Model.csproj", "{7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Logging", "MediaBrowser.Logging\MediaBrowser.Logging.csproj", "{37032B77-FE2E-4EC5-B7E4-BAF634443578}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,10 +35,6 @@ Global {32DFC600-CD2F-4B2D-B39A-3B4C6C32F9B4}.Debug|Any CPU.Build.0 = Debug|Any CPU {32DFC600-CD2F-4B2D-B39A-3B4C6C32F9B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {32DFC600-CD2F-4B2D-B39A-3B4C6C32F9B4}.Release|Any CPU.Build.0 = Release|Any CPU - {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Release|Any CPU.ActiveCfg = Release|Any CPU - {37032B77-FE2E-4EC5-B7E4-BAF634443578}.Release|Any CPU.Build.0 = Release|Any CPU {4FD51AC5-2C16-4308-A993-C3A84F3B4582}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4FD51AC5-2C16-4308-A993-C3A84F3B4582}.Debug|Any CPU.Build.0 = Debug|Any CPU {4FD51AC5-2C16-4308-A993-C3A84F3B4582}.Release|Any CPU.ActiveCfg = Release|Any CPU -- cgit v1.2.3 From 5c6ec34a9cff0819957fe5e4278f6e0d1ecc1fa3 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Fri, 17 Aug 2012 12:47:35 -0400 Subject: Consolidated handlers that return lists of items. Renamed ApiBaseItemWrapper to ApiBaseItemContainer. Added Person and Studio DTO's to BaseItemWrapper --- MediaBrowser.Api/ApiService.cs | 44 ++++++++++++++-- MediaBrowser.Api/HttpHandlers/GenresHandler.cs | 4 +- .../HttpHandlers/InProgressItemsHandler.cs | 19 ------- MediaBrowser.Api/HttpHandlers/ItemHandler.cs | 4 +- MediaBrowser.Api/HttpHandlers/ItemListHandler.cs | 59 ++++++++++++++++++++-- .../HttpHandlers/ItemsWithGenreHandler.cs | 22 -------- .../HttpHandlers/ItemsWithPersonHandler.cs | 32 ------------ .../HttpHandlers/ItemsWithStudioHandler.cs | 22 -------- .../HttpHandlers/ItemsWithYearHandler.cs | 22 -------- .../HttpHandlers/RecentlyAddedItemsHandler.cs | 24 --------- MediaBrowser.Api/HttpHandlers/StudiosHandler.cs | 4 +- .../HttpHandlers/UserConfigurationHandler.cs | 17 ------- MediaBrowser.Api/HttpHandlers/YearsHandler.cs | 4 +- MediaBrowser.Api/MediaBrowser.Api.csproj | 7 --- MediaBrowser.Api/Plugin.cs | 28 +--------- MediaBrowser.ApiInteraction/ApiClient.cs | 58 ++++++++------------- .../Configuration/ServerConfiguration.cs | 27 ---------- MediaBrowser.Controller/Kernel.cs | 34 +++++-------- .../Configuration/UserConfiguration.cs | 16 ------ MediaBrowser.Model/DTO/ApiBaseItem.cs | 13 ++--- MediaBrowser.Model/DTO/CategoryInfo.cs | 19 ------- MediaBrowser.Model/DTO/IBNItem.cs | 38 ++++++++++++++ MediaBrowser.Model/Entities/Person.cs | 1 - MediaBrowser.Model/MediaBrowser.Model.csproj | 3 +- MediaBrowser.Model/Users/User.cs | 7 +++ 25 files changed, 195 insertions(+), 333 deletions(-) delete mode 100644 MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs delete mode 100644 MediaBrowser.Model/Configuration/UserConfiguration.cs delete mode 100644 MediaBrowser.Model/DTO/CategoryInfo.cs create mode 100644 MediaBrowser.Model/DTO/IBNItem.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs index e4a7f71bf5..25a7ff9ec1 100644 --- a/MediaBrowser.Api/ApiService.cs +++ b/MediaBrowser.Api/ApiService.cs @@ -24,9 +24,9 @@ namespace MediaBrowser.Api /// /// Takes a BaseItem and returns the actual object that will be serialized by the api /// - public static BaseItemWrapper GetSerializationObject(BaseItem item, bool includeChildren, Guid userId) + public static BaseItemContainer GetSerializationObject(BaseItem item, bool includeChildren, Guid userId) { - BaseItemWrapper wrapper = new BaseItemWrapper() + BaseItemContainer wrapper = new BaseItemContainer() { Item = item, UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id), @@ -60,7 +60,45 @@ namespace MediaBrowser.Api wrapper.Children = Kernel.Instance.GetParentalAllowedChildren(folder, userId).Select(c => GetSerializationObject(c, false, userId)); } - wrapper.People = item.People; + // Attach People by transforming them into BaseItemPerson (DTO) + if (item.People != null) + { + wrapper.People = item.People.Select(p => + { + BaseItemPerson baseItemPerson = new BaseItemPerson(); + + baseItemPerson.PersonInfo = p; + + Person ibnObject = Kernel.Instance.ItemController.GetPerson(p.Name); + + if (ibnObject != null) + { + baseItemPerson.PrimaryImagePath = ibnObject.PrimaryImagePath; + } + + return baseItemPerson; + }); + } + } + + // Attach Studios by transforming them into BaseItemStudio (DTO) + if (item.Studios != null) + { + wrapper.Studios = item.Studios.Select(s => + { + BaseItemStudio baseItemStudio = new BaseItemStudio(); + + baseItemStudio.Name = s; + + Studio ibnObject = Kernel.Instance.ItemController.GetStudio(s); + + if (ibnObject != null) + { + baseItemStudio.PrimaryImagePath = ibnObject.PrimaryImagePath; + } + + return baseItemStudio; + }); } return wrapper; diff --git a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs index c3292d3633..902871fa11 100644 --- a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs @@ -7,9 +7,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class GenresHandler : BaseJsonHandler>> + public class GenresHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs b/MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs deleted file mode 100644 index 2bee275a45..0000000000 --- a/MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - class InProgressItemsHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetInProgressItems(parent, UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs index efb67db54e..3df8e914fb 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs @@ -5,9 +5,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class ItemHandler : BaseJsonHandler> + public class ItemHandler : BaseJsonHandler> { - protected sealed override BaseItemWrapper GetObjectToSerialize() + protected sealed override BaseItemContainer GetObjectToSerialize() { Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs index 6e08561b23..b3d85687fe 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs @@ -2,14 +2,15 @@ using System.Collections.Generic; using System.Linq; using MediaBrowser.Common.Net.Handlers; +using MediaBrowser.Controller; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public abstract class ItemListHandler : BaseJsonHandler>> + public class ItemListHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { return ItemsToSerialize.Select(i => { @@ -18,9 +19,51 @@ namespace MediaBrowser.Api.HttpHandlers }); } - protected abstract IEnumerable ItemsToSerialize + protected IEnumerable ItemsToSerialize { - get; + get + { + Folder parent = ApiService.GetItemById(ItemId) as Folder; + + if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetInProgressItems(parent, UserId); + } + else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetRecentlyAddedItems(parent, UserId); + } + else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetRecentlyAddedUnplayedItems(parent, UserId); + } + else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithGenre(parent, QueryString["name"], UserId); + } + else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithYear(parent, int.Parse(QueryString["year"]), UserId); + } + else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithStudio(parent, QueryString["name"], UserId); + } + else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithPerson(parent, QueryString["name"], UserId); + } + + throw new InvalidOperationException(); + } + } + + protected string ItemId + { + get + { + return QueryString["id"]; + } } protected Guid UserId @@ -30,5 +73,13 @@ namespace MediaBrowser.Api.HttpHandlers return Guid.Parse(QueryString["userid"]); } } + + private string ListType + { + get + { + return QueryString["listtype"] ?? string.Empty; + } + } } } diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs deleted file mode 100644 index 16bb561967..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within a Genre - /// - public class ItemsWithGenreHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetItemsWithGenre(parent, QueryString["name"], UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs deleted file mode 100644 index 624abc7620..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within containing a person - /// - public class ItemsWithPersonHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - PersonType? personType = null; - - string type = QueryString["persontype"]; - - if (!string.IsNullOrEmpty(type)) - { - personType = (PersonType)Enum.Parse(typeof(PersonType), type, true); - } - - return Kernel.Instance.GetItemsWithPerson(parent, QueryString["name"], personType, UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs deleted file mode 100644 index 30120d5248..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within containing a studio - /// - public class ItemsWithStudioHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetItemsWithStudio(parent, QueryString["name"], UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs deleted file mode 100644 index d5d4df4446..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within containing a studio - /// - public class ItemsWithYearHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetItemsWithYear(parent, int.Parse(QueryString["name"]), UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs b/MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs deleted file mode 100644 index f36c9c9975..0000000000 --- a/MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - class RecentlyAddedItemsHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - if (QueryString["unplayed"] == "1") - { - return Kernel.Instance.GetRecentlyAddedUnplayedItems(parent, UserId); - } - - return Kernel.Instance.GetRecentlyAddedItems(parent, UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs index b1be2cad2a..b33988b3ec 100644 --- a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs @@ -7,9 +7,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class StudiosHandler : BaseJsonHandler>> + public class StudiosHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs deleted file mode 100644 index 12e80f3060..0000000000 --- a/MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using MediaBrowser.Common.Net.Handlers; -using MediaBrowser.Controller; -using MediaBrowser.Model.Configuration; - -namespace MediaBrowser.Api.HttpHandlers -{ - public class UserConfigurationHandler : BaseJsonHandler - { - protected override UserConfiguration GetObjectToSerialize() - { - Guid userId = Guid.Parse(QueryString["userid"]); - - return Kernel.Instance.GetUserConfiguration(userId); - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs index cc34748805..8a58a2a19d 100644 --- a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs @@ -7,9 +7,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class YearsHandler : BaseJsonHandler>> + public class YearsHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index e6a1816f6d..4b6b6aa1a2 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -49,23 +49,16 @@ - - - - - - - diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index 6bfdd5134a..659763c5fc 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -49,46 +49,22 @@ namespace MediaBrowser.Api { return new UsersHandler(); } - else if (localPath.EndsWith("/api/itemswithgenre", StringComparison.OrdinalIgnoreCase)) + else if (localPath.EndsWith("/api/itemlist", StringComparison.OrdinalIgnoreCase)) { - return new ItemsWithGenreHandler(); + return new ItemListHandler(); } else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase)) { return new GenresHandler(); } - else if (localPath.EndsWith("/api/itemswithyear", StringComparison.OrdinalIgnoreCase)) - { - return new ItemsWithYearHandler(); - } - else if (localPath.EndsWith("/api/itemswithperson", StringComparison.OrdinalIgnoreCase)) - { - return new ItemsWithPersonHandler(); - } else if (localPath.EndsWith("/api/years", StringComparison.OrdinalIgnoreCase)) { return new YearsHandler(); } - else if (localPath.EndsWith("/api/itemswithstudio", StringComparison.OrdinalIgnoreCase)) - { - return new ItemsWithStudioHandler(); - } else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase)) { return new StudiosHandler(); } - else if (localPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase)) - { - return new RecentlyAddedItemsHandler(); - } - else if (localPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase)) - { - return new InProgressItemsHandler(); - } - else if (localPath.EndsWith("/api/userconfiguration", StringComparison.OrdinalIgnoreCase)) - { - return new UserConfigurationHandler(); - } else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase)) { return new PluginsHandler(); diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs index 7818dbdf8b..af79513e09 100644 --- a/MediaBrowser.ApiInteraction/ApiClient.cs +++ b/MediaBrowser.ApiInteraction/ApiClient.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Users; @@ -91,7 +90,7 @@ namespace MediaBrowser.ApiInteraction /// Use if a max width is required. Aspect ratio will be preserved. /// Use if a max height is required. Aspect ratio will be preserved. /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. - public IEnumerable GetBackdropImageUrls(BaseItemWrapper itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + public IEnumerable GetBackdropImageUrls(ApiBaseItemContainer itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) { Guid? backdropItemId = null; int backdropCount = 0; @@ -131,7 +130,7 @@ namespace MediaBrowser.ApiInteraction /// Use if a max width is required. Aspect ratio will be preserved. /// Use if a max height is required. Aspect ratio will be preserved. /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. - public string GetLogoImageUrl(BaseItemWrapper itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + public string GetLogoImageUrl(ApiBaseItemContainer itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) { Guid? logoItemId = !string.IsNullOrEmpty(itemWrapper.Item.LogoImagePath) ? itemWrapper.Item.Id : itemWrapper.ParentLogoItemId; @@ -154,7 +153,7 @@ namespace MediaBrowser.ApiInteraction /// /// Gets a BaseItem /// - public async Task> GetItemAsync(Guid id, Guid userId) + public async Task GetItemAsync(Guid id, Guid userId) { string url = ApiUrl + "/item?userId=" + userId.ToString(); @@ -165,7 +164,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>(stream); + return JsonSerializer.DeserializeFromStream(stream); } } @@ -185,61 +184,61 @@ namespace MediaBrowser.ApiInteraction /// /// Gets all Genres /// - public async Task>> GetAllGenresAsync(Guid userId) + public async Task>> GetAllGenresAsync(Guid userId) { string url = ApiUrl + "/genres?userId=" + userId.ToString(); using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>>(stream); } } /// /// Gets all Years /// - public async Task>> GetAllYearsAsync(Guid userId) + public async Task>> GetAllYearsAsync(Guid userId) { string url = ApiUrl + "/years?userId=" + userId.ToString(); using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>>(stream); } } /// /// Gets all items that contain a given Year /// - public async Task>> GetItemsWithYearAsync(string name, Guid userId) + public async Task> GetItemsWithYearAsync(string name, Guid userId) { - string url = ApiUrl + "/itemswithyear?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithyear&userId=" + userId.ToString() + "&name=" + name; using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } /// /// Gets all items that contain a given Genre /// - public async Task>> GetItemsWithGenreAsync(string name, Guid userId) + public async Task> GetItemsWithGenreAsync(string name, Guid userId) { - string url = ApiUrl + "/itemswithgenre?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithgenre&userId=" + userId.ToString() + "&name=" + name; using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } /// /// Gets all items that contain a given Person /// - public async Task>> GetItemsWithPersonAsync(string name, PersonType? personType, Guid userId) + public async Task> GetItemsWithPersonAsync(string name, PersonType? personType, Guid userId) { - string url = ApiUrl + "/itemswithperson?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithperson&userId=" + userId.ToString() + "&name=" + name; if (personType.HasValue) { @@ -248,46 +247,33 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } /// /// Gets all studious /// - public async Task>> GetAllStudiosAsync(Guid userId) + public async Task>> GetAllStudiosAsync(Guid userId) { string url = ApiUrl + "/studios?userId=" + userId.ToString(); using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); - } - } - - /// - /// Gets the current personalized configuration - /// - public async Task GetUserConfigurationAsync(Guid userId) - { - string url = ApiUrl + "/userconfiguration?userId=" + userId.ToString(); - - using (Stream stream = await HttpClient.GetStreamAsync(url)) - { - return JsonSerializer.DeserializeFromStream(stream); + return JsonSerializer.DeserializeFromStream>>(stream); } } /// /// Gets all items that contain a given Studio /// - public async Task>> GetItemsWithStudioAsync(string name, Guid userId) + public async Task> GetItemsWithStudioAsync(string name, Guid userId) { - string url = ApiUrl + "/itemswithstudio?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithstudio&userId=" + userId.ToString() + "&name=" + name; using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs index 56f3a854fa..88d1012b18 100644 --- a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs @@ -1,37 +1,10 @@ using System.Collections.Generic; using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Configuration; namespace MediaBrowser.Controller.Configuration { public class ServerConfiguration : BaseApplicationConfiguration { public string ImagesByNamePath { get; set; } - - /// - /// Gets or sets the default UI configuration - /// - public UserConfiguration DefaultUserConfiguration { get; set; } - - /// - /// Gets or sets a list of registered UI device names - /// - public List DeviceNames { get; set; } - - /// - /// Gets or sets all available UIConfigurations - /// The key contains device name and user id - /// - public Dictionary UserConfigurations { get; set; } - - public ServerConfiguration() - : base() - { - DefaultUserConfiguration = new UserConfiguration(); - - UserConfigurations = new Dictionary(); - - DeviceNames = new List(); - } } } diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index ef9a07814b..375b11a593 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -12,7 +12,6 @@ using MediaBrowser.Controller.Events; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Progress; @@ -155,11 +154,6 @@ namespace MediaBrowser.Controller } } - public UserConfiguration GetUserConfiguration(Guid userId) - { - return Configuration.DefaultUserConfiguration; - } - public void ReloadItem(BaseItem item) { Folder folder = item as Folder; @@ -263,9 +257,9 @@ namespace MediaBrowser.Controller { DateTime now = DateTime.Now; - UserConfiguration config = GetUserConfiguration(userId); + User user = Users.First(u => u.Id == userId); - return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < config.RecentItemDays); + return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < user.RecentItemDays); } /// @@ -358,7 +352,7 @@ namespace MediaBrowser.Controller /// Gets all years from all recursive children of a folder /// The CategoryInfo class is used to keep track of the number of times each year appears /// - public IEnumerable> GetAllYears(Folder parent, Guid userId) + public IEnumerable> GetAllYears(Folder parent, Guid userId) { Dictionary data = new Dictionary(); @@ -385,7 +379,7 @@ namespace MediaBrowser.Controller } // Now go through the dictionary and create a Category for each studio - List> list = new List>(); + List> list = new List>(); foreach (int key in data.Keys) { @@ -394,10 +388,10 @@ namespace MediaBrowser.Controller if (entity != null) { - list.Add(new CategoryInfo() + list.Add(new IBNItem() { Item = entity, - ItemCount = data[key] + BaseItemCount = data[key] }); } } @@ -409,7 +403,7 @@ namespace MediaBrowser.Controller /// Gets all studios from all recursive children of a folder /// The CategoryInfo class is used to keep track of the number of times each studio appears /// - public IEnumerable> GetAllStudios(Folder parent, Guid userId) + public IEnumerable> GetAllStudios(Folder parent, Guid userId) { Dictionary data = new Dictionary(); @@ -439,7 +433,7 @@ namespace MediaBrowser.Controller } // Now go through the dictionary and create a Category for each studio - List> list = new List>(); + List> list = new List>(); foreach (string key in data.Keys) { @@ -448,10 +442,10 @@ namespace MediaBrowser.Controller if (entity != null) { - list.Add(new CategoryInfo() + list.Add(new IBNItem() { Item = entity, - ItemCount = data[key] + BaseItemCount = data[key] }); } } @@ -463,7 +457,7 @@ namespace MediaBrowser.Controller /// Gets all genres from all recursive children of a folder /// The CategoryInfo class is used to keep track of the number of times each genres appears /// - public IEnumerable> GetAllGenres(Folder parent, Guid userId) + public IEnumerable> GetAllGenres(Folder parent, Guid userId) { Dictionary data = new Dictionary(); @@ -493,7 +487,7 @@ namespace MediaBrowser.Controller } // Now go through the dictionary and create a Category for each genre - List> list = new List>(); + List> list = new List>(); foreach (string key in data.Keys) { @@ -502,10 +496,10 @@ namespace MediaBrowser.Controller if (entity != null) { - list.Add(new CategoryInfo() + list.Add(new IBNItem() { Item = entity, - ItemCount = data[key] + BaseItemCount = data[key] }); } } diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.cs deleted file mode 100644 index 5616f6dd60..0000000000 --- a/MediaBrowser.Model/Configuration/UserConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ - -namespace MediaBrowser.Model.Configuration -{ - /// - /// This holds settings that can be personalized on a per-user, per-device basis. - /// - public class UserConfiguration - { - public int RecentItemDays { get; set; } - - public UserConfiguration() - { - RecentItemDays = 14; - } - } -} diff --git a/MediaBrowser.Model/DTO/ApiBaseItem.cs b/MediaBrowser.Model/DTO/ApiBaseItem.cs index d6b0f4a047..eca45c9f8b 100644 --- a/MediaBrowser.Model/DTO/ApiBaseItem.cs +++ b/MediaBrowser.Model/DTO/ApiBaseItem.cs @@ -20,14 +20,14 @@ namespace MediaBrowser.Model.DTO /// /// This is the full return object when requesting an Item /// - public class BaseItemWrapper - where T : BaseItem + public class BaseItemContainer + where TItemType : BaseItem { - public T Item { get; set; } + public TItemType Item { get; set; } public UserItemData UserItemData { get; set; } - public IEnumerable> Children { get; set; } + public IEnumerable> Children { get; set; } public bool IsFolder { get; set; } @@ -45,7 +45,8 @@ namespace MediaBrowser.Model.DTO return Type.Equals(type, StringComparison.OrdinalIgnoreCase); } - public IEnumerable People { get; set; } + public IEnumerable People { get; set; } + public IEnumerable Studios { get; set; } /// /// If the item does not have a logo, this will hold the Id of the Parent that has one. @@ -60,7 +61,7 @@ namespace MediaBrowser.Model.DTO /// /// This is strictly for convenience so the UI's don't have to use the verbose generic syntax of BaseItemWrapper /// - public class ApiBaseItemWrapper : BaseItemWrapper + public class ApiBaseItemContainer : BaseItemContainer { } } diff --git a/MediaBrowser.Model/DTO/CategoryInfo.cs b/MediaBrowser.Model/DTO/CategoryInfo.cs deleted file mode 100644 index e6b2aeafb0..0000000000 --- a/MediaBrowser.Model/DTO/CategoryInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ - -namespace MediaBrowser.Model.DTO -{ - /// - /// This is a stub class used by the api to get IBN types along with their item counts - /// - public class CategoryInfo - { - /// - /// The actual genre, year, studio, etc - /// - public T Item { get; set; } - - /// - /// The number of items that have the genre, year, studio, etc - /// - public int ItemCount { get; set; } - } -} diff --git a/MediaBrowser.Model/DTO/IBNItem.cs b/MediaBrowser.Model/DTO/IBNItem.cs new file mode 100644 index 0000000000..8a0620767f --- /dev/null +++ b/MediaBrowser.Model/DTO/IBNItem.cs @@ -0,0 +1,38 @@ +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Model.DTO +{ + /// + /// This is a stub class used by the api to get IBN types along with their item counts + /// + public class IBNItem + { + /// + /// The actual genre, year, studio, etc + /// + public T Item { get; set; } + + /// + /// The number of items that have the genre, year, studio, etc + /// + public int BaseItemCount { get; set; } + } + + /// + /// This is used by BaseItemContainer + /// + public class BaseItemPerson + { + public PersonInfo PersonInfo { get; set; } + public string PrimaryImagePath { get; set; } + } + + /// + /// This is used by BaseItemContainer + /// + public class BaseItemStudio + { + public string Name { get; set; } + public string PrimaryImagePath { get; set; } + } +} diff --git a/MediaBrowser.Model/Entities/Person.cs b/MediaBrowser.Model/Entities/Person.cs index 690a2de857..e85f8a9050 100644 --- a/MediaBrowser.Model/Entities/Person.cs +++ b/MediaBrowser.Model/Entities/Person.cs @@ -6,7 +6,6 @@ namespace MediaBrowser.Model.Entities /// public class Person : BaseEntity { - public PersonType PersonType { get; set; } } /// diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index dd9034ed56..14c7843edf 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -32,12 +32,11 @@ 4 - - + diff --git a/MediaBrowser.Model/Users/User.cs b/MediaBrowser.Model/Users/User.cs index 63698dc857..85776fb8b8 100644 --- a/MediaBrowser.Model/Users/User.cs +++ b/MediaBrowser.Model/Users/User.cs @@ -10,5 +10,12 @@ namespace MediaBrowser.Model.Users private Dictionary _ItemData = new Dictionary(); public Dictionary ItemData { get { return _ItemData; } set { _ItemData = value; } } + + public int RecentItemDays { get; set; } + + public User() + { + RecentItemDays = 14; + } } } -- cgit v1.2.3 From e52833059bc819cbdb41ba204b82aee1760ddb3a Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sun, 2 Sep 2012 09:45:02 -0400 Subject: Moved server configuration to the model so that the UI can read it --- .../HttpHandlers/ServerConfigurationHandler.cs | 15 ++ MediaBrowser.Api/MediaBrowser.Api.csproj | 1 + MediaBrowser.Api/Plugin.cs | 4 + MediaBrowser.ApiInteraction/ApiClient.cs | 18 +- .../Configuration/BaseApplicationConfiguration.cs | 19 -- .../Configuration/BaseApplicationPaths.cs | 132 ---------- MediaBrowser.Common/Kernel/BaseApplicationPaths.cs | 132 ++++++++++ MediaBrowser.Common/Kernel/BaseKernel.cs | 10 +- MediaBrowser.Common/MediaBrowser.Common.csproj | 3 +- MediaBrowser.Common/UI/BaseApplication.cs | 5 +- .../Configuration/ServerApplicationPaths.cs | 278 --------------------- .../Configuration/ServerConfiguration.cs | 10 - MediaBrowser.Controller/Kernel.cs | 2 +- .../MediaBrowser.Controller.csproj | 3 +- MediaBrowser.Controller/ServerApplicationPaths.cs | 278 +++++++++++++++++++++ .../Configuration/BaseApplicationConfiguration.cs | 17 ++ .../Configuration/ServerConfiguration.cs | 9 + MediaBrowser.Model/MediaBrowser.Model.csproj | 2 + 18 files changed, 483 insertions(+), 455 deletions(-) create mode 100644 MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs delete mode 100644 MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs delete mode 100644 MediaBrowser.Common/Configuration/BaseApplicationPaths.cs create mode 100644 MediaBrowser.Common/Kernel/BaseApplicationPaths.cs delete mode 100644 MediaBrowser.Controller/Configuration/ServerApplicationPaths.cs delete mode 100644 MediaBrowser.Controller/Configuration/ServerConfiguration.cs create mode 100644 MediaBrowser.Controller/ServerApplicationPaths.cs create mode 100644 MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs create mode 100644 MediaBrowser.Model/Configuration/ServerConfiguration.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs new file mode 100644 index 0000000000..175876b4ca --- /dev/null +++ b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; +using MediaBrowser.Common.Net.Handlers; +using MediaBrowser.Controller; +using MediaBrowser.Model.Configuration; + +namespace MediaBrowser.Api.HttpHandlers +{ + class ServerConfigurationHandler : BaseSerializationHandler + { + protected override Task GetObjectToSerialize() + { + return Task.FromResult(Kernel.Instance.Configuration); + } + } +} diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 5d32210938..89bb5adc91 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -65,6 +65,7 @@ + diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index 467b30ef15..f13b9efb33 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -105,6 +105,10 @@ namespace MediaBrowser.Api { return new WeatherHandler(); } + else if (localPath.EndsWith("/api/cerverconfiguration", StringComparison.OrdinalIgnoreCase)) + { + return new ServerConfigurationHandler(); + } return null; } diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs index 99af250ca8..922b4bb0c9 100644 --- a/MediaBrowser.ApiInteraction/ApiClient.cs +++ b/MediaBrowser.ApiInteraction/ApiClient.cs @@ -4,6 +4,7 @@ using System.IO; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Weather; @@ -568,7 +569,20 @@ namespace MediaBrowser.ApiInteraction /// /// Gets weather information for the default location as set in configuration /// - public async Task GetWeatherInfo() + public async Task GetServerConfigurationAsync() + { + string url = ApiUrl + "/ServerConfiguration"; + + using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) + { + return DeserializeFromStream(stream); + } + } + + /// + /// Gets weather information for the default location as set in configuration + /// + public async Task GetWeatherInfoAsync() { string url = ApiUrl + "/weather"; @@ -581,7 +595,7 @@ namespace MediaBrowser.ApiInteraction /// /// Gets weather information for a specific zip code /// - public async Task GetWeatherInfo(string zipCode) + public async Task GetWeatherInfoAsync(string zipCode) { string url = ApiUrl + "/weather?zipcode=" + zipCode; diff --git a/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs deleted file mode 100644 index 7ed782bdb1..0000000000 --- a/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs +++ /dev/null @@ -1,19 +0,0 @@ -using MediaBrowser.Common.Logging; - -namespace MediaBrowser.Common.Configuration -{ - /// - /// Serves as a common base class for the Server and UI application Configurations - /// - public class BaseApplicationConfiguration - { - public LogSeverity LogSeverity { get; set; } - public int HttpServerPortNumber { get; set; } - - public BaseApplicationConfiguration() - { - LogSeverity = LogSeverity.Info; - HttpServerPortNumber = 8096; - } - } -} diff --git a/MediaBrowser.Common/Configuration/BaseApplicationPaths.cs b/MediaBrowser.Common/Configuration/BaseApplicationPaths.cs deleted file mode 100644 index d030da844c..0000000000 --- a/MediaBrowser.Common/Configuration/BaseApplicationPaths.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System.Configuration; -using System.IO; -using System.Reflection; - -namespace MediaBrowser.Common.Configuration -{ - /// - /// Provides a base class to hold common application paths used by both the UI and Server. - /// This can be subclassed to add application-specific paths. - /// - public abstract class BaseApplicationPaths - { - private string _programDataPath; - /// - /// Gets the path to the program data folder - /// - public string ProgramDataPath - { - get - { - if (_programDataPath == null) - { - _programDataPath = GetProgramDataPath(); - } - return _programDataPath; - } - } - - private string _pluginsPath; - /// - /// Gets the path to the plugin directory - /// - public string PluginsPath - { - get - { - if (_pluginsPath == null) - { - _pluginsPath = Path.Combine(ProgramDataPath, "plugins"); - if (!Directory.Exists(_pluginsPath)) - { - Directory.CreateDirectory(_pluginsPath); - } - } - - return _pluginsPath; - } - } - - private string _logDirectoryPath; - /// - /// Gets the path to the log directory - /// - public string LogDirectoryPath - { - get - { - if (_logDirectoryPath == null) - { - _logDirectoryPath = Path.Combine(ProgramDataPath, "logs"); - if (!Directory.Exists(_logDirectoryPath)) - { - Directory.CreateDirectory(_logDirectoryPath); - } - } - return _logDirectoryPath; - } - } - - private string _configurationDirectoryPath; - /// - /// Gets the path to the application configuration root directory - /// - public string ConfigurationDirectoryPath - { - get - { - if (_configurationDirectoryPath == null) - { - _configurationDirectoryPath = Path.Combine(ProgramDataPath, "config"); - if (!Directory.Exists(_configurationDirectoryPath)) - { - Directory.CreateDirectory(_configurationDirectoryPath); - } - } - return _configurationDirectoryPath; - } - } - - private string _systemConfigurationFilePath; - /// - /// Gets the path to the system configuration file - /// - public string SystemConfigurationFilePath - { - get - { - if (_systemConfigurationFilePath == null) - { - _systemConfigurationFilePath = Path.Combine(ConfigurationDirectoryPath, "system.xml"); - } - return _systemConfigurationFilePath; - } - } - - /// - /// Gets the path to the application's ProgramDataFolder - /// - private static string GetProgramDataPath() - { - string programDataPath = ConfigurationManager.AppSettings["ProgramDataPath"]; - - // If it's a relative path, e.g. "..\" - if (!Path.IsPathRooted(programDataPath)) - { - string path = Assembly.GetExecutingAssembly().Location; - path = Path.GetDirectoryName(path); - - programDataPath = Path.Combine(path, programDataPath); - - programDataPath = Path.GetFullPath(programDataPath); - } - - if (!Directory.Exists(programDataPath)) - { - Directory.CreateDirectory(programDataPath); - } - - return programDataPath; - } - } -} diff --git a/MediaBrowser.Common/Kernel/BaseApplicationPaths.cs b/MediaBrowser.Common/Kernel/BaseApplicationPaths.cs new file mode 100644 index 0000000000..3c394680f6 --- /dev/null +++ b/MediaBrowser.Common/Kernel/BaseApplicationPaths.cs @@ -0,0 +1,132 @@ +using System.Configuration; +using System.IO; +using System.Reflection; + +namespace MediaBrowser.Common.Kernel +{ + /// + /// Provides a base class to hold common application paths used by both the UI and Server. + /// This can be subclassed to add application-specific paths. + /// + public abstract class BaseApplicationPaths + { + private string _programDataPath; + /// + /// Gets the path to the program data folder + /// + public string ProgramDataPath + { + get + { + if (_programDataPath == null) + { + _programDataPath = GetProgramDataPath(); + } + return _programDataPath; + } + } + + private string _pluginsPath; + /// + /// Gets the path to the plugin directory + /// + public string PluginsPath + { + get + { + if (_pluginsPath == null) + { + _pluginsPath = Path.Combine(ProgramDataPath, "plugins"); + if (!Directory.Exists(_pluginsPath)) + { + Directory.CreateDirectory(_pluginsPath); + } + } + + return _pluginsPath; + } + } + + private string _logDirectoryPath; + /// + /// Gets the path to the log directory + /// + public string LogDirectoryPath + { + get + { + if (_logDirectoryPath == null) + { + _logDirectoryPath = Path.Combine(ProgramDataPath, "logs"); + if (!Directory.Exists(_logDirectoryPath)) + { + Directory.CreateDirectory(_logDirectoryPath); + } + } + return _logDirectoryPath; + } + } + + private string _configurationDirectoryPath; + /// + /// Gets the path to the application configuration root directory + /// + public string ConfigurationDirectoryPath + { + get + { + if (_configurationDirectoryPath == null) + { + _configurationDirectoryPath = Path.Combine(ProgramDataPath, "config"); + if (!Directory.Exists(_configurationDirectoryPath)) + { + Directory.CreateDirectory(_configurationDirectoryPath); + } + } + return _configurationDirectoryPath; + } + } + + private string _systemConfigurationFilePath; + /// + /// Gets the path to the system configuration file + /// + public string SystemConfigurationFilePath + { + get + { + if (_systemConfigurationFilePath == null) + { + _systemConfigurationFilePath = Path.Combine(ConfigurationDirectoryPath, "system.xml"); + } + return _systemConfigurationFilePath; + } + } + + /// + /// Gets the path to the application's ProgramDataFolder + /// + private static string GetProgramDataPath() + { + string programDataPath = ConfigurationManager.AppSettings["ProgramDataPath"]; + + // If it's a relative path, e.g. "..\" + if (!Path.IsPathRooted(programDataPath)) + { + string path = Assembly.GetExecutingAssembly().Location; + path = Path.GetDirectoryName(path); + + programDataPath = Path.Combine(path, programDataPath); + + programDataPath = Path.GetFullPath(programDataPath); + } + + if (!Directory.Exists(programDataPath)) + { + Directory.CreateDirectory(programDataPath); + } + + return programDataPath; + } + } +} diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 5ba68cf4eb..44569cbadf 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -6,11 +6,11 @@ using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Logging; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Serialization; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Progress; namespace MediaBrowser.Common.Kernel @@ -93,17 +93,17 @@ namespace MediaBrowser.Common.Kernel protected void ReloadComposableParts() { DisposeComposableParts(); - + // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that // This will prevent the .dll file from getting locked, and allow us to replace it when needed IEnumerable pluginAssemblies = Directory.GetFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories).Select(f => Assembly.Load(File.ReadAllBytes((f)))); var catalog = new AggregateCatalog(pluginAssemblies.Select(a => new AssemblyCatalog(a))); - + // Include composable parts in the Common assembly // Uncomment this if it's ever needed //catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); - + // Include composable parts in the subclass assembly catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly)); @@ -171,7 +171,7 @@ namespace MediaBrowser.Common.Kernel Configuration = XmlSerializer.DeserializeFromFile(ApplicationPaths.SystemConfigurationFilePath); } - Logger.LoggerInstance.LogSeverity = Configuration.LogSeverity; + Logger.LoggerInstance.LogSeverity = Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info; } /// diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index d80303d1f8..841eccf736 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -74,8 +74,7 @@ - - + diff --git a/MediaBrowser.Common/UI/BaseApplication.cs b/MediaBrowser.Common/UI/BaseApplication.cs index fb771f1e3c..2112be6792 100644 --- a/MediaBrowser.Common/UI/BaseApplication.cs +++ b/MediaBrowser.Common/UI/BaseApplication.cs @@ -1,13 +1,10 @@ using System; -using System.IO; -using System.Threading.Tasks; +using System.Reflection; using System.Windows; -using System.Windows.Controls; using System.Windows.Media.Imaging; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Logging; using MediaBrowser.Model.Progress; -using System.Reflection; namespace MediaBrowser.Common.UI { diff --git a/MediaBrowser.Controller/Configuration/ServerApplicationPaths.cs b/MediaBrowser.Controller/Configuration/ServerApplicationPaths.cs deleted file mode 100644 index 92283ab25f..0000000000 --- a/MediaBrowser.Controller/Configuration/ServerApplicationPaths.cs +++ /dev/null @@ -1,278 +0,0 @@ -using System.IO; -using MediaBrowser.Common.Configuration; - -namespace MediaBrowser.Controller.Configuration -{ - /// - /// Extends BaseApplicationPaths to add paths that are only applicable on the server - /// - public class ServerApplicationPaths : BaseApplicationPaths - { - private string _rootFolderPath; - /// - /// Gets the path to the root media directory - /// - public string RootFolderPath - { - get - { - if (_rootFolderPath == null) - { - _rootFolderPath = Path.Combine(ProgramDataPath, "root"); - if (!Directory.Exists(_rootFolderPath)) - { - Directory.CreateDirectory(_rootFolderPath); - } - } - return _rootFolderPath; - } - } - - private string _ibnPath; - /// - /// Gets the path to the Images By Name directory - /// - public string ImagesByNamePath - { - get - { - if (_ibnPath == null) - { - _ibnPath = Path.Combine(ProgramDataPath, "ImagesByName"); - if (!Directory.Exists(_ibnPath)) - { - Directory.CreateDirectory(_ibnPath); - } - } - - return _ibnPath; - } - } - - private string _PeoplePath; - /// - /// Gets the path to the People directory - /// - public string PeoplePath - { - get - { - if (_PeoplePath == null) - { - _PeoplePath = Path.Combine(ImagesByNamePath, "People"); - if (!Directory.Exists(_PeoplePath)) - { - Directory.CreateDirectory(_PeoplePath); - } - } - - return _PeoplePath; - } - } - - private string _GenrePath; - /// - /// Gets the path to the Genre directory - /// - public string GenrePath - { - get - { - if (_GenrePath == null) - { - _GenrePath = Path.Combine(ImagesByNamePath, "Genre"); - if (!Directory.Exists(_GenrePath)) - { - Directory.CreateDirectory(_GenrePath); - } - } - - return _GenrePath; - } - } - - private string _StudioPath; - /// - /// Gets the path to the Studio directory - /// - public string StudioPath - { - get - { - if (_StudioPath == null) - { - _StudioPath = Path.Combine(ImagesByNamePath, "Studio"); - if (!Directory.Exists(_StudioPath)) - { - Directory.CreateDirectory(_StudioPath); - } - } - - return _StudioPath; - } - } - - private string _yearPath; - /// - /// Gets the path to the Year directory - /// - public string YearPath - { - get - { - if (_yearPath == null) - { - _yearPath = Path.Combine(ImagesByNamePath, "Year"); - if (!Directory.Exists(_yearPath)) - { - Directory.CreateDirectory(_yearPath); - } - } - - return _yearPath; - } - } - - private string _userConfigurationDirectoryPath; - /// - /// Gets the path to the user configuration directory - /// - public string UserConfigurationDirectoryPath - { - get - { - if (_userConfigurationDirectoryPath == null) - { - _userConfigurationDirectoryPath = Path.Combine(ConfigurationDirectoryPath, "user"); - if (!Directory.Exists(_userConfigurationDirectoryPath)) - { - Directory.CreateDirectory(_userConfigurationDirectoryPath); - } - } - return _userConfigurationDirectoryPath; - } - } - - private string _CacheDirectory = null; - /// - /// Gets the folder path to the cache directory - /// - public string CacheDirectory - { - get - { - if (_CacheDirectory == null) - { - _CacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.ProgramDataPath, "cache"); - - if (!Directory.Exists(_CacheDirectory)) - { - Directory.CreateDirectory(_CacheDirectory); - } - } - - return _CacheDirectory; - } - } - - private string _FFProbeAudioCacheDirectory = null; - /// - /// Gets the folder path to the ffprobe audio cache directory - /// - public string FFProbeAudioCacheDirectory - { - get - { - if (_FFProbeAudioCacheDirectory == null) - { - _FFProbeAudioCacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.CacheDirectory, "ffprobe-audio"); - - if (!Directory.Exists(_FFProbeAudioCacheDirectory)) - { - Directory.CreateDirectory(_FFProbeAudioCacheDirectory); - } - } - - return _FFProbeAudioCacheDirectory; - } - } - - private string _FFProbeVideoCacheDirectory = null; - /// - /// Gets the folder path to the ffprobe video cache directory - /// - public string FFProbeVideoCacheDirectory - { - get - { - if (_FFProbeVideoCacheDirectory == null) - { - _FFProbeVideoCacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.CacheDirectory, "ffprobe-video"); - - if (!Directory.Exists(_FFProbeVideoCacheDirectory)) - { - Directory.CreateDirectory(_FFProbeVideoCacheDirectory); - } - } - - return _FFProbeVideoCacheDirectory; - } - } - - private string _FFMpegDirectory = null; - /// - /// Gets the folder path to ffmpeg - /// - public string FFMpegDirectory - { - get - { - if (_FFMpegDirectory == null) - { - _FFMpegDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.ProgramDataPath, "FFMpeg"); - - if (!Directory.Exists(_FFMpegDirectory)) - { - Directory.CreateDirectory(_FFMpegDirectory); - } - } - - return _FFMpegDirectory; - } - } - - private string _FFMpegPath = null; - /// - /// Gets the path to ffmpeg.exe - /// - public string FFMpegPath - { - get - { - if (_FFMpegPath == null) - { - _FFMpegPath = Path.Combine(FFMpegDirectory, "ffmpeg.exe"); - } - - return _FFMpegPath; - } - } - - private string _FFProbePath = null; - /// - /// Gets the path to ffprobe.exe - /// - public string FFProbePath - { - get - { - if (_FFProbePath == null) - { - _FFProbePath = Path.Combine(FFMpegDirectory, "ffprobe.exe"); - } - - return _FFProbePath; - } - } - } -} diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs deleted file mode 100644 index 368c8ef371..0000000000 --- a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs +++ /dev/null @@ -1,10 +0,0 @@ -using MediaBrowser.Common.Configuration; - -namespace MediaBrowser.Controller.Configuration -{ - public class ServerConfiguration : BaseApplicationConfiguration - { - public bool EnableInternetProviders { get; set; } - public string WeatherZipCode { get; set; } - } -} diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 1a161ccc98..32f4a58285 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -9,12 +9,12 @@ using System.Text; using System.Threading.Tasks; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Logging; -using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Weather; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Progress; diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index f72202fea8..1547deea21 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -58,8 +58,7 @@ - - + diff --git a/MediaBrowser.Controller/ServerApplicationPaths.cs b/MediaBrowser.Controller/ServerApplicationPaths.cs new file mode 100644 index 0000000000..0f4932fd04 --- /dev/null +++ b/MediaBrowser.Controller/ServerApplicationPaths.cs @@ -0,0 +1,278 @@ +using System.IO; +using MediaBrowser.Common.Kernel; + +namespace MediaBrowser.Controller +{ + /// + /// Extends BaseApplicationPaths to add paths that are only applicable on the server + /// + public class ServerApplicationPaths : BaseApplicationPaths + { + private string _rootFolderPath; + /// + /// Gets the path to the root media directory + /// + public string RootFolderPath + { + get + { + if (_rootFolderPath == null) + { + _rootFolderPath = Path.Combine(ProgramDataPath, "root"); + if (!Directory.Exists(_rootFolderPath)) + { + Directory.CreateDirectory(_rootFolderPath); + } + } + return _rootFolderPath; + } + } + + private string _ibnPath; + /// + /// Gets the path to the Images By Name directory + /// + public string ImagesByNamePath + { + get + { + if (_ibnPath == null) + { + _ibnPath = Path.Combine(ProgramDataPath, "ImagesByName"); + if (!Directory.Exists(_ibnPath)) + { + Directory.CreateDirectory(_ibnPath); + } + } + + return _ibnPath; + } + } + + private string _PeoplePath; + /// + /// Gets the path to the People directory + /// + public string PeoplePath + { + get + { + if (_PeoplePath == null) + { + _PeoplePath = Path.Combine(ImagesByNamePath, "People"); + if (!Directory.Exists(_PeoplePath)) + { + Directory.CreateDirectory(_PeoplePath); + } + } + + return _PeoplePath; + } + } + + private string _GenrePath; + /// + /// Gets the path to the Genre directory + /// + public string GenrePath + { + get + { + if (_GenrePath == null) + { + _GenrePath = Path.Combine(ImagesByNamePath, "Genre"); + if (!Directory.Exists(_GenrePath)) + { + Directory.CreateDirectory(_GenrePath); + } + } + + return _GenrePath; + } + } + + private string _StudioPath; + /// + /// Gets the path to the Studio directory + /// + public string StudioPath + { + get + { + if (_StudioPath == null) + { + _StudioPath = Path.Combine(ImagesByNamePath, "Studio"); + if (!Directory.Exists(_StudioPath)) + { + Directory.CreateDirectory(_StudioPath); + } + } + + return _StudioPath; + } + } + + private string _yearPath; + /// + /// Gets the path to the Year directory + /// + public string YearPath + { + get + { + if (_yearPath == null) + { + _yearPath = Path.Combine(ImagesByNamePath, "Year"); + if (!Directory.Exists(_yearPath)) + { + Directory.CreateDirectory(_yearPath); + } + } + + return _yearPath; + } + } + + private string _userConfigurationDirectoryPath; + /// + /// Gets the path to the user configuration directory + /// + public string UserConfigurationDirectoryPath + { + get + { + if (_userConfigurationDirectoryPath == null) + { + _userConfigurationDirectoryPath = Path.Combine(ConfigurationDirectoryPath, "user"); + if (!Directory.Exists(_userConfigurationDirectoryPath)) + { + Directory.CreateDirectory(_userConfigurationDirectoryPath); + } + } + return _userConfigurationDirectoryPath; + } + } + + private string _CacheDirectory = null; + /// + /// Gets the folder path to the cache directory + /// + public string CacheDirectory + { + get + { + if (_CacheDirectory == null) + { + _CacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.ProgramDataPath, "cache"); + + if (!Directory.Exists(_CacheDirectory)) + { + Directory.CreateDirectory(_CacheDirectory); + } + } + + return _CacheDirectory; + } + } + + private string _FFProbeAudioCacheDirectory = null; + /// + /// Gets the folder path to the ffprobe audio cache directory + /// + public string FFProbeAudioCacheDirectory + { + get + { + if (_FFProbeAudioCacheDirectory == null) + { + _FFProbeAudioCacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.CacheDirectory, "ffprobe-audio"); + + if (!Directory.Exists(_FFProbeAudioCacheDirectory)) + { + Directory.CreateDirectory(_FFProbeAudioCacheDirectory); + } + } + + return _FFProbeAudioCacheDirectory; + } + } + + private string _FFProbeVideoCacheDirectory = null; + /// + /// Gets the folder path to the ffprobe video cache directory + /// + public string FFProbeVideoCacheDirectory + { + get + { + if (_FFProbeVideoCacheDirectory == null) + { + _FFProbeVideoCacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.CacheDirectory, "ffprobe-video"); + + if (!Directory.Exists(_FFProbeVideoCacheDirectory)) + { + Directory.CreateDirectory(_FFProbeVideoCacheDirectory); + } + } + + return _FFProbeVideoCacheDirectory; + } + } + + private string _FFMpegDirectory = null; + /// + /// Gets the folder path to ffmpeg + /// + public string FFMpegDirectory + { + get + { + if (_FFMpegDirectory == null) + { + _FFMpegDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.ProgramDataPath, "FFMpeg"); + + if (!Directory.Exists(_FFMpegDirectory)) + { + Directory.CreateDirectory(_FFMpegDirectory); + } + } + + return _FFMpegDirectory; + } + } + + private string _FFMpegPath = null; + /// + /// Gets the path to ffmpeg.exe + /// + public string FFMpegPath + { + get + { + if (_FFMpegPath == null) + { + _FFMpegPath = Path.Combine(FFMpegDirectory, "ffmpeg.exe"); + } + + return _FFMpegPath; + } + } + + private string _FFProbePath = null; + /// + /// Gets the path to ffprobe.exe + /// + public string FFProbePath + { + get + { + if (_FFProbePath == null) + { + _FFProbePath = Path.Combine(FFMpegDirectory, "ffprobe.exe"); + } + + return _FFProbePath; + } + } + } +} diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs new file mode 100644 index 0000000000..17be9eaef6 --- /dev/null +++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs @@ -0,0 +1,17 @@ + +namespace MediaBrowser.Model.Configuration +{ + /// + /// Serves as a common base class for the Server and UI application Configurations + /// + public class BaseApplicationConfiguration + { + public bool EnableDebugLevelLogging { get; set; } + public int HttpServerPortNumber { get; set; } + + public BaseApplicationConfiguration() + { + HttpServerPortNumber = 8096; + } + } +} diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs new file mode 100644 index 0000000000..97b88a5d9b --- /dev/null +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -0,0 +1,9 @@ + +namespace MediaBrowser.Model.Configuration +{ + public class ServerConfiguration : BaseApplicationConfiguration + { + public bool EnableInternetProviders { get; set; } + public string WeatherZipCode { get; set; } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index dabc6864ca..b91e7ea173 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -32,6 +32,8 @@ 4 + + -- cgit v1.2.3 From b1212467a07a645b61e7a5ac1aa9af9470f6b8ac Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sun, 2 Sep 2012 10:11:58 -0400 Subject: Added EnableUserProfiles to server config --- MediaBrowser.Model/Configuration/ServerConfiguration.cs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 97b88a5d9b..480cf3adb0 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -5,5 +5,13 @@ namespace MediaBrowser.Model.Configuration { public bool EnableInternetProviders { get; set; } public string WeatherZipCode { get; set; } + public bool EnableUserProfiles { get; set; } + + public ServerConfiguration() + : base() + { + EnableUserProfiles = true; + WeatherZipCode = "02116"; + } } } -- cgit v1.2.3 From 3c473752298e2bc91d3cb10a13c236cfaa2bc11e Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sun, 2 Sep 2012 13:34:12 -0400 Subject: Weather updates --- MediaBrowser.ApiInteraction/ApiClient.cs | 18 +++++++++++++----- MediaBrowser.Common/Kernel/BaseKernel.cs | 10 +++++++++- .../Net/Handlers/BaseSerializationHandler.cs | 2 +- MediaBrowser.Controller/Weather/WeatherClient.cs | 12 +++++++++--- .../Configuration/ServerConfiguration.cs | 8 +++++--- MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + MediaBrowser.Model/Weather/WeatherUnits.cs | 9 +++++++++ 7 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 MediaBrowser.Model/Weather/WeatherUnits.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs index bc06aa9a2e..3de40f6a86 100644 --- a/MediaBrowser.ApiInteraction/ApiClient.cs +++ b/MediaBrowser.ApiInteraction/ApiClient.cs @@ -573,9 +573,9 @@ namespace MediaBrowser.ApiInteraction { string url = ApiUrl + "/ServerConfiguration"; - using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) + using (Stream stream = await GetSerializedStreamAsync(url, ApiInteraction.SerializationFormat.Json).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream, ApiInteraction.SerializationFormat.Json); } } @@ -622,19 +622,27 @@ namespace MediaBrowser.ApiInteraction /// This is a helper around getting a stream from the server that contains serialized data /// private Task GetSerializedStreamAsync(string url) + { + return GetSerializedStreamAsync(url, SerializationFormat); + } + + /// + /// This is a helper around getting a stream from the server that contains serialized data + /// + private Task GetSerializedStreamAsync(string url, SerializationFormat serializationFormat) { if (url.IndexOf('?') == -1) { - url += "?dataformat=" + SerializationFormat.ToString().ToLower(); + url += "?dataformat=" + serializationFormat.ToString().ToLower(); } else { - url += "&dataformat=" + SerializationFormat.ToString().ToLower(); + url += "&dataformat=" + serializationFormat.ToString().ToLower(); } return GetStreamAsync(url); } - + private T DeserializeFromStream(Stream stream) { return DeserializeFromStream(stream, SerializationFormat); diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 44569cbadf..cdde17b24a 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -41,6 +41,14 @@ namespace MediaBrowser.Common.Kernel /// public HttpServer HttpServer { get; private set; } + protected virtual string HttpServerUrlPrefix + { + get + { + return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/"; + } + } + /// /// Gets the kernel context. The UI kernel will have to override this. /// @@ -181,7 +189,7 @@ namespace MediaBrowser.Common.Kernel { DisposeHttpServer(); - HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/"); + HttpServer = new HttpServer(HttpServerUrlPrefix); } /// diff --git a/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs index a0696d4a61..dd3020e035 100644 --- a/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs @@ -62,7 +62,7 @@ namespace MediaBrowser.Common.Net.Handlers protected async override Task WriteResponseToOutputStream(Stream stream) { - await EnsureObjectToSerialize(); + await EnsureObjectToSerialize().ConfigureAwait(false); switch (SerializationFormat) { diff --git a/MediaBrowser.Controller/Weather/WeatherClient.cs b/MediaBrowser.Controller/Weather/WeatherClient.cs index c49c504773..e2aada34f8 100644 --- a/MediaBrowser.Controller/Weather/WeatherClient.cs +++ b/MediaBrowser.Controller/Weather/WeatherClient.cs @@ -53,12 +53,18 @@ namespace MediaBrowser.Controller.Weather { WeatherInfo info = new WeatherInfo(); - if (data.current_condition.Any()) + if (data.current_condition != null) { - info.CurrentWeather = data.current_condition.First().ToWeatherStatus(); + if (data.current_condition.Any()) + { + info.CurrentWeather = data.current_condition.First().ToWeatherStatus(); + } } - info.Forecasts = data.weather.Select(w => w.ToWeatherForecast()).ToArray(); + if (data.weather != null) + { + info.Forecasts = data.weather.Select(w => w.ToWeatherForecast()).ToArray(); + } return info; } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 480cf3adb0..c229ca5568 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -1,17 +1,19 @@ - +using MediaBrowser.Model.Weather; + namespace MediaBrowser.Model.Configuration { public class ServerConfiguration : BaseApplicationConfiguration { public bool EnableInternetProviders { get; set; } - public string WeatherZipCode { get; set; } public bool EnableUserProfiles { get; set; } + public string WeatherZipCode { get; set; } + public WeatherUnits WeatherUnit { get; set; } + public ServerConfiguration() : base() { EnableUserProfiles = true; - WeatherZipCode = "02116"; } } } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index b91e7ea173..668fd8f5b5 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -61,6 +61,7 @@ + diff --git a/MediaBrowser.Model/Weather/WeatherUnits.cs b/MediaBrowser.Model/Weather/WeatherUnits.cs new file mode 100644 index 0000000000..3bea67b9a4 --- /dev/null +++ b/MediaBrowser.Model/Weather/WeatherUnits.cs @@ -0,0 +1,9 @@ + +namespace MediaBrowser.Model.Weather +{ + public enum WeatherUnits + { + Fahrenheit, + Celsius + } +} -- cgit v1.2.3 From 50f88997bab58f4cfcbd3f420521776a54eb372d Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sat, 8 Sep 2012 16:25:56 -0400 Subject: Added protobuf support for serializing ServerConfiguration --- MediaBrowser.ApiInteraction.Portable/ApiClient.cs | 5 +---- MediaBrowser.ApiInteraction/BaseHttpApiClient.cs | 7 ++----- .../Configuration/BaseApplicationConfiguration.cs | 9 ++++++++- MediaBrowser.Model/Configuration/ServerConfiguration.cs | 11 +++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.ApiInteraction.Portable/ApiClient.cs b/MediaBrowser.ApiInteraction.Portable/ApiClient.cs index cbd179b02e..eef73dd874 100644 --- a/MediaBrowser.ApiInteraction.Portable/ApiClient.cs +++ b/MediaBrowser.ApiInteraction.Portable/ApiClient.cs @@ -269,10 +269,7 @@ namespace MediaBrowser.ApiInteraction.Portable { string url = ApiUrl + "/ServerConfiguration"; - // At the moment this can't be retrieved in protobuf format - SerializationFormats format = DataSerializer.CanDeSerializeJsv ? SerializationFormats.Jsv : SerializationFormats.Json; - - GetDataAsync(url, callback, format); + GetDataAsync(url, callback); } /// diff --git a/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs b/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs index f298e1f7ec..c3871514e9 100644 --- a/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs +++ b/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs @@ -313,12 +313,9 @@ namespace MediaBrowser.ApiInteraction { string url = ApiUrl + "/ServerConfiguration"; - // At the moment this can't be retrieved in protobuf format - SerializationFormats format = DataSerializer.CanDeSerializeJsv ? SerializationFormats.Jsv : SerializationFormats.Json; - - using (Stream stream = await GetSerializedStreamAsync(url, format).ConfigureAwait(false)) + using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DataSerializer.DeserializeFromStream(stream, format); + return DeserializeFromStream(stream); } } diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs index 17be9eaef6..41eb1da2c8 100644 --- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs +++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs @@ -1,12 +1,19 @@ - +using ProtoBuf; + namespace MediaBrowser.Model.Configuration { /// /// Serves as a common base class for the Server and UI application Configurations + /// ProtoInclude tells Protobuf about subclasses, + /// The number 50 can be any number, so long as it doesn't clash with any of the ProtoMember numbers either here or in subclasses. /// + [ProtoContract, ProtoInclude(50, typeof(ServerConfiguration))] public class BaseApplicationConfiguration { + [ProtoMember(1)] public bool EnableDebugLevelLogging { get; set; } + + [ProtoMember(2)] public int HttpServerPortNumber { get; set; } public BaseApplicationConfiguration() diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index c229ca5568..5bcd09ef00 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -1,13 +1,24 @@ using MediaBrowser.Model.Weather; +using ProtoBuf; namespace MediaBrowser.Model.Configuration { + /// + /// Represents the server configuration. + /// + [ProtoContract] public class ServerConfiguration : BaseApplicationConfiguration { + [ProtoMember(3)] public bool EnableInternetProviders { get; set; } + + [ProtoMember(4)] public bool EnableUserProfiles { get; set; } + [ProtoMember(5)] public string WeatherZipCode { get; set; } + + [ProtoMember(6)] public WeatherUnits WeatherUnit { get; set; } public ServerConfiguration() -- cgit v1.2.3