0

I am here because I have a program and some features in my mind.

But I am not sure what these features are called in programming terms. So I am unable to even do a proper google search regarding the same. I am keen to identify what this is called, so I can progress my Analysis and Research.

I have developed a program, with C# and Windows Forms. Currently it interfaces with YouTube API and monitors the chat. I am also raising some events, when chat messages arrive and when the message follows a certain format/syntax. Everything is working fine so far.

What I want to do is:

If someone using my software, who has access to just the binaries. But want to write their own logic, which handles some of the events I am raising. How do they do that?

I want the user to write their own program/class, put it in a specific folder. I will expect it to have a Start() and End() method. Inside the methods, they can write the code to subscribe to any event of their choice and do what they need to.

I already have written code inside my main loop, which will loop through the folder which is supposed to contain the user programs, and tries to invoke the Start/End method of their programs/classes.

For me, as the original author of the project, I can just go ahead and start writing the code inside the folder. Once I build and execute. Everything works fine. The main program triggers the Start/End inside the program/class that I added. And the events are also handled fine.

But how about someone using my software, who wants to handle it's events, without having to re-compile my code. How do they do that?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • You might ask your search engine for `c# plugin`. – Axel Kemper Dec 29 '20 at 10:47
  • Thank you Axel. Checking now. – Tamil Ninja Dec 29 '20 at 10:50
  • Indeed, i think what Alex mentioned is a good term. Usually you would approach it by defining a "Plugin" API, potentially via a shared assembly that your "plugins" should target and an interface that these 3rd party plugins should implement. I'd suggest trying to build your own extensions the same way too, this way you'll stumble upon most of the problems that other developers would when building their extensions. – Ivan Zub Dec 29 '20 at 11:49
  • I wonder if you could run a separate executable to run a Lua or other similar script interpreter. – halfer Dec 30 '20 at 10:55
  • Hi Halfer, What you suggested was the first thing that came to my mind. I have seen game engines and streamlabs chatbot do that. But based on other inputs to this i found out and learned how to develop pluggable programs. So far eveything seems to be progressing well. To start with I am using 'Option 1' suggested by SAMIKSC. – Tamil Ninja Dec 31 '20 at 08:57

1 Answers1

0

You have the following options
Option 1

  • Create a template project with all required references and a code file (.cs) with the Start() / End() methods.
  • Add comments to the start() / end() methods or add a code sample of how they can work with the additional events.
  • The project should compile fine without any source code for your main project.
  • If you expect the users to use Visual Studio Code, give them instructions to compile using VS code.
  • If they are going to use any text editor, you need to provide them with a msbuild command line to compile their code.
  • Finally they can put the .cs code file in the specific folder along with your main project binary and try it out.

Option 2

  • The above option will work only if your users are also programmers.
  • If they are semi-techies, you could provide a simpler format for them to provide the additional events.
  • For example, create a json or xml format where they can specify the event name and how they want to handle it - either a script or choose from some options. For example -
    {
      "myevents": [
      {
        "event": "chatUpvote",
        "handler": "ThankYouHandler"
      },
     {
       "event": "chatDownvote",
       "handler": "TellMeMoreHandler"
      }]
    }
samiksc
  • 167
  • 10