Skip to content

Commit

Permalink
More DI
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Feb 24, 2013
1 parent 4c69cc5 commit 5c28f49
Show file tree
Hide file tree
Showing 101 changed files with 2,453 additions and 1,601 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using System.IO;
using System.Threading.Tasks;

namespace MediaBrowser.ApiInteraction.Javascript
namespace MediaBrowser.Api.Javascript
{
/// <summary>
/// Class GetJavascriptApiClient
/// </summary>
[Route("/JsApiClient.js", "GET")]
[Api(("Gets an api wrapper in Javascript"))]
[ServiceStack.ServiceHost.Api(("Gets an api wrapper in Javascript"))]
public class GetJavascriptApiClient
{
/// <summary>
Expand Down Expand Up @@ -52,7 +52,7 @@ public object Get(GetJavascriptApiClient request)
/// <returns>Stream.</returns>
private Task<Stream> GetStream()
{
return Task.FromResult(GetType().Assembly.GetManifestResourceStream("MediaBrowser.ApiInteraction.Javascript.ApiClient.js"));
return Task.FromResult(GetType().Assembly.GetManifestResourceStream("MediaBrowser.Api.Javascript.ApiClient.js"));
}
}
}
25 changes: 23 additions & 2 deletions MediaBrowser.Api/LibraryService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
Expand Down Expand Up @@ -97,6 +98,26 @@ public class GetDefaultVirtualFolders : IReturn<List<VirtualFolderInfo>>
/// </summary>
public class LibraryService : BaseRestService
{
/// <summary>
/// The _app host
/// </summary>
private readonly IApplicationHost _appHost;

/// <summary>
/// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary>
/// <param name="appHost">The app host.</param>
/// <exception cref="System.ArgumentNullException">appHost</exception>
public LibraryService(IApplicationHost appHost)
{
if (appHost == null)
{
throw new ArgumentNullException("appHost");
}

_appHost = appHost;
}

/// <summary>
/// Gets the specified request.
/// </summary>
Expand Down Expand Up @@ -210,7 +231,7 @@ public object Get(GetItemTypes request)
{
var kernel = (Kernel)Kernel;

var allTypes = kernel.AllTypes.Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(BaseItem)));
var allTypes = _appHost.AllConcreteTypes.Where(t => t.IsSubclassOf(typeof(BaseItem)));

if (request.HasInternetProvider)
{
Expand Down
2 changes: 2 additions & 0 deletions MediaBrowser.Api/MediaBrowser.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="Images\ImageService.cs" />
<Compile Include="Images\ImageWriter.cs" />
<Compile Include="Images\UploadImageHandler.cs" />
<Compile Include="Javascript\JavascriptApiClientService.cs" />
<Compile Include="LibraryService.cs" />
<Compile Include="LocalizationService.cs" />
<Compile Include="PackageService.cs" />
Expand Down Expand Up @@ -128,6 +129,7 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Javascript\ApiClient.js" />
<Content Include="options.xml" />
</ItemGroup>
<ItemGroup />
Expand Down
29 changes: 25 additions & 4 deletions MediaBrowser.Api/PluginService.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using ServiceStack.ServiceHost;
using ServiceStack.Text.Controller;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ServiceStack.Text.Controller;

namespace MediaBrowser.Api
{
Expand Down Expand Up @@ -119,6 +119,27 @@ public class UpdatePluginSecurityInfo : IReturnVoid, IRequiresRequestStream
/// </summary>
public class PluginService : BaseRestService
{
/// <summary>
/// The _json serializer
/// </summary>
private readonly IJsonSerializer _jsonSerializer;

/// <summary>
/// Initializes a new instance of the <see cref="PluginService" /> class.
/// </summary>
/// <param name="jsonSerializer">The json serializer.</param>
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
public PluginService(IJsonSerializer jsonSerializer)
: base()
{
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}

_jsonSerializer = jsonSerializer;
}

/// <summary>
/// Gets the specified request.
/// </summary>
Expand Down Expand Up @@ -198,7 +219,7 @@ public void Post(UpdatePluginSecurityInfo request)
{
var kernel = (Kernel)Kernel;

var info = JsonSerializer.DeserializeFromStream<PluginSecurityInfo>(request.RequestStream);
var info = _jsonSerializer.DeserializeFromStream<PluginSecurityInfo>(request.RequestStream);

kernel.PluginSecurityManager.SupporterKey = info.SupporterKey;
kernel.PluginSecurityManager.LegacyKey = info.LegacyKey;
Expand All @@ -217,7 +238,7 @@ public void Post(UpdatePluginConfiguration request)

var plugin = Kernel.Plugins.First(p => p.Id == id);

var configuration = JsonSerializer.DeserializeFromStream(request.RequestStream, plugin.ConfigurationType) as BasePluginConfiguration;
var configuration = _jsonSerializer.DeserializeFromStream(request.RequestStream, plugin.ConfigurationType) as BasePluginConfiguration;

plugin.UpdateConfiguration(configuration);
}
Expand Down
33 changes: 29 additions & 4 deletions MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Tasks;
using ServiceStack.ServiceHost;
using System;
Expand Down Expand Up @@ -90,11 +90,32 @@ public class ScheduledTaskService : BaseRestService
/// <value>The task manager.</value>
private ITaskManager TaskManager { get; set; }

public ScheduledTaskService(ITaskManager taskManager)
/// <summary>
/// The _json serializer
/// </summary>
private readonly IJsonSerializer _jsonSerializer;

/// <summary>
/// Initializes a new instance of the <see cref="ScheduledTaskService" /> class.
/// </summary>
/// <param name="taskManager">The task manager.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <exception cref="System.ArgumentNullException">taskManager</exception>
public ScheduledTaskService(ITaskManager taskManager, IJsonSerializer jsonSerializer)
{
if (taskManager == null)
{
throw new ArgumentNullException("taskManager");
}
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}

TaskManager = taskManager;
_jsonSerializer = jsonSerializer;
}

/// <summary>
/// Gets the specified request.
/// </summary>
Expand All @@ -113,6 +134,7 @@ public object Get(GetScheduledTasks request)
/// </summary>
/// <param name="request">The request.</param>
/// <returns>IEnumerable{TaskInfo}.</returns>
/// <exception cref="MediaBrowser.Common.Extensions.ResourceNotFoundException">Task not found</exception>
public object Get(GetScheduledTask request)
{
var task = TaskManager.ScheduledTasks.FirstOrDefault(i => i.Id == request.Id);
Expand All @@ -131,6 +153,7 @@ public object Get(GetScheduledTask request)
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <exception cref="MediaBrowser.Common.Extensions.ResourceNotFoundException">Task not found</exception>
public void Post(StartScheduledTask request)
{
var task = TaskManager.ScheduledTasks.FirstOrDefault(i => i.Id == request.Id);
Expand All @@ -147,6 +170,7 @@ public void Post(StartScheduledTask request)
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <exception cref="MediaBrowser.Common.Extensions.ResourceNotFoundException">Task not found</exception>
public void Delete(StopScheduledTask request)
{
var task = TaskManager.ScheduledTasks.FirstOrDefault(i => i.Id == request.Id);
Expand All @@ -163,6 +187,7 @@ public void Delete(StopScheduledTask request)
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <exception cref="MediaBrowser.Common.Extensions.ResourceNotFoundException">Task not found</exception>
public void Post(UpdateScheduledTaskTriggers request)
{
// We need to parse this manually because we told service stack not to with IRequiresRequestStream
Expand All @@ -177,7 +202,7 @@ public void Post(UpdateScheduledTaskTriggers request)
throw new ResourceNotFoundException("Task not found");
}

var triggerInfos = JsonSerializer.DeserializeFromStream<TaskTriggerInfo[]>(request.RequestStream);
var triggerInfos = _jsonSerializer.DeserializeFromStream<TaskTriggerInfo[]>(request.RequestStream);

task.Triggers = triggerInfos.Select(ScheduledTaskHelpers.GetTrigger);
}
Expand Down
35 changes: 32 additions & 3 deletions MediaBrowser.Api/SystemService.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Controller;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.System;
using ServiceStack.ServiceHost;
using System;
using System.IO;
using System.Threading.Tasks;

namespace MediaBrowser.Api
{
/// <summary>
/// Class GetSystemInfo
/// </summary>
[Route("/System/Info", "GET")]
public class GetSystemInfo : IReturn<SystemInfo>
{
Expand Down Expand Up @@ -40,6 +44,10 @@ public class GetConfiguration : IReturn<ServerConfiguration>
[Route("/System/Configuration", "POST")]
public class UpdateConfiguration : IRequiresRequestStream
{
/// <summary>
/// The raw Http Request Input Stream
/// </summary>
/// <value>The request stream.</value>
public Stream RequestStream { get; set; }
}

Expand All @@ -48,6 +56,27 @@ public class UpdateConfiguration : IRequiresRequestStream
/// </summary>
public class SystemService : BaseRestService
{
/// <summary>
/// The _json serializer
/// </summary>
private readonly IJsonSerializer _jsonSerializer;

/// <summary>
/// Initializes a new instance of the <see cref="SystemService" /> class.
/// </summary>
/// <param name="jsonSerializer">The json serializer.</param>
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
public SystemService(IJsonSerializer jsonSerializer)
: base()
{
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}

_jsonSerializer = jsonSerializer;
}

/// <summary>
/// Gets the specified request.
/// </summary>
Expand Down Expand Up @@ -95,8 +124,8 @@ public void Post(RestartApplication request)
/// <param name="request">The request.</param>
public void Post(UpdateConfiguration request)
{
var serverConfig = JsonSerializer.DeserializeFromStream<ServerConfiguration>(request.RequestStream);
var serverConfig = _jsonSerializer.DeserializeFromStream<ServerConfiguration>(request.RequestStream);

var kernel = (Kernel)Kernel;

kernel.UpdateConfiguration(serverConfig);
Expand Down
Loading

0 comments on commit 5c28f49

Please sign in to comment.