I think this can be "almost" done with existing software and firmware
You connect up what ever activates the solenoid to a spare IO pin via standard electronics (Google solenoid on arduino)
Now you can manually control the solenoid with the G42 command [
reprap.org]
In slic3r for eg you now set up two extruders and under custom gcode is the tool change gcode. you should be able to set this with the G42 command above and any retraction/extrusion commands needs to get things in the right place.
Only think im not quite sure about is you need a if statement somewhere, ie e0 solinoid on, or e1 soliniod off... but im sure its do able
may need your own post processor for this...