Added a BaseKernel for the UI and Server to share, and made some other minor re-organizations.
This commit is contained in:
parent
3f55707755
commit
0a48b5e31a
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using MediaBrowser.Net.Handlers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.IO;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using MediaBrowser.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using MediaBrowser.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
19
MediaBrowser.Common/Configuration/BaseConfiguration.cs
Normal file
19
MediaBrowser.Common/Configuration/BaseConfiguration.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
130
MediaBrowser.Common/Kernel/BaseKernel.cs
Normal file
130
MediaBrowser.Common/Kernel/BaseKernel.cs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
9
MediaBrowser.Common/Kernel/KernelContext.cs
Normal file
9
MediaBrowser.Common/Kernel/KernelContext.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
namespace MediaBrowser.Common.Kernel
|
||||
{
|
||||
public enum KernelContext
|
||||
{
|
||||
Server,
|
||||
UI
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.Common.Logging
|
||||
{
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.Common.Logging
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
|
||||
namespace MediaBrowser.Model.Logging
|
||||
namespace MediaBrowser.Common.Logging
|
||||
{
|
||||
[Flags]
|
||||
public enum LogSeverity
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
{
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MediaBrowser.Net.Handlers
|
||||
namespace MediaBrowser.Common.Net.Handlers
|
||||
{
|
||||
public abstract class BaseEmbeddedResourceHandler : BaseHandler
|
||||
{
|
|
@ -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
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
namespace MediaBrowser.Net.Handlers
|
||||
namespace MediaBrowser.Common.Net.Handlers
|
||||
{
|
||||
public abstract class BaseJsonHandler : BaseHandler
|
||||
{
|
|
@ -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
|
||||
{
|
|
@ -2,7 +2,7 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Net
|
||||
namespace MediaBrowser.Common.Net
|
||||
{
|
||||
public class Request
|
||||
{
|
|
@ -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
|
||||
{
|
|
@ -2,7 +2,7 @@ using System;
|
|||
using System.IO;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace MediaBrowser.Net
|
||||
namespace MediaBrowser.Common.Net
|
||||
{
|
||||
public static class StreamExtensions
|
||||
{
|
|
@ -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)
|
||||
{
|
||||
PluginsPath = pluginFolderPath;
|
||||
}
|
||||
|
||||
public IEnumerable<IPlugin> GetAllPlugins()
|
||||
/// <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)
|
||||
{
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all plugins within PluginsPath
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<IPlugin> GetAllPlugins()
|
||||
{
|
||||
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();
|
||||
|
||||
|
|
|
@ -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>
|
16
MediaBrowser.Controller/Configuration/ServerConfiguration.cs
Normal file
16
MediaBrowser.Controller/Configuration/ServerConfiguration.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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" />
|
||||
|
|
|
@ -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>
|
|
@ -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")]
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Rx-Main" version="1.0.11226" targetFramework="net45" />
|
||||
</packages>
|
|
@ -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" />
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user