Fix warnings and move to System.Text.Json

This commit is contained in:
Bond_009 2019-12-20 21:49:16 +01:00
parent bb62dd14c2
commit 5751d86536
3 changed files with 20 additions and 12 deletions

View File

@ -1,7 +1,13 @@
#pragma warning disable CS1591
#pragma warning disable SA1402
#pragma warning disable SA1600
#pragma warning disable SA1649
using System; using System;
using System.Buffers; using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text.Json;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -73,7 +79,6 @@ namespace MediaBrowser.Api.Playback
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly IMediaEncoder _mediaEncoder; private readonly IMediaEncoder _mediaEncoder;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IJsonSerializer _json;
private readonly IAuthorizationContext _authContext; private readonly IAuthorizationContext _authContext;
public MediaInfoService( public MediaInfoService(
@ -86,7 +91,6 @@ namespace MediaBrowser.Api.Playback
INetworkManager networkManager, INetworkManager networkManager,
IMediaEncoder mediaEncoder, IMediaEncoder mediaEncoder,
IUserManager userManager, IUserManager userManager,
IJsonSerializer json,
IAuthorizationContext authContext) IAuthorizationContext authContext)
: base(logger, serverConfigurationManager, httpResultFactory) : base(logger, serverConfigurationManager, httpResultFactory)
{ {
@ -96,7 +100,6 @@ namespace MediaBrowser.Api.Playback
_networkManager = networkManager; _networkManager = networkManager;
_mediaEncoder = mediaEncoder; _mediaEncoder = mediaEncoder;
_userManager = userManager; _userManager = userManager;
_json = json;
_authContext = authContext; _authContext = authContext;
} }
@ -193,7 +196,7 @@ namespace MediaBrowser.Api.Playback
var profile = request.DeviceProfile; var profile = request.DeviceProfile;
Logger.LogInformation("GetPostedPlaybackInfo profile: {profile}", _json.SerializeToString(profile)); Logger.LogInformation("GetPostedPlaybackInfo profile: {@Profile}", profile);
if (profile == null) if (profile == null)
{ {
@ -266,9 +269,8 @@ namespace MediaBrowser.Api.Playback
{ {
// Since we're going to be setting properties on MediaSourceInfos that come out of _mediaSourceManager, we should clone it // Since we're going to be setting properties on MediaSourceInfos that come out of _mediaSourceManager, we should clone it
// Should we move this directly into MediaSourceManager? // Should we move this directly into MediaSourceManager?
var json = JsonSerializer.SerializeToUtf8Bytes(obj);
var json = _json.SerializeToString(obj); return JsonSerializer.Deserialize<T>(json);
return _json.DeserializeFromString<T>(json);
} }
private async Task<PlaybackInfoResponse> GetPlaybackInfo(Guid id, Guid userId, string[] supportedLiveMediaTypes, string mediaSourceId = null, string liveStreamId = null) private async Task<PlaybackInfoResponse> GetPlaybackInfo(Guid id, Guid userId, string[] supportedLiveMediaTypes, string mediaSourceId = null, string liveStreamId = null)
@ -309,7 +311,7 @@ namespace MediaBrowser.Api.Playback
result.MediaSources = new MediaSourceInfo[] { mediaSource }; result.MediaSources = new MediaSourceInfo[] { mediaSource };
} }
if (result.MediaSources.Length == 0) if (result.MediaSources.Count == 0)
{ {
if (!result.ErrorCode.HasValue) if (!result.ErrorCode.HasValue)
{ {

View File

@ -74,7 +74,6 @@ namespace MediaBrowser.Api.Playback
[Authenticated] [Authenticated]
public class UniversalAudioService : BaseApiService public class UniversalAudioService : BaseApiService
{ {
private readonly ILoggerFactory _loggerFactory;
private readonly EncodingHelper _encodingHelper; private readonly EncodingHelper _encodingHelper;
public UniversalAudioService( public UniversalAudioService(
@ -243,7 +242,6 @@ namespace MediaBrowser.Api.Playback
NetworkManager, NetworkManager,
MediaEncoder, MediaEncoder,
UserManager, UserManager,
JsonSerializer,
AuthorizationContext) AuthorizationContext)
{ {
Request = Request Request = Request

View File

@ -1,15 +1,20 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
namespace MediaBrowser.Model.MediaInfo namespace MediaBrowser.Model.MediaInfo
{ {
/// <summary>
/// Class PlaybackInfoResponse.
/// </summary>
public class PlaybackInfoResponse public class PlaybackInfoResponse
{ {
/// <summary> /// <summary>
/// Gets or sets the media sources. /// Gets or sets the media sources.
/// </summary> /// </summary>
/// <value>The media sources.</value> /// <value>The media sources.</value>
public MediaSourceInfo[] MediaSources { get; set; } public IReadOnlyList<MediaSourceInfo> MediaSources { get; set; }
/// <summary> /// <summary>
/// Gets or sets the play session identifier. /// Gets or sets the play session identifier.
@ -23,9 +28,12 @@ namespace MediaBrowser.Model.MediaInfo
/// <value>The error code.</value> /// <value>The error code.</value>
public PlaybackErrorCode? ErrorCode { get; set; } public PlaybackErrorCode? ErrorCode { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="PlaybackInfoResponse" /> class.
/// </summary>
public PlaybackInfoResponse() public PlaybackInfoResponse()
{ {
MediaSources = new MediaSourceInfo[] { }; MediaSources = Array.Empty<MediaSourceInfo>();
} }
} }
} }