Jump to content

Updated Plugin Docs for .NET Core


Luke

Recommended Posts

I have updated the documentation on how to build a plugin to support .NET Core. See here if you'd like to test out Emby Server running on .NET Core.

 

For those migrating an existing plugin, a few notes:

  • I recommend following the guide to start with a fresh solution, and then you can copy your code files in afterwards. Don't forget to mark config pages as embedded resources just like before.
  • Just copy in code files, because many other files and folders will no longer be needed.
  • Give the new solution the same name as your 2015 solution
  • When overriding the plugin Id, make sure to preserve the value you had before in your 2015 solution

@@Sven

@@mutu310

@@chef

@@radeon

@@Inrego

@@softworkz

@@reggi

@@krustyreturns 

@@Frank Drebin

@@snazy2000

@@hamstercat

@@Aphid

@@BeppoMonkeyBoy

@@flexage

@@pünktchen 

@

@t.andre

  • Like 5
Link to comment
Share on other sites

Same for media portal, although in that plugin the cache isn't optional so i went ahead and did it. that same pattern could be used for dvbviewer.

Link to comment
Share on other sites

mutu310

But ideally we just support .NET Core (2.0?) right? Right now my targets are .NET Framework 4.5, ASP.NET Core 1.0 and WIndows 8.

Link to comment
Share on other sites

No ideally you just support .NET Standard 1.3. Did you create a fresh solution as I suggested? Because if you did then the above configuration you mention I don't think is even possible.

Link to comment
Share on other sites

mutu310

No ideally you just support .NET Standard 1.3. Did you create a fresh solution as I suggested? Because if you did then the above configuration you mention I don't think is even possible.

 

Oh. I was going to try so only because I saw this in the first post: "If you are developing a brand new plugin, consider going .net core only."

Link to comment
Share on other sites

mutu310

No ideally you just support .NET Standard 1.3. Did you create a fresh solution as I suggested? Because if you did then the above configuration you mention I don't think is even possible.

 

 

Oh. I was going to try so only because I saw this in the first post: "If you are developing a brand new plugin, consider going .net core only."

 

Also I did manage to create a solution with just .NET Core (haven't added anything yet)... simply File > New > Project > Class Library (.NET Core)

Link to comment
Share on other sites

mutu310

OK, I tried with .NET Standard 1.3 now...

 

However I'm getting this error...

 

There was an error reflecting type 'MediaBrowser.Channels.BlurN.Configuration.PluginConfiguration'.

Link to comment
Share on other sites

mutu310

You'll want to avoid refection I imagine.

Problem is I'm not (consciously) doing it so I'm not sure what the problem is. Should I use the prerelease NuGet packages?
Link to comment
Share on other sites

mutu310
using System;
using System.Reflection;
using MediaBrowser.Model.Plugins;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Net.Http;
using System.Linq;
using System.Collections.Generic;

namespace MediaBrowser.Channels.BlurN.Configuration
{
    public class PluginConfiguration : BasePluginConfiguration
    {
        public decimal MinimumIMDBRating { get; set; }
        public int MinimumIMDBVotes { get; set; }
        public int Age { get; set; }
        public DateTime LastPublishDate { get; set; }
        public Boolean AddItemsAlreadyInLibrary { get; set; }
        public Boolean HidePlayedMovies { get; set; }
        public Boolean EnableDebugLogging { get; set; }
        public int ChannelRefreshCount { get; set; }
        public string InstallationID { get; set; }
        public bool Action { get; set; }
        public bool Adventure { get; set; }
        public bool Animation { get; set; }
        public bool Biography { get; set; }
        public bool Comedy { get; set; }
        public bool Crime { get; set; }
        public bool Drama { get; set; }
        public bool Family { get; set; }
        public bool Fantasy { get; set; }
        public bool FilmNoir { get; set; }
        public bool History { get; set; }
        public bool Horror { get; set; }
        public bool Music { get; set; }
        public bool Musical { get; set; }
        public bool Mystery { get; set; }
        public bool Romance { get; set; }
        public bool SciFi { get; set; }
        public bool Sport { get; set; }
        public bool Thriller { get; set; }
        public bool War { get; set; }
        public bool Western { get; set; }
        public string BlurNVersion { get { return typeof(PluginConfiguration).GetTypeInfo().Assembly.GetName().Version.ToString(); } }
        public string BlurNLatestVersion { get { return GetLatestVersion().Result; } }

        private string Branch
        {
            get
            {
                if (BlurNVersion.EndsWith("26"))
                    return "Pre3.2.27.0";
                if (BlurNVersion.EndsWith("27"))
                    return "3.2.27.0";
                return "master";
            }
        }

        private string LatestVersionURI
        {
            get { return $"https://raw.githubusercontent.com/MarkCiliaVincenti/MediaBrowser.Channels.BlurN/{Branch}/MediaBrowser.Channels.BlurN/latestversion.txt"; }
        }

        private async Task<string> GetLatestVersion()
        {
            try
            {
                using (var _httpClient = new HttpClient())
                    using (var response = await _httpClient.GetAsync(LatestVersionURI, CancellationToken.None).ConfigureAwait(false))
                        return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
            }
            catch
            {
                return "could not be retrieved";
            }
        }

        public PluginConfiguration()
        {
            ChannelRefreshCount = 1;
            MinimumIMDBRating = 6.8m;
            MinimumIMDBVotes = 1000;
            Age = 730;
            LastPublishDate = DateTime.MinValue;
            AddItemsAlreadyInLibrary = true;
            HidePlayedMovies = true;
            EnableDebugLogging = false;
            InstallationID = Guid.NewGuid().ToString();
            Action = true;
            Adventure = true;
            Animation = true;
            Biography = true;
            Comedy = true;
            Crime = true;
            Drama = true;
            Family = true;
            Fantasy = true;
            FilmNoir = true;
            History = true;
            Horror = true;
            Music = true;
            Musical = true;
            Mystery = true;
            Romance = true;
            SciFi = true;
            Sport = true;
            Thriller = true;
            War = true;
            Western = true;
        }
    }
}

Here's what failing. Hardcoding the BlurNVersion property with the below did not work either:

 

public string BlurNVersion { get { return "1.2.5.28"; } }

Link to comment
Share on other sites

Problem is I'm not (consciously) doing it so I'm not sure what the problem is. Should I use the prerelease NuGet packages?

 

For .net Core, you should follow all of the instructions in this guide.

Link to comment
Share on other sites

And then I would remove all of that latest version stuff. I'm not sure what you're trying to accomplish there.

Link to comment
Share on other sites

pünktchen

Same for media portal, although in that plugin the cache isn't optional so i went ahead and did it. that same pattern could be used for dvbviewer.

 

Thanks for that! Looks like a simple and clever approach. I haven't tested it yet, but from looking at your code changes shouldn't it be

if (_timerCache == null || _timerExpirationTime <= DateTime.UtcNow) instead of if (_timerCache == null || _timerExpirationTime >= DateTime.UtcNow) ?

Link to comment
Share on other sites

ackbarr

I'm attempting to update my plugins to the .NET standard 1.3 approach and I've hit a bit of a sticking point. I need to serialize a class to json. In my previous code I used ServiceStack as the serializer, but that does not work with .NET Standard. I haven't had any luck including additional nuget packages such as ServiceStack.Core to my assembly (or maybe I'm not deploying them properly).

 

Digging through the Nuget class libary I found MediaBrowser.Model.Serialization.IJsonSerializer, but I don't see any concrete constructors exposed in the MediaBrowser.Server.Core package.

 

What would you recommend?

Link to comment
Share on other sites

There isn't a constructor. Just add IJsonSerializer to the constructor of any of your classes and it will be automatically injected in.

Link to comment
Share on other sites

ackbarr

There isn't a constructor. Just add IJsonSerializer to the constructor of any of your classes and it will be automatically injected in.

Thanks for that. Your comment lead me to the Dependency Injection page on the wiki, which I guess I missed the last time around.

Link to comment
Share on other sites

mutu310

And then I would remove all of that latest version stuff. I'm not sure what you're trying to accomplish there.

 

Even without that, it's still failing. I'm on the verge of giving up because I'm not sure what I'm supposed to be doing at all to get this working. I'm just randomly throwing things in the hope they work. My code compiles fine and then I can't debug in Emby.

Edited by mutu310
Link to comment
Share on other sites

mutu310

I've spent too many hours on BlurN in the last few weeks trying to get it working amongst the many changes in Emby and I've finally given up. @@Luke or someone else, I'd appreciate if you can upgrade the code at https://github.com/MarkCiliaVincenti/MediaBrowser.Channels.BlurN for me; otherwise I think I'm unfortunately going to have to retire the plugin.

Edited by mutu310
Link to comment
Share on other sites

I've spent too many hours on BlurN in the last few weeks trying to get it working amongst the many changes in Emby and I've finally given up. @@Luke or someone else, I'd appreciate if you can upgrade the code at https://github.com/MarkCiliaVincenti/MediaBrowser.Channels.BlurN for me; otherwise I think I'm unfortunately going to have to retire the plugin.

 

I submitted a pull request. Give it a shot. Make sure you have visual studio 2017 installed + the .net core 2.0 sdk.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...