Merge pull request #709 from Bond-009/null

Fix always null expressions
This commit is contained in:
Andrew Rabert 2019-01-26 14:14:23 -05:00 committed by GitHub
commit 7165868509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 55 deletions

View File

@ -76,7 +76,6 @@ namespace Emby.Dlna.ContentDirectory
_dlna.GetDefaultProfile(); _dlna.GetDefaultProfile();
var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase)); var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase));
string accessToken = null;
var user = GetUser(profile); var user = GetUser(profile);
@ -85,7 +84,7 @@ namespace Emby.Dlna.ContentDirectory
_libraryManager, _libraryManager,
profile, profile,
serverAddress, serverAddress,
accessToken, null,
_imageProcessor, _imageProcessor,
_userDataManager, _userDataManager,
user, user,

View File

@ -162,9 +162,7 @@ namespace Emby.Dlna.PlayTo
uuid = location.GetMD5().ToString("N"); uuid = location.GetMD5().ToString("N");
} }
string deviceName = null; var sessionInfo = _sessionManager.LogSessionActivity("DLNA", _appHost.ApplicationVersion, uuid, null, uri.OriginalString, null);
var sessionInfo = _sessionManager.LogSessionActivity("DLNA", _appHost.ApplicationVersion, uuid, deviceName, uri.OriginalString, null);
var controller = sessionInfo.SessionControllers.OfType<PlayToController>().FirstOrDefault(); var controller = sessionInfo.SessionControllers.OfType<PlayToController>().FirstOrDefault();
@ -172,7 +170,7 @@ namespace Emby.Dlna.PlayTo
{ {
var device = await Device.CreateuPnpDeviceAsync(uri, _httpClient, _config, _logger, _timerFactory, cancellationToken).ConfigureAwait(false); var device = await Device.CreateuPnpDeviceAsync(uri, _httpClient, _config, _logger, _timerFactory, cancellationToken).ConfigureAwait(false);
deviceName = device.Properties.Name; string deviceName = device.Properties.Name;
_sessionManager.UpdateDeviceName(sessionInfo.Id, deviceName); _sessionManager.UpdateDeviceName(sessionInfo.Id, deviceName);
@ -186,8 +184,6 @@ namespace Emby.Dlna.PlayTo
serverAddress = _appHost.GetLocalApiUrl(info.LocalIpAddress); serverAddress = _appHost.GetLocalApiUrl(info.LocalIpAddress);
} }
string accessToken = null;
controller = new PlayToController(sessionInfo, controller = new PlayToController(sessionInfo,
_sessionManager, _sessionManager,
_libraryManager, _libraryManager,
@ -196,7 +192,7 @@ namespace Emby.Dlna.PlayTo
_userManager, _userManager,
_imageProcessor, _imageProcessor,
serverAddress, serverAddress,
accessToken, null,
_deviceDiscovery, _deviceDiscovery,
_userDataManager, _userDataManager,
_localization, _localization,

View File

@ -36,7 +36,7 @@ namespace Emby.Naming.AudioBook
return null; return null;
} }
var extension = Path.GetExtension(path) ?? string.Empty; var extension = Path.GetExtension(path);
// Check supported extensions // Check supported extensions
if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)) if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{ {

View File

@ -462,9 +462,8 @@ namespace Emby.Server.Implementations
private static Tuple<Assembly, string> GetAssembly(Type type) private static Tuple<Assembly, string> GetAssembly(Type type)
{ {
var assembly = type.GetTypeInfo().Assembly; var assembly = type.GetTypeInfo().Assembly;
string path = null;
return new Tuple<Assembly, string>(assembly, path); return new Tuple<Assembly, string>(assembly, null);
} }
public virtual IStreamHelper CreateStreamHelper() public virtual IStreamHelper CreateStreamHelper()

View File

@ -1005,7 +1005,7 @@ namespace Emby.XmlTv.Classes
} }
} }
public static Regex _regDateWithOffset = new Regex(@"^(?<dateDigits>[0-9]{4,14})(\s(?<dateOffset>[+-]*[0-9]{1,4}))?$"); public const string _regDateWithOffset = @"^(?<dateDigits>[0-9]{4,14})(\s(?<dateOffset>[+-]*[0-9]{1,4}))?$";
public DateTimeOffset? ParseDate(string dateValue) public DateTimeOffset? ParseDate(string dateValue)
{ {
@ -1018,15 +1018,15 @@ namespace Emby.XmlTv.Classes
'200007281733 BST', '200209', '19880523083000 +0300'. (BST == +0100.) '200007281733 BST', '200209', '19880523083000 +0300'. (BST == +0100.)
*/ */
DateTimeOffset? result = null; if (string.IsNullOrEmpty(dateValue))
if (!string.IsNullOrEmpty(dateValue))
{ {
return null;
}
var completeDate = "20000101000000"; var completeDate = "20000101000000";
var dateComponent = string.Empty; var dateComponent = string.Empty;
var dateOffset = "+00:00"; var dateOffset = "+00:00";
var match = Regex.Match(dateValue, _regDateWithOffset);
var match = _regDateWithOffset.Match(dateValue);
if (match.Success) if (match.Success)
{ {
dateComponent = match.Groups["dateDigits"].Value; dateComponent = match.Groups["dateDigits"].Value;
@ -1051,17 +1051,14 @@ namespace Emby.XmlTv.Classes
} }
var standardDate = string.Format("{0} {1}", dateComponent, dateOffset); var standardDate = string.Format("{0} {1}", dateComponent, dateOffset);
if (DateTimeOffset.TryParseExact(standardDate, "yyyyMMddHHmmss zzz", CultureInfo.CurrentCulture, DateTimeStyles.None, out var parsedDateTime)) if (DateTimeOffset.TryParseExact(standardDate, "yyyyMMddHHmmss zzz", CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTimeOffset parsedDateTime))
{ {
return parsedDateTime.ToUniversalTime(); return parsedDateTime.ToUniversalTime();
} }
else
{
//Logger.LogWarning("Unable to parse the date {0} from standardised form {1}", dateValue, standardDate);
}
}
return result; // Logger.LogWarning("Unable to parse the date {0} from standardised form {1}", dateValue, standardDate);
return null;
} }
public string StandardiseDate(string value) public string StandardiseDate(string value)
@ -1070,7 +1067,7 @@ namespace Emby.XmlTv.Classes
var dateComponent = string.Empty; var dateComponent = string.Empty;
var dateOffset = "+0000"; var dateOffset = "+0000";
var match = _regDateWithOffset.Match(value); var match = Regex.Match(value, _regDateWithOffset);
if (match.Success) if (match.Success)
{ {
dateComponent = match.Groups["dateDigits"].Value; dateComponent = match.Groups["dateDigits"].Value;

View File

@ -508,7 +508,7 @@ namespace MediaBrowser.Controller.Entities
if (query.IsLiked.HasValue) if (query.IsLiked.HasValue)
{ {
userData = userData ?? userDataManager.GetUserData(user, item); userData = userDataManager.GetUserData(user, item);
if (!userData.Likes.HasValue || userData.Likes != query.IsLiked.Value) if (!userData.Likes.HasValue || userData.Likes != query.IsLiked.Value)
{ {

View File

@ -510,13 +510,11 @@ namespace MediaBrowser.Providers.Music
return new ValueTuple<string, string>(); return new ValueTuple<string, string>();
} }
private static ValueTuple<string, string> ParseArtistNameCredit(XmlReader reader) private static (string, string) ParseArtistNameCredit(XmlReader reader)
{ {
reader.MoveToContent(); reader.MoveToContent();
reader.Read(); reader.Read();
string name = null;
// http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator // http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator
// Loop through each element // Loop through each element
@ -547,7 +545,7 @@ namespace MediaBrowser.Providers.Music
} }
} }
return new ValueTuple<string, string>(name, null); return (null, null);
} }
private static ValueTuple<string, string> ParseArtistArtistCredit(XmlReader reader, string artistId) private static ValueTuple<string, string> ParseArtistArtistCredit(XmlReader reader, string artistId)