Skip to content

Commit

Permalink
Merge pull request #2447 from Bond-009/minor
Browse files Browse the repository at this point in the history
Add analyzers to MediaBrowser.Providers and minor improvements
  • Loading branch information
JustAMan authored Apr 1, 2020
2 parents d8b4df6 + 3ab50f5 commit 10275a1
Show file tree
Hide file tree
Showing 45 changed files with 204 additions and 202 deletions.
1 change: 0 additions & 1 deletion Emby.Notifications/Api/NotificationsService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma warning disable CS1591
#pragma warning disable SA1402
#pragma warning disable SA1600
#pragma warning disable SA1649

using System;
Expand Down
1 change: 0 additions & 1 deletion Emby.Notifications/CoreNotificationTypes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion Emby.Notifications/NotificationConfigurationFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System.Collections.Generic;
using MediaBrowser.Common.Configuration;
Expand Down
9 changes: 7 additions & 2 deletions Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,15 @@ protected async Task RegisterResources(IServiceCollection serviceCollection, ICo

serviceCollection.AddSingleton<IDeviceDiscovery>(new DeviceDiscovery(ServerConfigurationManager));

ChapterManager = new ChapterManager(LibraryManager, LoggerFactory, ServerConfigurationManager, ItemRepository);
ChapterManager = new ChapterManager(ItemRepository);
serviceCollection.AddSingleton(ChapterManager);

EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, LoggerFactory, MediaEncoder, ChapterManager, LibraryManager);
EncodingManager = new MediaEncoder.EncodingManager(
LoggerFactory.CreateLogger<MediaEncoder.EncodingManager>(),
FileSystemManager,
MediaEncoder,
ChapterManager,
LibraryManager);
serviceCollection.AddSingleton(EncodingManager);

var activityLogRepo = GetActivityLogRepository();
Expand Down
11 changes: 7 additions & 4 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ private ChapterInfo GetChapter(IReadOnlyList<IResultSetValue> reader, BaseItem i
/// <summary>
/// Saves the chapters.
/// </summary>
public void SaveChapters(Guid id, List<ChapterInfo> chapters)
public void SaveChapters(Guid id, IReadOnlyList<ChapterInfo> chapters)
{
CheckDisposed();

Expand Down Expand Up @@ -2035,22 +2035,24 @@ public void SaveChapters(Guid id, List<ChapterInfo> chapters)
}
}

private void InsertChapters(byte[] idBlob, List<ChapterInfo> chapters, IDatabaseConnection db)
private void InsertChapters(byte[] idBlob, IReadOnlyList<ChapterInfo> chapters, IDatabaseConnection db)
{
var startIndex = 0;
var limit = 100;
var chapterIndex = 0;

const string StartInsertText = "insert into " + ChaptersTableName + " (ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath, ImageDateModified) values ";
var insertText = new StringBuilder(StartInsertText, 256);

while (startIndex < chapters.Count)
{
var insertText = new StringBuilder("insert into " + ChaptersTableName + " (ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath, ImageDateModified) values ");

var endIndex = Math.Min(chapters.Count, startIndex + limit);

for (var i = startIndex; i < endIndex; i++)
{
insertText.AppendFormat("(@ItemId, @ChapterIndex{0}, @StartPositionTicks{0}, @Name{0}, @ImagePath{0}, @ImageDateModified{0}),", i.ToString(CultureInfo.InvariantCulture));
}

insertText.Length -= 1; // Remove last ,

using (var statement = PrepareStatement(db, insertText.ToString()))
Expand All @@ -2077,6 +2079,7 @@ private void InsertChapters(byte[] idBlob, List<ChapterInfo> chapters, IDatabase
}

startIndex += limit;
insertText.Length = StartInsertText.Length;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.IO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System.Threading.Tasks;
using MediaBrowser.Controller.Plugins;
Expand Down
1 change: 0 additions & 1 deletion Emby.Server.Implementations/LiveTv/EmbyTV/IRecorder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Globalization;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using MediaBrowser.Controller.LiveTv;
Expand Down
1 change: 0 additions & 1 deletion Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Concurrent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Concurrent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System.Collections.Generic;
using MediaBrowser.Common.Configuration;
Expand Down
1 change: 0 additions & 1 deletion Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Globalization;
Expand Down
1 change: 0 additions & 1 deletion Emby.Server.Implementations/LiveTv/LiveTvManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Concurrent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Buffers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System;
using System.Collections.Generic;
Expand Down
40 changes: 20 additions & 20 deletions Emby.Server.Implementations/MediaEncoder/EncodingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ public class EncodingManager : IEncodingManager
private readonly IChapterManager _chapterManager;
private readonly ILibraryManager _libraryManager;

/// <summary>
/// The first chapter ticks.
/// </summary>
private static readonly long _firstChapterTicks = TimeSpan.FromSeconds(15).Ticks;

public EncodingManager(
ILogger<EncodingManager> logger,
IFileSystem fileSystem,
ILoggerFactory loggerFactory,
IMediaEncoder encoder,
IChapterManager chapterManager, ILibraryManager libraryManager)
IChapterManager chapterManager,
ILibraryManager libraryManager)
{
_logger = logger;
_fileSystem = fileSystem;
_logger = loggerFactory.CreateLogger(nameof(EncodingManager));
_encoder = encoder;
_chapterManager = chapterManager;
_libraryManager = libraryManager;
Expand Down Expand Up @@ -97,12 +103,7 @@ private bool IsEligibleForChapterImageExtraction(Video video)
return video.DefaultVideoStreamIndex.HasValue;
}

/// <summary>
/// The first chapter ticks
/// </summary>
private static readonly long FirstChapterTicks = TimeSpan.FromSeconds(15).Ticks;

public async Task<bool> RefreshChapterImages(Video video, IDirectoryService directoryService, List<ChapterInfo> chapters, bool extractImages, bool saveChapters, CancellationToken cancellationToken)
public async Task<bool> RefreshChapterImages(Video video, IDirectoryService directoryService, IReadOnlyList<ChapterInfo> chapters, bool extractImages, bool saveChapters, CancellationToken cancellationToken)
{
if (!IsEligibleForChapterImageExtraction(video))
{
Expand Down Expand Up @@ -135,7 +136,7 @@ public async Task<bool> RefreshChapterImages(Video video, IDirectoryService dire
try
{
// Add some time for the first chapter to make sure we don't end up with a black image
var time = chapter.StartPositionTicks == 0 ? TimeSpan.FromTicks(Math.Min(FirstChapterTicks, video.RunTimeTicks ?? 0)) : TimeSpan.FromTicks(chapter.StartPositionTicks);
var time = chapter.StartPositionTicks == 0 ? TimeSpan.FromTicks(Math.Min(_firstChapterTicks, video.RunTimeTicks ?? 0)) : TimeSpan.FromTicks(chapter.StartPositionTicks);

var protocol = MediaProtocol.File;

Expand All @@ -152,9 +153,9 @@ public async Task<bool> RefreshChapterImages(Video video, IDirectoryService dire
{
_fileSystem.DeleteFile(tempFile);
}
catch
catch (IOException ex)
{

_logger.LogError(ex, "Error deleting temporary chapter image encoding file {Path}", tempFile);
}

chapter.ImagePath = path;
Expand Down Expand Up @@ -184,7 +185,7 @@ public async Task<bool> RefreshChapterImages(Video video, IDirectoryService dire

if (saveChapters && changesMade)
{
_chapterManager.SaveChapters(video.Id.ToString(), chapters);
_chapterManager.SaveChapters(video.Id, chapters);
}

DeleteDeadImages(currentImages, chapters);
Expand All @@ -199,22 +200,21 @@ private string GetChapterImagePath(Video video, long chapterPositionTicks)
return Path.Combine(GetChapterImagesPath(video), filename);
}

private static List<string> GetSavedChapterImages(Video video, IDirectoryService directoryService)
private static IReadOnlyList<string> GetSavedChapterImages(Video video, IDirectoryService directoryService)
{
var path = GetChapterImagesPath(video);
if (!Directory.Exists(path))
{
return new List<string>();
return Array.Empty<string>();
}

try
{
return directoryService.GetFilePaths(path)
.ToList();
return directoryService.GetFilePaths(path);
}
catch (IOException)
{
return new List<string>();
return Array.Empty<string>();
}
}

Expand All @@ -227,15 +227,15 @@ private void DeleteDeadImages(IEnumerable<string> images, IEnumerable<ChapterInf

foreach (var image in deadImages)
{
_logger.LogDebug("Deleting dead chapter image {path}", image);
_logger.LogDebug("Deleting dead chapter image {Path}", image);

try
{
_fileSystem.DeleteFile(image);
}
catch (IOException ex)
{
_logger.LogError(ex, "Error deleting {path}.", image);
_logger.LogError(ex, "Error deleting {Path}.", image);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions MediaBrowser.Controller/Chapters/IChapterManager.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Entities;

namespace MediaBrowser.Controller.Chapters
{
/// <summary>
/// Interface IChapterManager
/// Interface IChapterManager.
/// </summary>
public interface IChapterManager
{
/// <summary>
/// Saves the chapters.
/// </summary>
void SaveChapters(string itemId, List<ChapterInfo> chapters);
void SaveChapters(Guid itemId, IReadOnlyList<ChapterInfo> chapters);
}
}
5 changes: 2 additions & 3 deletions MediaBrowser.Controller/Entities/Folder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS1591

using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -28,7 +30,6 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class Folder : BaseItem
{
public static IUserManager UserManager { get; set; }
public static IUserViewManager UserViewManager { get; set; }

/// <summary>
Expand Down Expand Up @@ -620,7 +621,6 @@ public virtual int GetRecursiveChildCount(User user)
{
EnableImages = false
}

}).TotalRecordCount;
}

Expand Down Expand Up @@ -1713,7 +1713,6 @@ public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData use
{
EnableImages = false
}

});

double unplayedCount = unplayedQueryResult.TotalRecordCount;
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Controller/Entities/IItemByName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Marker interface
/// Marker interface.
/// </summary>
public interface IItemByName
{
Expand Down
1 change: 0 additions & 1 deletion MediaBrowser.Controller/Library/IMediaSourceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable SA1600

using System.Collections.Generic;
using System.Threading;
Expand Down
Loading

0 comments on commit 10275a1

Please sign in to comment.