diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-21 14:39:47 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-21 14:39:47 -0400 |
| commit | 0a48b5e31aa712acd988626a88c52c47467945b2 (patch) | |
| tree | d2f9cc9bc6aacca3c1cd847bcdfaa209566b7231 | |
| parent | 3f557077550b79e2c209a4041a9318886b79ed14 (diff) | |
Added a BaseKernel for the UI and Server to share, and made some other minor re-organizations.
41 files changed, 254 insertions, 396 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs index ae6228ae8..33beb2901 100644 --- a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs @@ -1,9 +1,9 @@ using System;
using System.IO;
using System.Linq;
+using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Net.Handlers;
namespace MediaBrowser.Api.HttpHandlers
{
diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs index 2ff235493..a54d65524 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs @@ -1,5 +1,4 @@ using System;
-using MediaBrowser.Net.Handlers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
diff --git a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs index 54af1b7e9..a94c2061e 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs @@ -1,7 +1,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
-using MediaBrowser.Net.Handlers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
diff --git a/MediaBrowser.Api/HttpHandlers/JsonHandler.cs b/MediaBrowser.Api/HttpHandlers/JsonHandler.cs index e663085ec..a891d7d68 100644 --- a/MediaBrowser.Api/HttpHandlers/JsonHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/JsonHandler.cs @@ -1,6 +1,6 @@ using System.IO;
using MediaBrowser.Common.Json;
-using MediaBrowser.Net.Handlers;
+using MediaBrowser.Common.Net.Handlers;
namespace MediaBrowser.Api.HttpHandlers
{
diff --git a/MediaBrowser.Api/HttpHandlers/MediaHandler.cs b/MediaBrowser.Api/HttpHandlers/MediaHandler.cs index 47aab3c41..73f8de7d8 100644 --- a/MediaBrowser.Api/HttpHandlers/MediaHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/MediaHandler.cs @@ -1,7 +1,7 @@ using System;
using System.IO;
+using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Net.Handlers;
namespace MediaBrowser.Api.HttpHandlers
{
diff --git a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs index 66daca777..d2898104f 100644 --- a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs @@ -1,5 +1,4 @@ using System;
-using MediaBrowser.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
diff --git a/MediaBrowser.Api/HttpHandlers/UsersHandler.cs b/MediaBrowser.Api/HttpHandlers/UsersHandler.cs index 816d4e83a..d10561e43 100644 --- a/MediaBrowser.Api/HttpHandlers/UsersHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/UsersHandler.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Net.Handlers;
-using MediaBrowser.Controller;
+using MediaBrowser.Controller;
namespace MediaBrowser.Api.HttpHandlers
{
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index dd5c07232..c0942cbb9 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -76,10 +76,6 @@ <Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
<Name>MediaBrowser.Model</Name>
</ProjectReference>
- <ProjectReference Include="..\MediaBrowser.Net\MediaBrowser.Net.csproj">
- <Project>{5da08d1c-0d52-4b1b-aa66-e4a171d938f6}</Project>
- <Name>MediaBrowser.Net</Name>
- </ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index af885ef82..9a4db1518 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -1,10 +1,10 @@ using System;
using System.Reactive.Linq;
using MediaBrowser.Api.HttpHandlers;
+using MediaBrowser.Common.Net;
+using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
-using MediaBrowser.Net;
-using MediaBrowser.Net.Handlers;
namespace MediaBrowser.Api
{
diff --git a/MediaBrowser.Common/ApiInteraction/ApiController.cs b/MediaBrowser.Common/ApiInteraction/ApiController.cs deleted file mode 100644 index b3a51c512..000000000 --- a/MediaBrowser.Common/ApiInteraction/ApiController.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.IO;
-using System.IO.Compression;
-using System.Linq;
-using System.Net;
-using System.Threading.Tasks;
-using MediaBrowser.Common.Json;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Users;
-
-namespace MediaBrowser.Common.ApiInteraction
-{
- public class ApiController
- {
- public string ApiUrl { get; set; }
-
- private WebClient WebClient { get; set; }
-
- public ApiController()
- {
- WebClient = new WebClient();
- }
-
- public async Task<ApiBaseItemWrapper<ApiBaseItem>> GetRootItem(Guid userId)
- {
- string url = ApiUrl + "/item?userId=" + userId.ToString();
-
- using (Stream stream = await WebClient.OpenReadTaskAsync(url))
- {
- using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
- {
- return DeserializeBaseItemWrapper(gzipStream);
- }
- }
- }
-
- public async Task<ApiBaseItemWrapper<ApiBaseItem>> GetItem(Guid id, Guid userId)
- {
- string url = ApiUrl + "/item?userId=" + userId.ToString();
-
- if (id != Guid.Empty)
- {
- url += "&id=" + id.ToString();
- }
-
- using (Stream stream = await WebClient.OpenReadTaskAsync(url))
- {
- using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
- {
- return DeserializeBaseItemWrapper(gzipStream);
- }
- }
- }
-
- public async Task<IEnumerable<User>> GetAllUsers()
- {
- string url = ApiUrl + "/users";
-
- using (Stream stream = await WebClient.OpenReadTaskAsync(url))
- {
- using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
- {
- return JsonSerializer.DeserializeFromStream<IEnumerable<User>>(gzipStream);
- }
- }
- }
-
- public async Task<IEnumerable<CategoryInfo>> GetAllGenres(Guid userId)
- {
- string url = ApiUrl + "/genres?userId=" + userId.ToString();
-
- using (Stream stream = await WebClient.OpenReadTaskAsync(url))
- {
- using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
- {
- return JsonSerializer.DeserializeFromStream<IEnumerable<CategoryInfo>>(gzipStream);
- }
- }
- }
-
- public async Task<CategoryInfo> GetGenre(string name, Guid userId)
- {
- string url = ApiUrl + "/genre?userId=" + userId.ToString() + "&name=" + name;
-
- using (Stream stream = await WebClient.OpenReadTaskAsync(url))
- {
- using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
- {
- return JsonSerializer.DeserializeFromStream<CategoryInfo>(gzipStream);
- }
- }
- }
-
- public async Task<IEnumerable<CategoryInfo>> GetAllStudios(Guid userId)
- {
- string url = ApiUrl + "/studios?userId=" + userId.ToString();
-
- using (Stream stream = await WebClient.OpenReadTaskAsync(url))
- {
- using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
- {
- return JsonSerializer.DeserializeFromStream<IEnumerable<CategoryInfo>>(gzipStream);
- }
- }
- }
-
- public async Task<CategoryInfo> GetStudio(string name, Guid userId)
- {
- string url = ApiUrl + "/studio?userId=" + userId.ToString() + "&name=" + name;
-
- using (Stream stream = await WebClient.OpenReadTaskAsync(url))
- {
- using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
- {
- return JsonSerializer.DeserializeFromStream<CategoryInfo>(gzipStream);
- }
- }
- }
-
- private static ApiBaseItemWrapper<ApiBaseItem> DeserializeBaseItemWrapper(Stream stream)
- {
- ApiBaseItemWrapper<ApiBaseItem> data = JsonSerializer.DeserializeFromStream<ApiBaseItemWrapper<ApiBaseItem>>(stream);
-
- return data;
- }
- }
-}
diff --git a/MediaBrowser.Common/Configuration/BaseConfiguration.cs b/MediaBrowser.Common/Configuration/BaseConfiguration.cs new file mode 100644 index 000000000..bf53686ab --- /dev/null +++ b/MediaBrowser.Common/Configuration/BaseConfiguration.cs @@ -0,0 +1,19 @@ +using MediaBrowser.Common.Logging;
+
+namespace MediaBrowser.Common.Configuration
+{
+ /// <summary>
+ /// Serves as a common base class for the Server and UI Configurations
+ /// </summary>
+ public class BaseConfiguration
+ {
+ public LogSeverity LogSeverity { get; set; }
+ public int HttpServerPortNumber { get; set; }
+
+ public BaseConfiguration()
+ {
+ LogSeverity = LogSeverity.Info;
+ HttpServerPortNumber = 8096;
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs new file mode 100644 index 000000000..d6c13ce38 --- /dev/null +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -0,0 +1,130 @@ +using System.Configuration;
+using System.IO;
+using System.Reflection;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Json;
+using MediaBrowser.Common.Logging;
+using MediaBrowser.Common.Net;
+using MediaBrowser.Common.Plugins;
+
+namespace MediaBrowser.Common.Kernel
+{
+ /// <summary>
+ /// Represents a shared base kernel for both the UI and server apps
+ /// </summary>
+ public abstract class BaseKernel<TConfigurationType>
+ where TConfigurationType : BaseConfiguration, new()
+ {
+ /// <summary>
+ /// Gets the path to the program data folder
+ /// </summary>
+ public string ProgramDataPath { get; private set; }
+
+ /// <summary>
+ /// Gets the current configuration
+ /// </summary>
+ public TConfigurationType Configuration { get; private set; }
+
+ /// <summary>
+ /// Both the UI and server will have a built-in HttpServer.
+ /// People will inevitably want remote control apps so it's needed in the UI too.
+ /// </summary>
+ public HttpServer HttpServer { get; private set; }
+
+ public PluginController PluginController { get; private set; }
+
+ /// <summary>
+ /// Gets the kernel context. The UI kernel will have to override this.
+ /// </summary>
+ protected KernelContext KernelContext { get { return KernelContext.Server; } }
+
+ protected virtual string HttpServerUrlPrefix
+ {
+ get
+ {
+ return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/";
+ }
+ }
+
+ public BaseKernel()
+ {
+ ProgramDataPath = GetProgramDataPath();
+
+ PluginController = new PluginController() { PluginsPath = Path.Combine(ProgramDataPath, "Plugins") };
+
+ Logger.LoggerInstance = new FileLogger(Path.Combine(ProgramDataPath, "Logs"));
+ }
+
+ public virtual void Init()
+ {
+ ReloadConfiguration();
+
+ ReloadHttpServer();
+
+ ReloadPlugins();
+ }
+
+ /// <summary>
+ /// Gets the path to the application's ProgramDataFolder
+ /// </summary>
+ /// <returns></returns>
+ private 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;
+ }
+
+ private void ReloadConfiguration()
+ {
+ // Deserialize config
+ Configuration = GetConfiguration(ProgramDataPath);
+
+ Logger.LoggerInstance.LogSeverity = Configuration.LogSeverity;
+ }
+
+ private void ReloadHttpServer()
+ {
+ if (HttpServer != null)
+ {
+ HttpServer.Dispose();
+ }
+
+ HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/");
+ }
+
+ protected virtual void ReloadPlugins()
+ {
+ // Find plugins
+ PluginController.Init(KernelContext);
+ }
+
+ private static TConfigurationType GetConfiguration(string directory)
+ {
+ string file = Path.Combine(directory, "config.js");
+
+ if (!File.Exists(file))
+ {
+ return new TConfigurationType();
+ }
+
+ return JsonSerializer.DeserializeFromFile<TConfigurationType>(file);
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Kernel/KernelContext.cs b/MediaBrowser.Common/Kernel/KernelContext.cs new file mode 100644 index 000000000..6aa1e83bd --- /dev/null +++ b/MediaBrowser.Common/Kernel/KernelContext.cs @@ -0,0 +1,9 @@ +
+namespace MediaBrowser.Common.Kernel
+{
+ public enum KernelContext
+ {
+ Server,
+ UI
+ }
+}
diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs index 407c8baa7..51c6632d5 100644 --- a/MediaBrowser.Common/Logging/BaseLogger.cs +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -2,7 +2,6 @@ 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 d1e234250..39c69eb45 100644 --- a/MediaBrowser.Common/Logging/LogRow.cs +++ b/MediaBrowser.Common/Logging/LogRow.cs @@ -1,7 +1,6 @@ using System;
using System.Collections.Generic;
using System.Text;
-using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Logging
{
diff --git a/MediaBrowser.Model/Logging/LogSeverity.cs b/MediaBrowser.Common/Logging/LogSeverity.cs index bac03acdd..2abab1a44 100644 --- a/MediaBrowser.Model/Logging/LogSeverity.cs +++ b/MediaBrowser.Common/Logging/LogSeverity.cs @@ -1,6 +1,6 @@ using System;
-namespace MediaBrowser.Model.Logging
+namespace MediaBrowser.Common.Logging
{
[Flags]
public enum LogSeverity
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 252c9c8cc..1f68a3da7 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -34,7 +34,12 @@ <HintPath>..\packages\ServiceStack.Text.3.8.5\lib\net35\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.Configuration" />
<Reference Include="System.Core" />
+ <Reference Include="System.Reactive, Version=1.0.10621.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Rx-Main.1.0.11226\lib\Net4\System.Reactive.dll</HintPath>
+ </Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -42,9 +47,20 @@ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="ApiInteraction\ApiController.cs" />
+ <Compile Include="Configuration\BaseConfiguration.cs" />
<Compile Include="Events\GenericItemEventArgs.cs" />
<Compile Include="Json\JsonSerializer.cs" />
+ <Compile Include="Kernel\BaseKernel.cs" />
+ <Compile Include="Kernel\KernelContext.cs" />
+ <Compile Include="Logging\LogSeverity.cs" />
+ <Compile Include="Net\CollectionExtensions.cs" />
+ <Compile Include="Net\Handlers\BaseEmbeddedResourceHandler.cs" />
+ <Compile Include="Net\Handlers\BaseHandler.cs" />
+ <Compile Include="Net\Handlers\BaseJsonHandler.cs" />
+ <Compile Include="Net\HttpServer.cs" />
+ <Compile Include="Net\Request.cs" />
+ <Compile Include="Net\RequestContext.cs" />
+ <Compile Include="Net\StreamExtensions.cs" />
<Compile Include="Plugins\BasePluginConfiguration.cs" />
<Compile Include="Logging\BaseLogger.cs" />
<Compile Include="Logging\FileLogger.cs" />
@@ -63,6 +79,7 @@ <Name>MediaBrowser.Model</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/MediaBrowser.Net/CollectionExtensions.cs b/MediaBrowser.Common/Net/CollectionExtensions.cs index a6b59904f..98d24dfc0 100644 --- a/MediaBrowser.Net/CollectionExtensions.cs +++ b/MediaBrowser.Common/Net/CollectionExtensions.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Collections.Specialized;
using System.Linq;
-namespace MediaBrowser.Net
+namespace MediaBrowser.Common.Net
{
public static class CollectionExtensions
{
diff --git a/MediaBrowser.Net/Handlers/BaseEmbeddedResourceHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseEmbeddedResourceHandler.cs index d7f579d05..d8347db30 100644 --- a/MediaBrowser.Net/Handlers/BaseEmbeddedResourceHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseEmbeddedResourceHandler.cs @@ -1,7 +1,7 @@ using System;
using System.IO;
-namespace MediaBrowser.Net.Handlers
+namespace MediaBrowser.Common.Net.Handlers
{
public abstract class BaseEmbeddedResourceHandler : BaseHandler
{
diff --git a/MediaBrowser.Net/Handlers/BaseHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs index 7a2bcffe9..6f6779ad3 100644 --- a/MediaBrowser.Net/Handlers/BaseHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs @@ -4,7 +4,7 @@ using System.Collections.Specialized; using System.IO;
using System.IO.Compression;
-namespace MediaBrowser.Net.Handlers
+namespace MediaBrowser.Common.Net.Handlers
{
public abstract class BaseHandler
{
diff --git a/MediaBrowser.Net/Handlers/BaseJsonHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseJsonHandler.cs index 725b89c32..30113198b 100644 --- a/MediaBrowser.Net/Handlers/BaseJsonHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseJsonHandler.cs @@ -1,5 +1,5 @@
-namespace MediaBrowser.Net.Handlers
+namespace MediaBrowser.Common.Net.Handlers
{
public abstract class BaseJsonHandler : BaseHandler
{
diff --git a/MediaBrowser.Net/HttpServer.cs b/MediaBrowser.Common/Net/HttpServer.cs index aa24538d0..fad8d13eb 100644 --- a/MediaBrowser.Net/HttpServer.cs +++ b/MediaBrowser.Common/Net/HttpServer.cs @@ -2,7 +2,7 @@ using System; using System.Net;
using System.Reactive.Linq;
-namespace MediaBrowser.Net
+namespace MediaBrowser.Common.Net
{
public class HttpServer : IObservable<RequestContext>, IDisposable
{
diff --git a/MediaBrowser.Net/Request.cs b/MediaBrowser.Common/Net/Request.cs index 43f854233..795c9c36b 100644 --- a/MediaBrowser.Net/Request.cs +++ b/MediaBrowser.Common/Net/Request.cs @@ -2,7 +2,7 @@ using System.IO;
using System.Linq;
-namespace MediaBrowser.Net
+namespace MediaBrowser.Common.Net
{
public class Request
{
diff --git a/MediaBrowser.Net/RequestContext.cs b/MediaBrowser.Common/Net/RequestContext.cs index 4c1350701..5c7a6b99f 100644 --- a/MediaBrowser.Net/RequestContext.cs +++ b/MediaBrowser.Common/Net/RequestContext.cs @@ -1,9 +1,9 @@ using System;
using System.Linq;
using System.Net;
-using MediaBrowser.Net.Handlers;
+using MediaBrowser.Common.Net.Handlers;
-namespace MediaBrowser.Net
+namespace MediaBrowser.Common.Net
{
public class RequestContext
{
diff --git a/MediaBrowser.Net/StreamExtensions.cs b/MediaBrowser.Common/Net/StreamExtensions.cs index b4925cc7f..c10e458ad 100644 --- a/MediaBrowser.Net/StreamExtensions.cs +++ b/MediaBrowser.Common/Net/StreamExtensions.cs @@ -2,7 +2,7 @@ using System; using System.IO;
using System.Reactive.Linq;
-namespace MediaBrowser.Net
+namespace MediaBrowser.Common.Net
{
public static class StreamExtensions
{
diff --git a/MediaBrowser.Common/Plugins/PluginController.cs b/MediaBrowser.Common/Plugins/PluginController.cs index 9ce741ba1..1f83d485b 100644 --- a/MediaBrowser.Common/Plugins/PluginController.cs +++ b/MediaBrowser.Common/Plugins/PluginController.cs @@ -3,23 +3,45 @@ using System.Collections.Generic; using System.IO;
using System.Linq;
using System.Reflection;
+using System.Threading.Tasks;
+using MediaBrowser.Common.Kernel;
namespace MediaBrowser.Common.Plugins
{
+ /// <summary>
+ /// Manages Plugins within the PluginsPath directory
+ /// </summary>
public class PluginController
{
public string PluginsPath { get; set; }
- public PluginController(string pluginFolderPath)
+ /// <summary>
+ /// Gets the list of currently loaded plugins
+ /// </summary>
+ public IEnumerable<IPlugin> Plugins { get; private set; }
+
+ /// <summary>
+ /// Initializes the controller
+ /// </summary>
+ public void Init(KernelContext context)
{
- PluginsPath = pluginFolderPath;
+ AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
+ AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
+
+ Plugins = GetAllPlugins();
+
+ Parallel.For(0, Plugins.Count(), i =>
+ {
+ Plugins.ElementAt(i).Init();
+ });
}
- public IEnumerable<IPlugin> GetAllPlugins()
+ /// <summary>
+ /// Gets all plugins within PluginsPath
+ /// </summary>
+ /// <returns></returns>
+ private IEnumerable<IPlugin> GetAllPlugins()
{
- AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
- AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
-
if (!Directory.Exists(PluginsPath))
{
Directory.CreateDirectory(PluginsPath);
@@ -56,10 +78,10 @@ namespace MediaBrowser.Common.Plugins private IPlugin GetPluginFromDll(string path)
{
- return FindPlugin(Assembly.Load(File.ReadAllBytes(path)));
+ return GetPluginFromDll(Assembly.Load(File.ReadAllBytes(path)));
}
- private IPlugin FindPlugin(Assembly assembly)
+ private IPlugin GetPluginFromDll(Assembly assembly)
{
var plugin = assembly.GetTypes().Where(type => typeof(IPlugin).IsAssignableFrom(type)).FirstOrDefault();
diff --git a/MediaBrowser.Common/packages.config b/MediaBrowser.Common/packages.config index aad898882..15a978d36 100644 --- a/MediaBrowser.Common/packages.config +++ b/MediaBrowser.Common/packages.config @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="Rx-Main" version="1.0.11226" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.8.5" targetFramework="net45" />
</packages>
\ No newline at end of file diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs new file mode 100644 index 000000000..38b1b9caf --- /dev/null +++ b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs @@ -0,0 +1,16 @@ +using MediaBrowser.Common.Configuration;
+
+namespace MediaBrowser.Controller.Configuration
+{
+ public class ServerConfiguration : BaseConfiguration
+ {
+ public string ImagesByNamePath { get; set; }
+ public int RecentItemDays { get; set; }
+
+ public ServerConfiguration()
+ : base()
+ {
+ RecentItemDays = 14;
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 9cbef6874..0a5034859 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -5,33 +5,24 @@ using System.Linq; using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
-using MediaBrowser.Common.Json;
-using MediaBrowser.Common.Logging;
-using MediaBrowser.Common.Plugins;
+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;
-using MediaBrowser.Net;
namespace MediaBrowser.Controller
{
- public class Kernel
+ public class Kernel : BaseKernel<ServerConfiguration>
{
public static Kernel Instance { get; private set; }
- public string DataPath { get; private set; }
-
- public HttpServer HttpServer { get; private set; }
public ItemController ItemController { get; private set; }
public UserController UserController { get; private set; }
- public PluginController PluginController { get; private set; }
- public Configuration Configuration { get; private set; }
- public IEnumerable<IPlugin> Plugins { get; private set; }
public IEnumerable<User> Users { get; private set; }
public Folder RootFolder { get; private set; }
@@ -41,24 +32,20 @@ namespace MediaBrowser.Controller {
get
{
- return Path.Combine(DataPath, "Root");
+ return Path.Combine(ProgramDataPath, "Root");
}
}
/// <summary>
/// Creates a kernal based on a Data path, which is akin to our current programdata path
/// </summary>
- public Kernel(string dataPath)
+ public Kernel()
+ : base()
{
Instance = this;
- DataPath = dataPath;
-
- Logger.LoggerInstance = new FileLogger(Path.Combine(DataPath, "Logs"));
-
ItemController = new ItemController();
- UserController = new UserController(Path.Combine(DataPath, "Users"));
- PluginController = new PluginController(Path.Combine(DataPath, "Plugins"));
+ UserController = new UserController(Path.Combine(ProgramDataPath, "Users"));
DirectoryWatchers = new DirectoryWatchers();
ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath;
@@ -73,48 +60,15 @@ namespace MediaBrowser.Controller /// <summary>
/// Tells the kernel to start spinning up
/// </summary>
- public void Init()
+ public override void Init()
{
- ReloadConfiguration();
-
- ReloadHttpServer();
-
- LoadPlugins();
+ base.Init();
// Get users from users folder
// Load root media folder
Parallel.Invoke(ReloadUsers, ReloadRoot);
}
- private void ReloadConfiguration()
- {
- // Deserialize config
- Configuration = GetConfiguration(DataPath);
-
- Logger.LoggerInstance.LogSeverity = Configuration.LogSeverity;
- }
-
- private void LoadPlugins()
- {
- // Find plugins
- Plugins = PluginController.GetAllPlugins();
-
- Parallel.For(0, Plugins.Count(), i =>
- {
- Plugins.ElementAt(i).Init();
- });
- }
-
- private void ReloadHttpServer()
- {
- if (HttpServer != null)
- {
- HttpServer.Dispose();
- }
-
- HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/");
- }
-
/// <summary>
/// Registers a new BaseItem subclass
/// </summary>
@@ -192,18 +146,6 @@ namespace MediaBrowser.Controller }
}
- private static Configuration GetConfiguration(string directory)
- {
- string file = Path.Combine(directory, "config.js");
-
- if (!File.Exists(file))
- {
- return new Configuration();
- }
-
- return JsonSerializer.DeserializeFromFile<Configuration>(file);
- }
-
public void ReloadItem(BaseItem item)
{
Folder folder = item as Folder;
@@ -334,7 +276,7 @@ namespace MediaBrowser.Controller {
return false;
}
-
+
var userdata = GetUserItemData(userId, i.Id);
return userdata != null && userdata.PlaybackPosition.Ticks > 0;
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 1f57090a6..92a7e8107 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -42,6 +42,7 @@ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Configuration\ServerConfiguration.cs" />
<Compile Include="Events\ItemResolveEventArgs.cs" />
<Compile Include="IO\DirectoryWatchers.cs" />
<Compile Include="IO\Shortcut.cs" />
@@ -66,10 +67,6 @@ <Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
<Name>MediaBrowser.Model</Name>
</ProjectReference>
- <ProjectReference Include="..\MediaBrowser.Net\MediaBrowser.Net.csproj">
- <Project>{5da08d1c-0d52-4b1b-aa66-e4a171d938f6}</Project>
- <Name>MediaBrowser.Net</Name>
- </ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
diff --git a/MediaBrowser.HtmlBrowser/Handlers/EmbeddedResourceHandler.cs b/MediaBrowser.HtmlBrowser/Handlers/EmbeddedResourceHandler.cs index c62c6bbf6..8a118da2a 100644 --- a/MediaBrowser.HtmlBrowser/Handlers/EmbeddedResourceHandler.cs +++ b/MediaBrowser.HtmlBrowser/Handlers/EmbeddedResourceHandler.cs @@ -1,7 +1,6 @@ using System.IO;
using System.Reflection;
-using MediaBrowser.Net;
-using MediaBrowser.Net.Handlers;
+using MediaBrowser.Common.Net.Handlers;
namespace MediaBrowser.HtmlBrowser.Handlers
{
diff --git a/MediaBrowser.HtmlBrowser/MediaBrowser.HtmlBrowser.csproj b/MediaBrowser.HtmlBrowser/MediaBrowser.HtmlBrowser.csproj index b496e5697..219ec35c5 100644 --- a/MediaBrowser.HtmlBrowser/MediaBrowser.HtmlBrowser.csproj +++ b/MediaBrowser.HtmlBrowser/MediaBrowser.HtmlBrowser.csproj @@ -59,10 +59,6 @@ <Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
<Name>MediaBrowser.Model</Name>
</ProjectReference>
- <ProjectReference Include="..\MediaBrowser.Net\MediaBrowser.Net.csproj">
- <Project>{5da08d1c-0d52-4b1b-aa66-e4a171d938f6}</Project>
- <Name>MediaBrowser.Net</Name>
- </ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
diff --git a/MediaBrowser.HtmlBrowser/Plugin.cs b/MediaBrowser.HtmlBrowser/Plugin.cs index db3f72f6f..b8296492f 100644 --- a/MediaBrowser.HtmlBrowser/Plugin.cs +++ b/MediaBrowser.HtmlBrowser/Plugin.cs @@ -1,6 +1,6 @@ using System;
using System.Reactive.Linq;
-using MediaBrowser.Net.Handlers;
+using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.HtmlBrowser.Handlers;
diff --git a/MediaBrowser.Model/Configuration/Configuration.cs b/MediaBrowser.Model/Configuration/Configuration.cs deleted file mode 100644 index e7dc4b843..000000000 --- a/MediaBrowser.Model/Configuration/Configuration.cs +++ /dev/null @@ -1,19 +0,0 @@ -using MediaBrowser.Model.Logging;
-
-namespace MediaBrowser.Model.Configuration
-{
- public class Configuration
- {
- public string ImagesByNamePath { get; set; }
- public int HttpServerPortNumber { get; set; }
- public int RecentItemDays { get; set; }
- public LogSeverity LogSeverity { get; set; }
-
- public Configuration()
- {
- HttpServerPortNumber = 8096;
- RecentItemDays = 14;
- LogSeverity = LogSeverity.Info;
- }
- }
-}
diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index bcf8a8651..b41b54c0b 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -35,7 +35,6 @@ <!-- A reference to the entire .NET Framework is automatically included -->
</ItemGroup>
<ItemGroup>
- <Compile Include="Configuration\Configuration.cs" />
<Compile Include="Entities\ApiBaseItem.cs" />
<Compile Include="Entities\Audio.cs" />
<Compile Include="Entities\BaseItem.cs" />
@@ -46,7 +45,6 @@ <Compile Include="Entities\Studio.cs" />
<Compile Include="Entities\Video.cs" />
<Compile Include="Entities\Year.cs" />
- <Compile Include="Logging\LogSeverity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Users\User.cs" />
<Compile Include="Users\UserItemData.cs" />
diff --git a/MediaBrowser.Net/MediaBrowser.Net.csproj b/MediaBrowser.Net/MediaBrowser.Net.csproj deleted file mode 100644 index 6f1b7cccf..000000000 --- a/MediaBrowser.Net/MediaBrowser.Net.csproj +++ /dev/null @@ -1,66 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProjectGuid>{5DA08D1C-0D52-4B1B-AA66-E4A171D938F6}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>MediaBrowser.Net</RootNamespace>
- <AssemblyName>MediaBrowser.Net</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Reactive">
- <HintPath>..\packages\Rx-Main.1.0.11226\lib\Net4\System.Reactive.dll</HintPath>
- </Reference>
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="CollectionExtensions.cs" />
- <Compile Include="Handlers\BaseEmbeddedResourceHandler.cs" />
- <Compile Include="Handlers\BaseJsonHandler.cs" />
- <Compile Include="HttpServer.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Request.cs" />
- <Compile Include="RequestContext.cs" />
- <Compile Include="Handlers\BaseHandler.cs" />
- <Compile Include="StreamExtensions.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ 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 00964b6a2..000000000 --- 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/packages.config b/MediaBrowser.Net/packages.config deleted file mode 100644 index 47102a263..000000000 --- a/MediaBrowser.Net/packages.config +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="Rx-Main" version="1.0.11226" targetFramework="net45" />
-</packages>
\ No newline at end of file diff --git a/MediaBrowser.Program/App.config b/MediaBrowser.Program/App.config index 04df0f820..5aff9b350 100644 --- a/MediaBrowser.Program/App.config +++ b/MediaBrowser.Program/App.config @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
- <add key="DataPath" value="..\..\..\ProgramData" />
+ <add key="ProgramDataPath" value="..\..\..\ProgramData" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
diff --git a/MediaBrowser.Program/Program.cs b/MediaBrowser.Program/Program.cs index 1933ad126..ff7ad002f 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 23e78b42f..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.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
|
