pünktchen 1262 Posted March 26, 2018 Share Posted March 26, 2018 (edited) I try to duplicate some of Emby's tv schedules methodes to my live tv plugins, but the implementation of "ILibraryManager" doesn't work. I get a System.argument.Null.Exception. What i'm doing wrong? using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Tasks; namespace MediaBrowser.Plugins.MediaPortal.Helpers { public class CheckTimers { //private readonly ILibraryManager _libraryManager; public void SkipTimers(CancellationToken cancellationToken) { MediaPortal1TvService tvservice = new MediaPortal1TvService(); var timers = tvservice.GetTimersAsync(cancellationToken).Result; foreach ( var timer in timers) { if (IsAlreadyInLibrary(timer)) { tvservice.CancelTimerAsync(timer.Id, cancellationToken); } } } public bool IsAlreadyInLibrary(TimerInfo timer) { if ((timer.EpisodeNumber.HasValue && timer.SeasonNumber.HasValue) || !string.IsNullOrWhiteSpace(timer.EpisodeTitle)) { var seriesIds = (this as ILibraryManager).GetItemIds(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Series).Name }, Name = timer.Name }).Select(i => i.ToString("N")).ToArray(); // It never reaches this point. System.Argument.Null.Exception if (seriesIds.Length == 0) { return false; } //if (timer.EpisodeNumber.HasValue && timer.SeasonNumber.HasValue) //{ // var episode = _libraryManager.GetItemIds(new InternalItemsQuery // { // IncludeItemTypes = new[] { typeof(Episode).Name }, // ParentIndexNumber = timer.SeasonNumber.Value, // IndexNumber = timer.EpisodeNumber.Value, // AncestorIds = seriesIds, // IsVirtualItem = false, // Limit = 1 // }); // if (episode.Count > 0) // { // return true; // } //} } return false; } } } Edited March 26, 2018 by pünktchen Link to comment Share on other sites More sharing options...
Luke 37272 Posted March 26, 2018 Share Posted March 26, 2018 log? Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted March 26, 2018 Author Share Posted March 26, 2018 Line 816 at 2018-03-26 22:42:16.459 Link to comment Share on other sites More sharing options...
Luke 37272 Posted March 26, 2018 Share Posted March 26, 2018 Ok, your reference to _libraryManager is null. Try putting it into the constructor of your CheckTimers class. Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted March 26, 2018 Author Share Posted March 26, 2018 And that's my problem. How to do this without the need of implementing all methods of ILibraryManager? public class CheckTimers : ILibraryManager Link to comment Share on other sites More sharing options...
Luke 37272 Posted March 26, 2018 Share Posted March 26, 2018 You don't need to do that. Create a constructor for CheckTimers public CheckTimers(ILibraryManager libraryManager){ _libraryManager = libraryManager; } Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted March 26, 2018 Author Share Posted March 26, 2018 But if i do this public class CheckTimers { private readonly ILibraryManager _libraryManager; public CheckTimers(ILibraryManager libraryManager) { _libraryManager = libraryManager; } //Do something } what would be the parameter here public Task CreateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) { Plugin.TvProxy.CreateSeriesSchedule(cancellationToken, info); CheckTimers checkTimers = new CheckTimers(); //Missing ILibraryManager Parameter checkTimers.SkipTimers(cancellationToken); return Task.Delay(0, cancellationToken); } Link to comment Share on other sites More sharing options...
Luke 37272 Posted March 26, 2018 Share Posted March 26, 2018 Same concept in that class. Add it to the constructor all the way up your call chain. Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted March 26, 2018 Author Share Posted March 26, 2018 Success! You're the man! I really don't understand those constructors Link to comment Share on other sites More sharing options...
ebr 14960 Posted March 27, 2018 Share Posted March 27, 2018 Success! You're the man! I really don't understand those constructors Google "dependency injection c#" for some light reading . 1 Link to comment Share on other sites More sharing options...
chef 3750 Posted March 27, 2018 Share Posted March 27, 2018 (edited) Google "dependency injection c#" for some light reading .I find being able to call the interfaces in the constructor sooo much easy to reuse class style structures. Make coding with the API very easy Edited March 27, 2018 by chef Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted April 1, 2018 Author Share Posted April 1, 2018 @@Luke is there a property to query for "Original Title" in ILibraryManager? var seriesIds = _libraryManager.GetItemIds(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Series).Name }, // OriginalName = seriesName }).Select(i => i.ToString("N")).ToArray(); Link to comment Share on other sites More sharing options...
Luke 37272 Posted April 1, 2018 Share Posted April 1, 2018 No, currently not. Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted April 1, 2018 Author Share Posted April 1, 2018 Another one: How to get the name or id off all libraries? Link to comment Share on other sites More sharing options...
Luke 37272 Posted April 1, 2018 Share Posted April 1, 2018 You mean the top level libraries? Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted April 1, 2018 Author Share Posted April 1, 2018 Yes. Link to comment Share on other sites More sharing options...
Luke 37272 Posted April 2, 2018 Share Posted April 2, 2018 Do you want the collection folders from library setup? or the actual folder paths within them? Link to comment Share on other sites More sharing options...
pünktchen 1262 Posted April 3, 2018 Author Share Posted April 3, 2018 Do you want the collection folders from library setup? or the actual folder paths within them?Only the collections folder. Link to comment Share on other sites More sharing options...
Luke 37272 Posted April 3, 2018 Share Posted April 3, 2018 Try this. var folders = _libraryManager.GetUserRootFolder().Children.ToList(); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now