mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-02 00:12:24 +00:00
Fix warnings, improve performance (#1665)
* Fix warnings, improve performance `QueryResult.Items` is now a `IReadOnlyList` so we don't need to allocate a new `Array` when we have a `List` (and `Items` shouldn't need to be mutable anyway) * Update Providers .csproj to latest C# * Remove extra newline from DtoService.cs * Remove extra newline from UserLibraryService.cs
This commit is contained in:
@@ -247,7 +247,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
ReadTransactionMode);
|
||||
}
|
||||
|
||||
result.Items = list.ToArray();
|
||||
result.Items = list;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -2746,7 +2746,7 @@ namespace Emby.Server.Implementations.Data
|
||||
var returnList = GetItemList(query);
|
||||
return new QueryResult<BaseItem>
|
||||
{
|
||||
Items = returnList.ToArray(),
|
||||
Items = returnList,
|
||||
TotalRecordCount = returnList.Count
|
||||
};
|
||||
}
|
||||
@@ -2883,7 +2883,7 @@ namespace Emby.Server.Implementations.Data
|
||||
}
|
||||
|
||||
LogQueryTime("GetItems", commandText, now);
|
||||
result.Items = list.ToArray();
|
||||
result.Items = list;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3161,7 +3161,7 @@ namespace Emby.Server.Implementations.Data
|
||||
var returnList = GetItemIdsList(query);
|
||||
return new QueryResult<Guid>
|
||||
{
|
||||
Items = returnList.ToArray(),
|
||||
Items = returnList,
|
||||
TotalRecordCount = returnList.Count
|
||||
};
|
||||
}
|
||||
@@ -3281,7 +3281,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
LogQueryTime("GetItemIds", commandText, now);
|
||||
|
||||
result.Items = list.ToArray();
|
||||
result.Items = list;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -5520,7 +5520,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
|
||||
result.TotalRecordCount = list.Count;
|
||||
}
|
||||
|
||||
result.Items = list.ToArray();
|
||||
result.Items = list;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -80,27 +80,25 @@ namespace Emby.Server.Implementations.Dto
|
||||
return GetBaseItemDto(item, options, user, owner);
|
||||
}
|
||||
|
||||
public BaseItemDto[] GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
|
||||
=> GetBaseItemDtos(items, items.Count, options, user, owner);
|
||||
|
||||
public BaseItemDto[] GetBaseItemDtos(IEnumerable<BaseItem> items, int itemCount, DtoOptions options, User user = null, BaseItem owner = null)
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<BaseItemDto> GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
|
||||
{
|
||||
var returnItems = new BaseItemDto[itemCount];
|
||||
var programTuples = new List<Tuple<BaseItem, BaseItemDto>>();
|
||||
var channelTuples = new List<Tuple<BaseItemDto, LiveTvChannel>>();
|
||||
var returnItems = new BaseItemDto[items.Count];
|
||||
var programTuples = new List<(BaseItem, BaseItemDto)>();
|
||||
var channelTuples = new List<(BaseItemDto, LiveTvChannel)>();
|
||||
|
||||
var index = 0;
|
||||
foreach (var item in items)
|
||||
for (int index = 0; index < items.Count; index++)
|
||||
{
|
||||
var item = items[index];
|
||||
var dto = GetBaseItemDtoInternal(item, options, user, owner);
|
||||
|
||||
if (item is LiveTvChannel tvChannel)
|
||||
{
|
||||
channelTuples.Add(new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel));
|
||||
channelTuples.Add((dto, tvChannel));
|
||||
}
|
||||
else if (item is LiveTvProgram)
|
||||
{
|
||||
programTuples.Add(new Tuple<BaseItem, BaseItemDto>(item, dto));
|
||||
programTuples.Add((item, dto));
|
||||
}
|
||||
|
||||
if (item is IItemByName byName)
|
||||
@@ -121,7 +119,6 @@ namespace Emby.Server.Implementations.Dto
|
||||
}
|
||||
|
||||
returnItems[index] = dto;
|
||||
index++;
|
||||
}
|
||||
|
||||
if (programTuples.Count > 0)
|
||||
@@ -140,33 +137,32 @@ namespace Emby.Server.Implementations.Dto
|
||||
public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null)
|
||||
{
|
||||
var dto = GetBaseItemDtoInternal(item, options, user, owner);
|
||||
var tvChannel = item as LiveTvChannel;
|
||||
if (tvChannel != null)
|
||||
if (item is LiveTvChannel tvChannel)
|
||||
{
|
||||
var list = new List<Tuple<BaseItemDto, LiveTvChannel>> { new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel) };
|
||||
var list = new List<(BaseItemDto, LiveTvChannel)>(1) { (dto, tvChannel) };
|
||||
_livetvManager().AddChannelInfo(list, options, user);
|
||||
}
|
||||
else if (item is LiveTvProgram)
|
||||
{
|
||||
var list = new List<Tuple<BaseItem, BaseItemDto>> { new Tuple<BaseItem, BaseItemDto>(item, dto) };
|
||||
var list = new List<(BaseItem, BaseItemDto)>(1) { (item, dto) };
|
||||
var task = _livetvManager().AddInfoToProgramDto(list, options.Fields, user);
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
var byName = item as IItemByName;
|
||||
|
||||
if (byName != null)
|
||||
if (item is IItemByName itemByName
|
||||
&& options.ContainsField(ItemFields.ItemCounts))
|
||||
{
|
||||
if (options.ContainsField(ItemFields.ItemCounts))
|
||||
{
|
||||
SetItemByNameInfo(item, dto, GetTaggedItems(byName, user, new DtoOptions(false)
|
||||
{
|
||||
EnableImages = false
|
||||
|
||||
}), user);
|
||||
}
|
||||
|
||||
return dto;
|
||||
SetItemByNameInfo(
|
||||
item,
|
||||
dto,
|
||||
GetTaggedItems(
|
||||
itemByName,
|
||||
user,
|
||||
new DtoOptions(false)
|
||||
{
|
||||
EnableImages = false
|
||||
}),
|
||||
user);
|
||||
}
|
||||
|
||||
return dto;
|
||||
@@ -174,12 +170,12 @@ namespace Emby.Server.Implementations.Dto
|
||||
|
||||
private static IList<BaseItem> GetTaggedItems(IItemByName byName, User user, DtoOptions options)
|
||||
{
|
||||
return byName.GetTaggedItems(new InternalItemsQuery(user)
|
||||
{
|
||||
Recursive = true,
|
||||
DtoOptions = options
|
||||
|
||||
});
|
||||
return byName.GetTaggedItems(
|
||||
new InternalItemsQuery(user)
|
||||
{
|
||||
Recursive = true,
|
||||
DtoOptions = options
|
||||
});
|
||||
}
|
||||
|
||||
private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null)
|
||||
@@ -222,8 +218,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
AttachUserSpecificInfo(dto, item, user, options);
|
||||
}
|
||||
|
||||
var hasMediaSources = item as IHasMediaSources;
|
||||
if (hasMediaSources != null)
|
||||
if (item is IHasMediaSources hasMediaSources)
|
||||
{
|
||||
if (options.ContainsField(ItemFields.MediaSources))
|
||||
{
|
||||
@@ -769,14 +764,12 @@ namespace Emby.Server.Implementations.Dto
|
||||
|
||||
dto.CriticRating = item.CriticRating;
|
||||
|
||||
var hasDisplayOrder = item as IHasDisplayOrder;
|
||||
if (hasDisplayOrder != null)
|
||||
if (item is IHasDisplayOrder hasDisplayOrder)
|
||||
{
|
||||
dto.DisplayOrder = hasDisplayOrder.DisplayOrder;
|
||||
}
|
||||
|
||||
var hasCollectionType = item as IHasCollectionType;
|
||||
if (hasCollectionType != null)
|
||||
if (item is IHasCollectionType hasCollectionType)
|
||||
{
|
||||
dto.CollectionType = hasCollectionType.CollectionType;
|
||||
}
|
||||
@@ -1073,17 +1066,24 @@ namespace Emby.Server.Implementations.Dto
|
||||
|
||||
if (options.ContainsField(ItemFields.LocalTrailerCount))
|
||||
{
|
||||
int trailerCount = 0;
|
||||
if (allExtras == null)
|
||||
{
|
||||
allExtras = item.GetExtras().ToArray();
|
||||
}
|
||||
|
||||
dto.LocalTrailerCount = allExtras.Count(i => i.ExtraType.HasValue && i.ExtraType.Value == ExtraType.Trailer) + item.GetTrailers().Count();
|
||||
trailerCount += allExtras.Count(i => i.ExtraType.HasValue && i.ExtraType.Value == ExtraType.Trailer);
|
||||
|
||||
if (item is IHasTrailers hasTrailers)
|
||||
{
|
||||
trailerCount += hasTrailers.GetTrailerCount();
|
||||
}
|
||||
|
||||
dto.LocalTrailerCount = trailerCount;
|
||||
}
|
||||
|
||||
// Add EpisodeInfo
|
||||
var episode = item as Episode;
|
||||
if (episode != null)
|
||||
if (item is Episode episode)
|
||||
{
|
||||
dto.IndexNumberEnd = episode.IndexNumberEnd;
|
||||
dto.SeriesName = episode.SeriesName;
|
||||
@@ -1101,7 +1101,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
|
||||
Series episodeSeries = null;
|
||||
|
||||
//if (options.ContainsField(ItemFields.SeriesPrimaryImage))
|
||||
if (options.ContainsField(ItemFields.SeriesPrimaryImage))
|
||||
{
|
||||
episodeSeries = episodeSeries ?? episode.Series;
|
||||
if (episodeSeries != null)
|
||||
@@ -1121,8 +1121,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
}
|
||||
|
||||
// Add SeriesInfo
|
||||
var series = item as Series;
|
||||
if (series != null)
|
||||
if (item is Series series)
|
||||
{
|
||||
dto.AirDays = series.AirDays;
|
||||
dto.AirTime = series.AirTime;
|
||||
@@ -1130,8 +1129,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
}
|
||||
|
||||
// Add SeasonInfo
|
||||
var season = item as Season;
|
||||
if (season != null)
|
||||
if (item is Season season)
|
||||
{
|
||||
dto.SeriesName = season.SeriesName;
|
||||
dto.SeriesId = season.SeriesId;
|
||||
@@ -1147,7 +1145,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
}
|
||||
}
|
||||
|
||||
//if (options.ContainsField(ItemFields.SeriesPrimaryImage))
|
||||
if (options.ContainsField(ItemFields.SeriesPrimaryImage))
|
||||
{
|
||||
series = series ?? season.Series;
|
||||
if (series != null)
|
||||
@@ -1157,14 +1155,12 @@ namespace Emby.Server.Implementations.Dto
|
||||
}
|
||||
}
|
||||
|
||||
var musicVideo = item as MusicVideo;
|
||||
if (musicVideo != null)
|
||||
if (item is MusicVideo musicVideo)
|
||||
{
|
||||
SetMusicVideoProperties(dto, musicVideo);
|
||||
}
|
||||
|
||||
var book = item as Book;
|
||||
if (book != null)
|
||||
if (item is Book book)
|
||||
{
|
||||
SetBookProperties(dto, book);
|
||||
}
|
||||
@@ -1204,8 +1200,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
}
|
||||
}
|
||||
|
||||
var photo = item as Photo;
|
||||
if (photo != null)
|
||||
if (item is Photo photo)
|
||||
{
|
||||
SetPhotoProperties(dto, photo);
|
||||
}
|
||||
@@ -1224,8 +1219,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
|
||||
private BaseItem GetImageDisplayParent(BaseItem currentItem, BaseItem originalItem)
|
||||
{
|
||||
var musicAlbum = currentItem as MusicAlbum;
|
||||
if (musicAlbum != null)
|
||||
if (currentItem is MusicAlbum musicAlbum)
|
||||
{
|
||||
var artist = musicAlbum.GetMusicArtist(new DtoOptions(false));
|
||||
if (artist != null)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Controller.Security;
|
||||
@@ -89,7 +90,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
AccessToken = token
|
||||
});
|
||||
|
||||
var tokenInfo = result.Items.Length > 0 ? result.Items[0] : null;
|
||||
var tokenInfo = result.Items.Count > 0 ? result.Items[0] : null;
|
||||
|
||||
if (tokenInfo != null)
|
||||
{
|
||||
@@ -190,17 +191,23 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
/// <returns>Dictionary{System.StringSystem.String}.</returns>
|
||||
private Dictionary<string, string> GetAuthorization(string authorizationHeader)
|
||||
{
|
||||
if (authorizationHeader == null) return null;
|
||||
if (authorizationHeader == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var parts = authorizationHeader.Split(new[] { ' ' }, 2);
|
||||
|
||||
// There should be at least to parts
|
||||
if (parts.Length != 2) return null;
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var acceptedNames = new[] { "MediaBrowser", "Emby" };
|
||||
|
||||
// It has to be a digest request
|
||||
if (!acceptedNames.Contains(parts[0] ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
||||
if (!acceptedNames.Contains(parts[0], StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -232,7 +239,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
return value;
|
||||
}
|
||||
|
||||
return System.Net.WebUtility.HtmlEncode(value);
|
||||
return WebUtility.HtmlEncode(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1441,7 +1441,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
return new QueryResult<BaseItem>
|
||||
{
|
||||
Items = list.ToArray()
|
||||
Items = list
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1977,8 +1977,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
public LibraryOptions GetLibraryOptions(BaseItem item)
|
||||
{
|
||||
var collectionFolder = item as CollectionFolder;
|
||||
if (collectionFolder == null)
|
||||
if (!(item is CollectionFolder collectionFolder))
|
||||
{
|
||||
collectionFolder = GetCollectionFolders(item)
|
||||
.OfType<CollectionFolder>()
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace Emby.Server.Implementations.Library
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<BaseItem> GetItemsForLatestItems(User user, LatestItemsQuery request, DtoOptions options)
|
||||
private IReadOnlyList<BaseItem> GetItemsForLatestItems(User user, LatestItemsQuery request, DtoOptions options)
|
||||
{
|
||||
var parentId = request.ParentId;
|
||||
|
||||
@@ -236,24 +236,22 @@ namespace Emby.Server.Implementations.Library
|
||||
if (!parentId.Equals(Guid.Empty))
|
||||
{
|
||||
var parentItem = _libraryManager.GetItemById(parentId);
|
||||
var parentItemChannel = parentItem as Channel;
|
||||
if (parentItemChannel != null)
|
||||
if (parentItem is Channel parentItemChannel)
|
||||
{
|
||||
return _channelManager.GetLatestChannelItemsInternal(new InternalItemsQuery(user)
|
||||
{
|
||||
ChannelIds = new[] { parentId },
|
||||
IsPlayed = request.IsPlayed,
|
||||
StartIndex = request.StartIndex,
|
||||
Limit = request.Limit,
|
||||
IncludeItemTypes = request.IncludeItemTypes,
|
||||
EnableTotalRecordCount = false
|
||||
|
||||
|
||||
}, CancellationToken.None).Result.Items.ToList();
|
||||
return _channelManager.GetLatestChannelItemsInternal(
|
||||
new InternalItemsQuery(user)
|
||||
{
|
||||
ChannelIds = new[] { parentId },
|
||||
IsPlayed = request.IsPlayed,
|
||||
StartIndex = request.StartIndex,
|
||||
Limit = request.Limit,
|
||||
IncludeItemTypes = request.IncludeItemTypes,
|
||||
EnableTotalRecordCount = false
|
||||
},
|
||||
CancellationToken.None).Result.Items;
|
||||
}
|
||||
|
||||
var parent = parentItem as Folder;
|
||||
if (parent != null)
|
||||
if (parentItem is Folder parent)
|
||||
{
|
||||
parents.Add(parent);
|
||||
}
|
||||
|
||||
@@ -881,7 +881,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
}
|
||||
|
||||
var programList = _libraryManager.QueryItems(internalQuery).Items;
|
||||
var totalCount = programList.Length;
|
||||
var totalCount = programList.Count;
|
||||
|
||||
var orderedPrograms = programList.Cast<LiveTvProgram>().OrderBy(i => i.StartDate.Date);
|
||||
|
||||
@@ -969,8 +969,8 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
var timers = new Dictionary<string, List<TimerInfo>>();
|
||||
var seriesTimers = new Dictionary<string, List<SeriesTimerInfo>>();
|
||||
|
||||
TimerInfo[] timerList = null;
|
||||
SeriesTimerInfo[] seriesTimerList = null;
|
||||
IReadOnlyList<TimerInfo> timerList = null;
|
||||
IReadOnlyList<SeriesTimerInfo> seriesTimerList = null;
|
||||
|
||||
foreach (var programTuple in programs)
|
||||
{
|
||||
@@ -1296,6 +1296,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
}
|
||||
|
||||
private const int MaxGuideDays = 14;
|
||||
|
||||
private double GetGuideDays()
|
||||
{
|
||||
var config = GetConfiguration();
|
||||
@@ -1340,6 +1341,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
excludeItemTypes.Add(typeof(Movie).Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (query.IsSeries.HasValue)
|
||||
{
|
||||
if (query.IsSeries.Value)
|
||||
@@ -1351,10 +1353,12 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
excludeItemTypes.Add(typeof(Episode).Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (query.IsSports ?? false)
|
||||
{
|
||||
genres.Add("Sports");
|
||||
}
|
||||
|
||||
if (query.IsKids ?? false)
|
||||
{
|
||||
genres.Add("Kids");
|
||||
@@ -1400,20 +1404,20 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
|
||||
if (query.IsInProgress ?? false)
|
||||
{
|
||||
//TODO Fix The co-variant conversion between Video[] and BaseItem[], this can generate runtime issues.
|
||||
// TODO: Fix The co-variant conversion between Video[] and BaseItem[], this can generate runtime issues.
|
||||
result.Items = result
|
||||
.Items
|
||||
.OfType<Video>()
|
||||
.Where(i => !i.IsCompleteMedia)
|
||||
.ToArray();
|
||||
|
||||
result.TotalRecordCount = result.Items.Length;
|
||||
result.TotalRecordCount = result.Items.Count;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task AddInfoToProgramDto(List<Tuple<BaseItem, BaseItemDto>> tuples, ItemFields[] fields, User user = null)
|
||||
public Task AddInfoToProgramDto(IReadOnlyCollection<(BaseItem, BaseItemDto)> tuples, ItemFields[] fields, User user = null)
|
||||
{
|
||||
var programTuples = new List<Tuple<BaseItemDto, string, string>>();
|
||||
var hasChannelImage = fields.Contains(ItemFields.ChannelImage);
|
||||
@@ -1877,7 +1881,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
return _libraryManager.GetItemById(internalChannelId);
|
||||
}
|
||||
|
||||
public void AddChannelInfo(List<Tuple<BaseItemDto, LiveTvChannel>> tuples, DtoOptions options, User user)
|
||||
public void AddChannelInfo(IReadOnlyCollection<(BaseItemDto, LiveTvChannel)> tuples, DtoOptions options, User user)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Implementations.HttpServer;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using MediaBrowser.Model.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Emby.Server.Implementations.Services
|
||||
{
|
||||
|
||||
@@ -87,8 +87,7 @@ namespace Emby.Server.Implementations.Services
|
||||
|
||||
var response = actionContext.ServiceAction(instance, requestDto);
|
||||
|
||||
var taskResponse = response as Task;
|
||||
if (taskResponse != null)
|
||||
if (response is Task taskResponse)
|
||||
{
|
||||
return GetTaskResult(taskResponse);
|
||||
}
|
||||
@@ -104,8 +103,7 @@ namespace Emby.Server.Implementations.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
var taskObject = task as Task<object>;
|
||||
if (taskObject != null)
|
||||
if (task is Task<object> taskObject)
|
||||
{
|
||||
return await taskObject.ConfigureAwait(false);
|
||||
}
|
||||
@@ -136,7 +134,7 @@ namespace Emby.Server.Implementations.Services
|
||||
}
|
||||
catch (TypeAccessException)
|
||||
{
|
||||
return null; //return null for void Task's
|
||||
return null; // return null for void Task's
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,29 +153,22 @@ namespace Emby.Server.Implementations.Services
|
||||
Id = ServiceMethod.Key(serviceType, actionName, requestType.GetMethodName())
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
actionCtx.ServiceAction = CreateExecFn(serviceType, requestType, mi);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Potential problems with MONO, using reflection for fallback
|
||||
actionCtx.ServiceAction = (service, request) =>
|
||||
mi.Invoke(service, new[] { request });
|
||||
}
|
||||
actionCtx.ServiceAction = CreateExecFn(serviceType, requestType, mi);
|
||||
|
||||
var reqFilters = new List<IHasRequestFilter>();
|
||||
|
||||
foreach (var attr in mi.GetCustomAttributes(true))
|
||||
{
|
||||
var hasReqFilter = attr as IHasRequestFilter;
|
||||
|
||||
if (hasReqFilter != null)
|
||||
if (attr is IHasRequestFilter hasReqFilter)
|
||||
{
|
||||
reqFilters.Add(hasReqFilter);
|
||||
}
|
||||
}
|
||||
|
||||
if (reqFilters.Count > 0)
|
||||
{
|
||||
actionCtx.RequestFilters = reqFilters.OrderBy(i => i.Priority).ToArray();
|
||||
}
|
||||
|
||||
actions.Add(actionCtx);
|
||||
}
|
||||
@@ -198,15 +189,19 @@ namespace Emby.Server.Implementations.Services
|
||||
|
||||
if (mi.ReturnType != typeof(void))
|
||||
{
|
||||
var executeFunc = Expression.Lambda<ActionInvokerFn>
|
||||
(callExecute, serviceParam, requestDtoParam).Compile();
|
||||
var executeFunc = Expression.Lambda<ActionInvokerFn>(
|
||||
callExecute,
|
||||
serviceParam,
|
||||
requestDtoParam).Compile();
|
||||
|
||||
return executeFunc;
|
||||
}
|
||||
else
|
||||
{
|
||||
var executeFunc = Expression.Lambda<VoidActionInvokerFn>
|
||||
(callExecute, serviceParam, requestDtoParam).Compile();
|
||||
var executeFunc = Expression.Lambda<VoidActionInvokerFn>(
|
||||
callExecute,
|
||||
serviceParam,
|
||||
requestDtoParam).Compile();
|
||||
|
||||
return (service, request) =>
|
||||
{
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace Emby.Server.Implementations.Services
|
||||
{
|
||||
public static string GetMethodName(this Type type)
|
||||
{
|
||||
var typeName = type.FullName != null //can be null, e.g. generic types
|
||||
? LeftPart(type.FullName, "[[") //Generic Fullname
|
||||
.Replace(type.Namespace + ".", "") //Trim Namespaces
|
||||
.Replace("+", ".") //Convert nested into normal type
|
||||
var typeName = type.FullName != null // can be null, e.g. generic types
|
||||
? LeftPart(type.FullName, "[[") // Generic Fullname
|
||||
.Replace(type.Namespace + ".", string.Empty) // Trim Namespaces
|
||||
.Replace("+", ".") // Convert nested into normal type
|
||||
: type.Name;
|
||||
|
||||
return type.IsGenericParameter ? "'" + typeName : typeName;
|
||||
@@ -23,7 +23,11 @@ namespace Emby.Server.Implementations.Services
|
||||
|
||||
private static string LeftPart(string strVal, string needle)
|
||||
{
|
||||
if (strVal == null) return null;
|
||||
if (strVal == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var pos = strVal.IndexOf(needle, StringComparison.OrdinalIgnoreCase);
|
||||
return pos == -1
|
||||
? strVal
|
||||
|
||||
Reference in New Issue
Block a user