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: [PATCH] Fixed some project fragmentation that came from efforts to go portable --- MediaBrowser.Api/HttpHandlers/JsonHandler.cs | 3 +- .../BaseApplicationConfiguration.cs | 4 +- MediaBrowser.Common/Json/JsonSerializer.cs | 14 +---- MediaBrowser.Common/Kernel/BaseKernel.cs | 16 +++--- .../Logging}/BaseLogger.cs | 2 +- .../Logging}/LogRow.cs | 2 +- .../Logging}/LogSeverity.cs | 2 +- .../Logging}/Logger.cs | 2 +- .../Logging}/StreamLogger.cs | 4 +- .../MediaBrowser.Common.csproj | 10 ++-- MediaBrowser.Common/Plugins/BasePlugin.cs | 30 +++++------ .../Configuration/ServerConfiguration.cs | 1 + MediaBrowser.Controller/UserController.cs | 2 +- .../Xml/BaseItemXmlParser.cs | 4 +- .../MediaBrowser.Logging.csproj | 53 ------------------- .../Properties/AssemblyInfo.cs | 30 ----------- MediaBrowser.Model/Entities/BaseItem.cs | 2 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 10 +--- MediaBrowser.TV/Metadata/SeriesXmlParser.cs | 2 +- MediaBrowser.sln | 6 --- 20 files changed, 47 insertions(+), 152 deletions(-) rename {MediaBrowser.Model => MediaBrowser.Common}/Configuration/BaseApplicationConfiguration.cs (81%) rename {MediaBrowser.Logging => MediaBrowser.Common/Logging}/BaseLogger.cs (95%) rename {MediaBrowser.Logging => MediaBrowser.Common/Logging}/LogRow.cs (93%) rename {MediaBrowser.Logging => MediaBrowser.Common/Logging}/LogSeverity.cs (76%) rename {MediaBrowser.Logging => MediaBrowser.Common/Logging}/Logger.cs (92%) rename {MediaBrowser.Logging => MediaBrowser.Common/Logging}/StreamLogger.cs (91%) delete mode 100644 MediaBrowser.Logging/MediaBrowser.Logging.csproj delete mode 100644 MediaBrowser.Logging/Properties/AssemblyInfo.cs diff --git a/MediaBrowser.Api/HttpHandlers/JsonHandler.cs b/MediaBrowser.Api/HttpHandlers/JsonHandler.cs index a891d7d68..90502a0c5 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.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs similarity index 81% rename from MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs rename to MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs index 2511377c1..7ed782bdb 100644 --- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs +++ b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs @@ -1,6 +1,6 @@ -using MediaBrowser.Logging; +using MediaBrowser.Common.Logging; -namespace MediaBrowser.Model.Configuration +namespace MediaBrowser.Common.Configuration { /// /// Serves as a common base class for the Server and UI application Configurations diff --git a/MediaBrowser.Common/Json/JsonSerializer.cs b/MediaBrowser.Common/Json/JsonSerializer.cs index b7db1d900..8e132c152 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 820d94831..0fdc1f813 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.Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs similarity index 95% rename from MediaBrowser.Logging/BaseLogger.cs rename to MediaBrowser.Common/Logging/BaseLogger.cs index d73b47393..04c3b8097 100644 --- a/MediaBrowser.Logging/BaseLogger.cs +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -2,7 +2,7 @@ using System.Text; using System.Threading; -namespace MediaBrowser.Logging +namespace MediaBrowser.Common.Logging { public abstract class BaseLogger : IDisposable { diff --git a/MediaBrowser.Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs similarity index 93% rename from MediaBrowser.Logging/LogRow.cs rename to MediaBrowser.Common/Logging/LogRow.cs index da699035a..fda714263 100644 --- a/MediaBrowser.Logging/LogRow.cs +++ b/MediaBrowser.Common/Logging/LogRow.cs @@ -1,7 +1,7 @@ using System; using System.Text; -namespace MediaBrowser.Logging +namespace MediaBrowser.Common.Logging { public struct LogRow { diff --git a/MediaBrowser.Logging/LogSeverity.cs b/MediaBrowser.Common/Logging/LogSeverity.cs similarity index 76% rename from MediaBrowser.Logging/LogSeverity.cs rename to MediaBrowser.Common/Logging/LogSeverity.cs index 70c4f6304..2abab1a44 100644 --- a/MediaBrowser.Logging/LogSeverity.cs +++ b/MediaBrowser.Common/Logging/LogSeverity.cs @@ -1,6 +1,6 @@ using System; -namespace MediaBrowser.Logging +namespace MediaBrowser.Common.Logging { [Flags] public enum LogSeverity diff --git a/MediaBrowser.Logging/Logger.cs b/MediaBrowser.Common/Logging/Logger.cs similarity index 92% rename from MediaBrowser.Logging/Logger.cs rename to MediaBrowser.Common/Logging/Logger.cs index db46010a4..d1ae9b8f3 100644 --- a/MediaBrowser.Logging/Logger.cs +++ b/MediaBrowser.Common/Logging/Logger.cs @@ -1,6 +1,6 @@ using System; -namespace MediaBrowser.Logging +namespace MediaBrowser.Common.Logging { public static class Logger { diff --git a/MediaBrowser.Logging/StreamLogger.cs b/MediaBrowser.Common/Logging/StreamLogger.cs similarity index 91% rename from MediaBrowser.Logging/StreamLogger.cs rename to MediaBrowser.Common/Logging/StreamLogger.cs index c4ad7b80f..058c7e69c 100644 --- a/MediaBrowser.Logging/StreamLogger.cs +++ b/MediaBrowser.Common/Logging/StreamLogger.cs @@ -2,7 +2,7 @@ using System.IO; using System.Text; -namespace MediaBrowser.Logging +namespace MediaBrowser.Common.Logging { /// /// Provides a Logger that can write to any Stream @@ -20,7 +20,6 @@ namespace MediaBrowser.Logging protected override void LogEntry(LogRow row) { byte[] bytes = new UTF8Encoding().GetBytes(row.ToString() + Environment.NewLine); - Stream.Write(bytes, 0, bytes.Length); Stream.Flush(); } @@ -28,7 +27,6 @@ namespace MediaBrowser.Logging public override void Dispose() { base.Dispose(); - Stream.Dispose(); } } diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index bf9d17b78..8c8146cdc 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 61ecffc75..98b6120f7 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 e6f794595..56f3a854f 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 7fac4392e..c53397a31 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 ed8afd5a7..d3a7c3bd7 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/MediaBrowser.Logging.csproj b/MediaBrowser.Logging/MediaBrowser.Logging.csproj deleted file mode 100644 index 39840f71f..000000000 --- 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 fa0d3817d..000000000 --- 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.Model/Entities/BaseItem.cs b/MediaBrowser.Model/Entities/BaseItem.cs index 8a1ded03b..6f346a1dd 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 0157fcbf8..9485692d4 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 d36e7ff4b..ecee288cc 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 bebbc61af..6f94baf31 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