Skip to content

Commit

Permalink
deprecate IMemoryStreamFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed May 15, 2018
1 parent d5f4d57 commit 389e387
Show file tree
Hide file tree
Showing 109 changed files with 2,664 additions and 2,388 deletions.
24 changes: 5 additions & 19 deletions Emby.Dlna/Api/DlnaServerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,16 @@ public class DlnaServerService : IService, IRequiresRequest
private readonly IMediaReceiverRegistrar _mediaReceiverRegistrar;

private const string XMLContentType = "text/xml; charset=UTF-8";
private readonly IMemoryStreamFactory _memoryStreamProvider;

public IRequest Request { get; set; }
private IHttpResultFactory _resultFactory;

public DlnaServerService(IDlnaManager dlnaManager, IHttpResultFactory httpResultFactory, IContentDirectory contentDirectory, IConnectionManager connectionManager, IMediaReceiverRegistrar mediaReceiverRegistrar, IMemoryStreamFactory memoryStreamProvider)
public DlnaServerService(IDlnaManager dlnaManager, IHttpResultFactory httpResultFactory, IContentDirectory contentDirectory, IConnectionManager connectionManager, IMediaReceiverRegistrar mediaReceiverRegistrar)
{
_dlnaManager = dlnaManager;
_contentDirectory = contentDirectory;
_connectionManager = connectionManager;
_mediaReceiverRegistrar = mediaReceiverRegistrar;
_memoryStreamProvider = memoryStreamProvider;
_resultFactory = httpResultFactory;
}

Expand Down Expand Up @@ -236,24 +234,12 @@ private List<string> Parse(string pathUri)

public object Get(GetIcon request)
{
using (var response = _dlnaManager.GetIcon(request.Filename))
{
using (var ms = new MemoryStream())
{
response.Stream.CopyTo(ms);

ms.Position = 0;
var bytes = ms.ToArray();

var contentType = "image/" + response.Format.ToString().ToLower();
var contentType = "image/" + Path.GetExtension(request.Filename).TrimStart('.').ToLower();

var cacheLength = TimeSpan.FromDays(365);
var cacheKey = Request.RawUrl.GetMD5();
var cacheLength = TimeSpan.FromDays(365);
var cacheKey = Request.RawUrl.GetMD5();

return _resultFactory.GetStaticResult(Request, cacheKey, null, cacheLength, contentType, ()=> Task.FromResult<Stream>(new MemoryStream(bytes)));
//return ResultFactory.GetResult(bytes, contentType);
}
}
return _resultFactory.GetStaticResult(Request, cacheKey, null, cacheLength, contentType, () => Task.FromResult<Stream>(_dlnaManager.GetIcon(request.Filename).Stream));
}

public object Subscribe(ProcessContentDirectoryEventRequest request)
Expand Down
2 changes: 1 addition & 1 deletion Emby.Dlna/Didl/DidlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int maxWidth, int maxHe
Height = height.Value,
Width = width.Value

}, null, null, maxWidth, maxHeight);
}, 0, 0, maxWidth, maxHeight);

width = Convert.ToInt32(newSize.Width);
height = Convert.ToInt32(newSize.Height);
Expand Down
34 changes: 21 additions & 13 deletions Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
Expand Down Expand Up @@ -269,7 +270,6 @@ public virtual string OperatingSystemDisplayName
protected readonly SimpleInjector.Container Container = new SimpleInjector.Container();

protected ISystemEvents SystemEvents { get; set; }
protected IMemoryStreamFactory MemoryStreamFactory { get; set; }

/// <summary>
/// Gets the server configuration manager.
Expand Down Expand Up @@ -429,7 +429,6 @@ public ApplicationHost(ServerApplicationPaths applicationPaths,
networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets;
EnvironmentInfo = environmentInfo;
SystemEvents = systemEvents;
MemoryStreamFactory = new MemoryStreamProvider();

ApplicationPaths = applicationPaths;
LogManager = logManager;
Expand Down Expand Up @@ -526,6 +525,11 @@ private Tuple<Assembly, string> GetAssembly(Type type)
return new Tuple<Assembly, string>(assembly, path);
}

public virtual IStreamHelper CreateStreamHelper()
{
return new StreamHelper();
}

public virtual bool SupportsAutoRunAtStartup
{
get
Expand Down Expand Up @@ -859,9 +863,11 @@ protected virtual void OnLoggerLoaded(bool isFirstLoad)

protected virtual IHttpClient CreateHttpClient()
{
return new HttpClientManager.HttpClientManager(ApplicationPaths, LogManager.GetLogger("HttpClient"), FileSystemManager, MemoryStreamFactory, GetDefaultUserAgent);
return new HttpClientManager.HttpClientManager(ApplicationPaths, LogManager.GetLogger("HttpClient"), FileSystemManager, GetDefaultUserAgent);
}

public static IStreamHelper StreamHelper { get; set; }

/// <summary>
/// Registers resources that classes will depend on
/// </summary>
Expand All @@ -873,7 +879,6 @@ protected void RegisterResources()
RegisterSingleInstance<IApplicationPaths>(ApplicationPaths);

RegisterSingleInstance(JsonSerializer);
RegisterSingleInstance(MemoryStreamFactory);
RegisterSingleInstance(SystemEvents);

RegisterSingleInstance(LogManager, false);
Expand Down Expand Up @@ -902,6 +907,10 @@ protected void RegisterResources()
TimerFactory = new TimerFactory();
RegisterSingleInstance(TimerFactory);

var streamHelper = CreateStreamHelper();
ApplicationHost.StreamHelper = streamHelper;
RegisterSingleInstance(streamHelper);

RegisterSingleInstance(CryptographyProvider);

SocketFactory = new SocketFactory(LogManager.GetLogger("SocketFactory"));
Expand All @@ -918,7 +927,7 @@ protected void RegisterResources()
ZipClient = new ZipClient(FileSystemManager);
RegisterSingleInstance(ZipClient);

HttpResultFactory = new HttpResultFactory(LogManager, FileSystemManager, JsonSerializer, MemoryStreamFactory);
HttpResultFactory = new HttpResultFactory(LogManager, FileSystemManager, JsonSerializer);
RegisterSingleInstance(HttpResultFactory);

RegisterSingleInstance<IServerApplicationHost>(this);
Expand Down Expand Up @@ -947,11 +956,11 @@ protected void RegisterResources()
// This is only needed for disposal purposes. If removing this, make sure to have the manager handle disposing it
RegisterSingleInstance(UserRepository);

var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager.GetLogger("SqliteDisplayPreferencesRepository"), JsonSerializer, ApplicationPaths, MemoryStreamFactory, FileSystemManager);
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager.GetLogger("SqliteDisplayPreferencesRepository"), JsonSerializer, ApplicationPaths, FileSystemManager);
DisplayPreferencesRepository = displayPreferencesRepo;
RegisterSingleInstance(DisplayPreferencesRepository);

var itemRepo = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LogManager.GetLogger("SqliteItemRepository"), MemoryStreamFactory, assemblyInfo, FileSystemManager, EnvironmentInfo, TimerFactory);
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LogManager.GetLogger("SqliteItemRepository"), assemblyInfo, FileSystemManager, EnvironmentInfo, TimerFactory);
ItemRepository = itemRepo;
RegisterSingleInstance(ItemRepository);

Expand All @@ -975,11 +984,11 @@ protected void RegisterResources()
CertificateInfo = GetCertificateInfo(true);
Certificate = GetCertificate(CertificateInfo);

HttpServer = HttpServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, MemoryStreamFactory, "Emby", "web/index.html", textEncoding, SocketFactory, CryptographyProvider, JsonSerializer, XmlSerializer, EnvironmentInfo, Certificate, FileSystemManager, SupportsDualModeSockets);
HttpServer = HttpServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, streamHelper, "Emby", "web/index.html", textEncoding, SocketFactory, CryptographyProvider, JsonSerializer, XmlSerializer, EnvironmentInfo, Certificate, FileSystemManager, SupportsDualModeSockets);
HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
RegisterSingleInstance(HttpServer, false);

ServerManager = new ServerManager.ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager, MemoryStreamFactory, textEncoding);
ServerManager = new ServerManager.ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager, textEncoding);
RegisterSingleInstance(ServerManager);

ImageProcessor = GetImageProcessor();
Expand Down Expand Up @@ -1012,7 +1021,7 @@ protected void RegisterResources()
SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, MediaSourceManager, ServerConfigurationManager, LocalizationManager);
RegisterSingleInstance(SubtitleManager);

ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer, MemoryStreamFactory);
ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer);
RegisterSingleInstance(ProviderManager);

DtoService = new DtoService(LogManager.GetLogger("DtoService"), LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager, SyncManager, this, () => DeviceManager, () => MediaSourceManager, () => LiveTvManager);
Expand Down Expand Up @@ -1072,7 +1081,7 @@ protected void RegisterResources()
AuthService = new AuthService(UserManager, authContext, ServerConfigurationManager, ConnectManager, SessionManager, NetworkManager);
RegisterSingleInstance<IAuthService>(AuthService);

SubtitleEncoder = new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager, MemoryStreamFactory, ProcessFactory, textEncoding);
SubtitleEncoder = new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager, ProcessFactory, textEncoding);
RegisterSingleInstance(SubtitleEncoder);

RegisterSingleInstance(CreateResourceFileManager());
Expand Down Expand Up @@ -1289,7 +1298,6 @@ private void RegisterMediaEncoder(IAssemblyInfo assemblyInfo)
() => MediaSourceManager,
HttpClient,
ZipClient,
MemoryStreamFactory,
ProcessFactory,
(Environment.ProcessorCount > 2 ? 14000 : 40000),
EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows,
Expand All @@ -1307,7 +1315,7 @@ private void RegisterMediaEncoder(IAssemblyInfo assemblyInfo)
/// <returns>Task{IUserRepository}.</returns>
private IUserRepository GetUserRepository()
{
var repo = new SqliteUserRepository(LogManager.GetLogger("SqliteUserRepository"), ApplicationPaths, JsonSerializer, MemoryStreamFactory);
var repo = new SqliteUserRepository(LogManager.GetLogger("SqliteUserRepository"), ApplicationPaths, JsonSerializer);

repo.Initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ namespace Emby.Server.Implementations.Data
/// </summary>
public class SqliteDisplayPreferencesRepository : BaseSqliteRepository, IDisplayPreferencesRepository
{
private readonly IMemoryStreamFactory _memoryStreamProvider;
protected IFileSystem FileSystem { get; private set; }

public SqliteDisplayPreferencesRepository(ILogger logger, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IMemoryStreamFactory memoryStreamProvider, IFileSystem fileSystem)
public SqliteDisplayPreferencesRepository(ILogger logger, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IFileSystem fileSystem)
: base(logger)
{
_jsonSerializer = jsonSerializer;
_memoryStreamProvider = memoryStreamProvider;
FileSystem = fileSystem;
DbFilePath = Path.Combine(appPaths.DataPath, "displaypreferences.db");
}
Expand Down Expand Up @@ -119,7 +117,7 @@ public void SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid u

private void SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, IDatabaseConnection connection)
{
var serialized = _jsonSerializer.SerializeToBytes(displayPreferences, _memoryStreamProvider);
var serialized = _jsonSerializer.SerializeToBytes(displayPreferences);

using (var statement = connection.PrepareStatement("replace into userdisplaypreferences (id, userid, client, data) values (@id, @userId, @client, @data)"))
{
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Data/SqliteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static DateTime ReadDateTime(this IResultSetValue result)
/// </summary>
/// <returns>System.Byte[][].</returns>
/// <exception cref="System.ArgumentNullException">obj</exception>
public static byte[] SerializeToBytes(this IJsonSerializer json, object obj, IMemoryStreamFactory streamProvider)
public static byte[] SerializeToBytes(this IJsonSerializer json, object obj)
{
if (obj == null)
{
Expand Down
Loading

0 comments on commit 389e387

Please sign in to comment.