make media encoding project portable

This commit is contained in:
Luke Pulverenti
2016-11-01 00:07:12 -04:00
parent 13d8110ce2
commit b1276dc208
23 changed files with 444 additions and 214 deletions

View File

@@ -27,11 +27,16 @@ using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Extensions;
using Emby.Common.Implementations.Cryptography;
using Emby.Common.Implementations.Diagnostics;
using Emby.Common.Implementations.Threading;
using MediaBrowser.Common;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Diagnostics;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Threading;
#if NETSTANDARD1_6
using System.Runtime.Loader;
#endif
@@ -146,6 +151,9 @@ namespace Emby.Common.Implementations
protected ISystemEvents SystemEvents { get; private set; }
protected IProcessFactory ProcessFactory { get; private set; }
protected ITimerFactory TimerFactory { get; private set; }
/// <summary>
/// Gets the name.
/// </summary>
@@ -535,6 +543,12 @@ return null;
IsoManager = new IsoManager();
RegisterSingleInstance(IsoManager);
ProcessFactory = new ProcessFactory();
RegisterSingleInstance(ProcessFactory);
TimerFactory = new TimerFactory();
RegisterSingleInstance(TimerFactory);
return Task.FromResult(true);
}

View File

@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Model.Diagnostics;
namespace Emby.Common.Implementations.Diagnostics
{
public class CommonProcess : IProcess
{
public event EventHandler Exited;
private readonly ProcessOptions _options;
private readonly Process _process;
public CommonProcess(ProcessOptions options)
{
_options = options;
var startInfo = new ProcessStartInfo
{
Arguments = options.Arguments,
FileName = options.FileName,
WorkingDirectory = options.WorkingDirectory,
UseShellExecute = options.UseShellExecute,
CreateNoWindow = options.CreateNoWindow,
RedirectStandardError = options.RedirectStandardError,
RedirectStandardInput = options.RedirectStandardInput,
RedirectStandardOutput = options.RedirectStandardOutput
};
#if NET46
startInfo.ErrorDialog = options.ErrorDialog;
if (options.IsHidden)
{
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
}
#endif
_process = new Process
{
StartInfo = startInfo
};
if (options.EnableRaisingEvents)
{
_process.EnableRaisingEvents = true;
_process.Exited += _process_Exited;
}
}
private void _process_Exited(object sender, EventArgs e)
{
if (Exited != null)
{
Exited(_process, e);
}
}
public ProcessOptions StartInfo
{
get { return _options; }
}
public StreamWriter StandardInput
{
get { return _process.StandardInput; }
}
public StreamReader StandardError
{
get { return _process.StandardError; }
}
public StreamReader StandardOutput
{
get { return _process.StandardOutput; }
}
public int ExitCode
{
get { return _process.ExitCode; }
}
public void Start()
{
_process.Start();
}
public void Kill()
{
_process.Kill();
}
public bool WaitForExit(int timeMs)
{
return _process.WaitForExit(timeMs);
}
public void Dispose()
{
_process.Dispose();
}
}
}

View File

@@ -0,0 +1,12 @@
using MediaBrowser.Model.Diagnostics;
namespace Emby.Common.Implementations.Diagnostics
{
public class ProcessFactory : IProcessFactory
{
public IProcess Create(ProcessOptions options)
{
return new CommonProcess(options);
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Threading;
namespace Emby.Common.Implementations.Threading
{
public class CommonTimer : ITimer
{
private readonly Timer _timer;
public CommonTimer(Action<object> callback, object state, TimeSpan dueTime, TimeSpan period)
{
_timer = new Timer(new TimerCallback(callback), state, dueTime, period);
}
public CommonTimer(Action<object> callback, object state, int dueTimeMs, int periodMs)
{
_timer = new Timer(new TimerCallback(callback), state, dueTimeMs, periodMs);
}
public void Change(TimeSpan dueTime, TimeSpan period)
{
_timer.Change(dueTime, period);
}
public void Change(int dueTimeMs, int periodMs)
{
_timer.Change(dueTimeMs, periodMs);
}
public void Dispose()
{
_timer.Dispose();
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Model.Threading;
namespace Emby.Common.Implementations.Threading
{
public class TimerFactory : ITimerFactory
{
public ITimer Create(Action<object> callback, object state, TimeSpan dueTime, TimeSpan period)
{
return new CommonTimer(callback, state, dueTime, period);
}
public ITimer Create(Action<object> callback, object state, int dueTimeMs, int periodMs)
{
return new CommonTimer(callback, state, dueTimeMs, periodMs);
}
}
}

View File

@@ -44,6 +44,8 @@
"target": "project"
},
"System.IO.FileSystem.DriveInfo": "4.0.0",
"System.Diagnostics.Process": "4.1.0",
"System.Threading.Timer": "4.0.1",
"System.Net.Requests": "4.0.11",
"System.Xml.XmlSerializer": "4.0.11",
"System.Net.Http": "4.1.0",