diff options
| author | Erwin de Haan <EraYaN@users.noreply.github.com> | 2019-01-06 21:50:43 +0100 |
|---|---|---|
| committer | Erwin de Haan <EraYaN@users.noreply.github.com> | 2019-01-10 20:38:53 +0100 |
| commit | ec1f5dc317182582ebff843c9e8a4d5277405469 (patch) | |
| tree | 6514de336cc9aa94becb3fbd767285dfa61d0b1b /Emby.Server.Implementations/LiveTv/TunerHosts | |
| parent | 3d867c2c46cec39b669bb8647efef677f32b8a8d (diff) | |
Mayor code cleanup
Add Argument*Exceptions now use proper nameof operators.
Added exception messages to quite a few Argument*Exceptions.
Fixed rethorwing to be proper syntax.
Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling)
Added some TODOs to log certain exceptions.
Fix sln again.
Fixed all AssemblyInfo's and added proper copyright (where I could find them)
We live in *current year*.
Fixed the use of braces.
Fixed a ton of properties, and made a fair amount of functions static that should be and can be static.
Made more Methods that should be static static.
You can now use static to find bad functions!
Removed unused variable. And added one more proper XML comment.
Diffstat (limited to 'Emby.Server.Implementations/LiveTv/TunerHosts')
7 files changed, 51 insertions, 119 deletions
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs index ef2010ba64..78514c1d94 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs @@ -40,13 +40,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts FileSystem = fileSystem; } - public virtual bool IsSupported - { - get - { - return true; - } - } + public virtual bool IsSupported => true; protected abstract Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken); public abstract string Type { get; } @@ -140,7 +134,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { if (string.IsNullOrEmpty(channelId)) { - throw new ArgumentNullException("channelId"); + throw new ArgumentNullException(nameof(channelId)); } if (IsValidChannelId(channelId)) @@ -175,7 +169,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { if (string.IsNullOrEmpty(channelId)) { - throw new ArgumentNullException("channelId"); + throw new ArgumentNullException(nameof(channelId)); } if (!IsValidChannelId(channelId)) @@ -228,18 +222,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts throw new LiveTvConflictException(); } - protected virtual string ChannelIdPrefix - { - get - { - return Type + "_"; - } - } + protected virtual string ChannelIdPrefix => Type + "_"; + protected virtual bool IsValidChannelId(string channelId) { if (string.IsNullOrEmpty(channelId)) { - throw new ArgumentNullException("channelId"); + throw new ArgumentNullException(nameof(channelId)); } return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index be090df0c9..3ae47f3abe 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Dto; @@ -42,28 +42,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun _environment = environment; } - public string Name - { - get { return "HD Homerun"; } - } + public string Name => "HD Homerun"; - public override string Type - { - get { return DeviceType; } - } + public override string Type => DeviceType; - public static string DeviceType - { - get { return "hdhomerun"; } - } + public static string DeviceType => "hdhomerun"; - protected override string ChannelIdPrefix - { - get - { - return "hdhr_"; - } - } + protected override string ChannelIdPrefix => "hdhr_"; private string GetChannelId(TunerHostInfo info, Channels i) { @@ -274,7 +259,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun for (int i = 0; i < model.TunerCount; ++i) { - var name = String.Format("Tuner {0}", i + 1); + var name = string.Format("Tuner {0}", i + 1); var currentChannel = "none"; /// @todo Get current channel and map back to Station Id var isAvailable = await manager.CheckTunerAvailability(ipInfo, i, cancellationToken).ConfigureAwait(false); LiveTvTunerStatus status = isAvailable ? LiveTvTunerStatus.Available : LiveTvTunerStatus.LiveTv; @@ -325,7 +310,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun return await GetTunerInfosHttp(info, cancellationToken).ConfigureAwait(false); } - private string GetApiUrl(TunerHostInfo info) + private static string GetApiUrl(TunerHostInfo info) { var url = info.Url; @@ -359,7 +344,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun return Config.GetConfiguration<EncodingOptions>("encoding"); } - private string GetHdHrIdFromChannelId(string channelId) + private static string GetHdHrIdFromChannelId(string channelId) { return channelId.Split('_')[1]; } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs index 0e84622bda..335fc4cb48 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs @@ -37,10 +37,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { var commands = new List<Tuple<string, string>>(); - if (!String.IsNullOrEmpty(_channel)) + if (!string.IsNullOrEmpty(_channel)) commands.Add(Tuple.Create("channel", _channel)); - if (!String.IsNullOrEmpty(_program)) + if (!string.IsNullOrEmpty(_program)) commands.Add(Tuple.Create("program", _program)); return commands; } @@ -61,11 +61,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { var commands = new List<Tuple<string, string>>(); - if (!String.IsNullOrEmpty(_channel)) + if (!string.IsNullOrEmpty(_channel)) { if (!string.IsNullOrEmpty(_profile) && !string.Equals(_profile, "native", StringComparison.OrdinalIgnoreCase)) { - commands.Add(Tuple.Create("vchannel", String.Format("{0} transcode={1}", _channel, _profile))); + commands.Add(Tuple.Create("vchannel", string.Format("{0} transcode={1}", _channel, _profile))); } else { @@ -123,7 +123,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } } - private async Task<bool> CheckTunerAvailability(ISocket socket, IpAddressInfo remoteIp, int tuner, CancellationToken cancellationToken) + private static async Task<bool> CheckTunerAvailability(ISocket socket, IpAddressInfo remoteIp, int tuner, CancellationToken cancellationToken) { var ipEndPoint = new IpEndPointInfo(remoteIp, HdHomeRunPort); @@ -164,7 +164,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun continue; _activeTuner = i; - var lockKeyString = String.Format("{0:d}", lockKeyValue); + var lockKeyString = string.Format("{0:d}", lockKeyValue); var lockkeyMsg = CreateSetMessage(i, "lockkey", lockKeyString, null); await tcpClient.SendToAsync(lockkeyMsg, 0, lockkeyMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false); var response = await tcpClient.ReceiveAsync(receiveBuffer, 0, receiveBuffer.Length, cancellationToken).ConfigureAwait(false); @@ -188,7 +188,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } - var targetValue = String.Format("rtp://{0}:{1}", localIp, localPort); + var targetValue = string.Format("rtp://{0}:{1}", localIp, localPort); var targetMsg = CreateSetMessage(i, "target", targetValue, lockKeyValue); await tcpClient.SendToAsync(targetMsg, 0, targetMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false); @@ -262,7 +262,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun private static byte[] CreateGetMessage(int tuner, string name) { - var byteName = Encoding.UTF8.GetBytes(String.Format("/tuner{0}/{1}\0", tuner, name)); + var byteName = Encoding.UTF8.GetBytes(string.Format("/tuner{0}/{1}\0", tuner, name)); int messageLength = byteName.Length + 10; // 4 bytes for header + 4 bytes for crc + 2 bytes for tag name and length var message = new byte[messageLength]; @@ -280,10 +280,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun return message; } - private static byte[] CreateSetMessage(int tuner, String name, String value, uint? lockkey) + private static byte[] CreateSetMessage(int tuner, string name, string value, uint? lockkey) { - var byteName = Encoding.UTF8.GetBytes(String.Format("/tuner{0}/{1}\0", tuner, name)); - var byteValue = Encoding.UTF8.GetBytes(String.Format("{0}\0", value)); + var byteName = Encoding.UTF8.GetBytes(string.Format("/tuner{0}/{1}\0", tuner, name)); + var byteValue = Encoding.UTF8.GetBytes(string.Format("{0}\0", value)); int messageLength = byteName.Length + byteValue.Length + 12; if (lockkey.HasValue) @@ -360,7 +360,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun private static bool ParseReturnMessage(byte[] buf, int numBytes, out string returnVal) { - returnVal = String.Empty; + returnVal = string.Empty; if (numBytes < 4) return false; @@ -411,7 +411,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun private class HdHomerunCrc { - private static UInt32[] crc_table = { + private static uint[] crc_table = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, @@ -477,7 +477,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; - public static UInt32 GetCrc32(byte[] bytes, int numBytes) + public static uint GetCrc32(byte[] bytes, int numBytes) { var hash = 0xffffffff; for (var i = 0; i < numBytes; i++) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs index c781bccbb7..1a33154f87 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -38,7 +38,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun EnableStreamSharing = true; } - private Socket CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) + private static Socket CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) { var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); @@ -144,7 +144,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun }); } - private void Resolve(TaskCompletionSource<bool> openTaskCompletionSource) + private static void Resolve(TaskCompletionSource<bool> openTaskCompletionSource) { Task.Run(() => { @@ -204,16 +204,16 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); if (offset + count < 0) - throw new ArgumentOutOfRangeException("offset + count must not be negative", "offset+count"); + throw new ArgumentOutOfRangeException(nameof(offset),"offset + count must not be negative"); if (offset + count > buffer.Length) - throw new ArgumentException("offset + count must not be greater than the length of buffer", "offset+count"); + throw new ArgumentException("offset + count must not be greater than the length of buffer"); if (disposed) - throw new ObjectDisposedException(typeof(UdpClientStream).ToString()); + throw new ObjectDisposedException(nameof(UdpClientStream)); // This will always receive a 1328 packet size (PacketSize + RtpHeaderSize) // The RTP header will be stripped so see how many reads we need to make to fill the buffer. @@ -238,16 +238,16 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun public override int Read(byte[] buffer, int offset, int count) { if (buffer == null) - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); if (offset + count < 0) throw new ArgumentOutOfRangeException("offset + count must not be negative", "offset+count"); if (offset + count > buffer.Length) - throw new ArgumentException("offset + count must not be greater than the length of buffer", "offset+count"); + throw new ArgumentException("offset + count must not be greater than the length of buffer"); if (disposed) - throw new ObjectDisposedException(typeof(UdpClientStream).ToString()); + throw new ObjectDisposedException(nameof(UdpClientStream)); // This will always receive a 1328 packet size (PacketSize + RtpHeaderSize) // The RTP header will be stripped so see how many reads we need to make to fill the buffer. @@ -274,49 +274,19 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun disposed = true; } - public override bool CanRead - { - get - { - throw new NotImplementedException(); - } - } + public override bool CanRead => throw new NotImplementedException(); - public override bool CanSeek - { - get - { - throw new NotImplementedException(); - } - } + public override bool CanSeek => throw new NotImplementedException(); - public override bool CanWrite - { - get - { - throw new NotImplementedException(); - } - } + public override bool CanWrite => throw new NotImplementedException(); - public override long Length - { - get - { - throw new NotImplementedException(); - } - } + public override long Length => throw new NotImplementedException(); public override long Position { - get - { - throw new NotImplementedException(); - } + get => throw new NotImplementedException(); - set - { - throw new NotImplementedException(); - } + set => throw new NotImplementedException(); } public override void Flush() diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs index 4a2b4ebb22..b55b02ddc2 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs @@ -217,13 +217,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } - protected virtual int EmptyReadLimit - { - get - { - return 1000; - } - } + protected virtual int EmptyReadLimit => 1000; private void TrySeek(FileStream stream, long offset) { diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index a54bd16139..ab8731c397 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -39,15 +39,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts _mediaSourceManager = mediaSourceManager; } - public override string Type - { - get { return "m3u"; } - } + public override string Type => "m3u"; - public virtual string Name - { - get { return "M3U Tuner"; } - } + public virtual string Name => "M3U Tuner"; private string GetFullChannelIdPrefix(TunerHostInfo info) { diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index 208225c1ed..f83f958029 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -251,7 +251,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return numberString; } - private bool IsValidChannelNumber(string numberString) + private static bool IsValidChannelNumber(string numberString) { if (string.IsNullOrWhiteSpace(numberString) || string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) || @@ -269,7 +269,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return true; } - private string GetChannelName(string extInf, Dictionary<string, string> attributes) + private static string GetChannelName(string extInf, Dictionary<string, string> attributes) { var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null; @@ -314,7 +314,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return name; } - private Dictionary<string, string> ParseExtInf(string line, out string remaining) + private static Dictionary<string, string> ParseExtInf(string line, out string remaining) { var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
