Jump to content

Add Dependencies


Recommended Posts

bakes82
1 hour ago, Luke said:

Hi, I would suggest just embedding the source code instead.

So you want me to de compile someone else's nuget and embed it lol ...... 

Link to post
Share on other sites
Luke

Well they might have the source available somewhere. Anyhow, that's my response from the standpoint of what will work the most reliably across all possible platforms. If you really want to embed the dll, it is possible and others have found ways to do this and those discussions can be found in the community. @chef may have done it before.

Link to post
Share on other sites
bakes82

Well I kind of assumed being able to use Netwonsoft.Json you know would be a no brainier.......  Can we target 2.1 standard?  That has the new JSON built in I believe.

Link to post
Share on other sites
Luke

To be in the plugin catalog no as that won't work on all platforms. But if it works for you for a private plugin then yes you can.

Link to post
Share on other sites
chef

What part of Newtonsoft do you need to use that the IJsonSerializer interface doesn't have?

 

I do have a trick for embedding dependency dlls, then coping them over using reflection.

 

Link to post
Share on other sites
bakes82

I actually want to use the trakt.net library which also uses the newtonsoft.json,  I can pull the trakt library into my code, but then all the JSON stuff from newton needs the readers/writers and thats a mess when you try to pull the other lib in to the code.

 

Can you post the reflection.

Link to post
Share on other sites
chef
55 minutes ago, bakes82 said:

I actually want to use the trakt.net library which also uses the newtonsoft.json,  I can pull the trakt library into my code, but then all the JSON stuff from newton needs the readers/writers and thats a mess when you try to pull the other lib in to the code.

 

Can you post the reflection.

@Luke does emby still use Newtonsoft as it's serializer library, or did you guys decide to use something else?

 

@bakes82 if emby uses Newtonsoft as it's base json serializer, you can figure out which version it's using, then you can add that version dependency to your plugin project solution and call it directly. When you load the plugin, it will match the version emby uses and use it. But, this will only work if emby still uses Newtonsoft as one of its own project dependencies. Only other thing to keep in mind, is to find a version of the trakt.net library that uses the same Newtonsoft version. If they don't match you'll get runtime errors.

If you swap out versions of Newtonsoft, emby may have runtime errors.

 

Is there a way to get the trakt.net c# binaries and load the entire project into your plugin?

Edited by chef
Link to post
Share on other sites
bakes82
9 minutes ago, chef said:

@Luke does emby still use Newtonsoft as it's serializer library, or did you decide to use something else?

 

@bakes82 if emby uses Newtonsoft as it's base json serializer, you can figure out which version it's using, then you can add that version dependency to your plugin project solution and call it directly. When you load the plugin, it will match the version emby uses and use it. But, this will only work if emby still uses Newtonsoft as one of its own project dependencies.

So what about the code for the reflection?  There any many nugets that are premade for lots of things lol.  Seems way easier for me to be able to inject the DLL some how so I dont need to pull their repo copy out the code etc.  Even if there was a folder that we could put custom DLL in and emby would load from it would be fine too.

Link to post
Share on other sites
chef

An exame of utilizing emby dependencies directly is In my unzip and copy plugin, I call functions directly from SharpCompress.dll which emby uses to update itself. That particular library can also be used to unzip .rar files and copy them around. That plugin skips the IZip interface emby offers and uses the library binaries directly.

Link to post
Share on other sites
chef

this gets a bit hacky, so bare with me :)

Save the DLL as an embeded resource in your solution. So you will have a dependency on it, as well as the physical DLL in your solution.

Next we have to find the file in your solution so we can copy it over to the Emby Application system folder.

Something like this:

 

 

        private static void WriteResourceToFile(string resourceName, string fileFullPath)
        {
            // This should locate the first resource in your solution with the "resourceName"
            using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream().Single(s => s.EndsWith(resourceName))
            {
                using (var file = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write))
                {
                    resource?.CopyTo(file);
                }
            }
        }

"resourceName" is the library DLL

"fileFullPath" is the full path to copy it to. 

 

In order to get the "fileFullPath" you can try something like this using the "IServerApplicationPaths" interface in Emby:

        private IServerApplicationPaths ServerApplicationPaths  { get; set; }

        // This Run function should be in an class which inherits IServerEntryPoint so it runs when the server starts
        public void Run()
        {
            var rootFolderPath   = ServerApplicationPaths.RootFolderPath; 
            var serverSystemFolder = rootFolderPath.Replace(@"programdata\root", "system");
            //Copy the binaries to the serverSystemFolder
            WriteResourceToFile("trakt", serverSystemFolder);
	}

 

Now, you'll have to restart the server in order to load that binary which was copied over.

 

Note: The above code is untested, it would probabaly be very close to that.

 

Workflow would be:

1. Write the plugin and copy it into the "programdata/plugins" folder

2. Restart server to load plugin - which will copy over the binary into the server "system" folder

3. Restart server again to load new binary

 

Caviots to watch out for:

1. You'll have to check to make sure the copied DLL doesn't exist already in the server "system" folder before copying it over (so it doesn't copy it every time the server starts).

2. Each time Emby updates it will remove your DLL from the server root, your plugin will have to replace it, if it doesn't exist, and restart the server again each time.

 

 

It's hacky... I'm sorry it isn't less complicated.

I would try copying the trakt.dll a couple times during testing, to make sure you have targeted the Emby "system" folder (which is the "Emby-Server/system" folder).

Edited by chef
Link to post
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...