0

I have an existing program that I have to work around. It provides a fairly decent plugin architecture, but I've run into a problem. I need to create a command-line plugin that will check if the program is already running and then pass the command-line parameters to the existing instance.

Is this possible using a plugin? Would best practice in a situation like this be to use the messaging system?

Josh
  • 632
  • 7
  • 13
  • 1
    Could you provide what you have already, or some information on the plugin architecture of the program you're working with? – Cashley Feb 05 '13 at 17:02
  • The plugin architecture is fairly open. It uses a series of interfaces to determine what kind of plugin you're developing. The interfaces basically give you SetupPlugin(PluginArgs) and TeardownPlugin() to initialize (passing in the program's form and some other information) and destroy the plugin. PluginArgs gives most everything you need to access the program itself; SetupPlugin allows you to do most anything you wish. – Josh Feb 05 '13 at 17:20

1 Answers1

0

For the scenario you describe, I have used a WCF service hosted over the net.pipe protocol. Basically, I have a contract that defines an endpoint that can receive the information that you would provide as command-line arguments.

When your process starts, it first attempts to contact this service. If the service is available, that means an existing process is already up and running. In that case, open a channel to the process, send the data to it, and then exit. If the service is not available, start the service.

Dan
  • 9,717
  • 4
  • 47
  • 65
  • Let me be sure I understand correctly: I would create a plugin that starts a service and begins listening. This plugin would respond to commands given, manipulating the existing program as needed. I'd also either create another plugin or add to that plugin a command-line portion (avoids initializing the whole program if unnecessary) that would attempt to contact the service and send it a valid set of parameters. Sorry if I'm just repeating back--I'm fairly new to this and trying to be sure I've got it in my head what needs to be done. – Josh Feb 05 '13 at 17:24
  • That sounds right to me. If you could provide more details, so could I. – Dan Feb 05 '13 at 20:26
  • I've provided some details in the comment above, responding to Cashley. To add a few more: I'm trying to put together a custom application URI that would allow a user to click a web link, opening the program in question to a particular point. I'd _like_ to do that directly, but the program doesn't seem to support a single-instance setup or command-line parameters without plugins. – Josh Feb 06 '13 at 06:22
  • @Dan, I am attempting to do something similar to this. But i have no idea how to host a WCF service over the net.pipe protocol. I want to define a contract that defines an endpoint that can receive information from a process. When the process starts it has to contact this service and provide the information i need. Could you please provide me a skeleton of code to accomplish this? I feel that you might have done exactly what i am looking for. – Anee Sep 04 '13 at 07:01
  • @Anee Here's a link to some code that has a net.pipe service: http://stackoverflow.com/a/16097909/1507012 – Dan Sep 04 '13 at 19:36