views:

67

answers:

4

I want a simple, interactive way to demo middle-tier features of my app which have not had a UI created yet. I want an interactive console.

When my application (WPF but it shouldn't matter) boots up I would like to also start a console window. This window should run powershell (or ruby, or python, but preferably powershell) and have its scope set to access my ServiceLocator.

Alternately, I could start up my app and attach to the process appdomain from an external powershell window and grab a reference to the ServiceLocator. Is this even possible?

Anyways, I've created IronRuby engines and set variables in scopes before but if I went that route I would need to essentially create my own console input/display mechanism.

Does anyone know of a better way to go about this?

A: 

I've grown rather fond of Visual Studio's Immediate window where I can simply type assignments or call functions while debugging. It's obviously not what you're looking for, but if you or other readers aren't aware of it, it certainly is very useful.

Charlie Salts
Yeah, its good stuff but namespacing is a hassle and you can't use it while the apps is running so you can't do things like launch windows. Matter of fact, I just tried to grab a reference to ServiceLocator.Current and it doesn't work
George Mauer
A: 

Any Windows application can create a console by calling the Windows AllocConsole API function. Unfortunately, the .NET Console class doesn't expose that functionality. A few years back, I wrote a series of articles and some code to extend the .NET Console interface and included AllocConsole support. Unfortunately, DevSource seems to have lost the first article in that series.

Here are the two functions you'll want:

[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool AllocConsole();

[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool FreeConsole();

You can download the full extended console support package from my Web site: http://mischel.com/pubs/consoledotnet.zip

Jim Mischel
When you say the console runs alongside the app, what is the scope inside the console? I don't understand how this works if I'm not directly injecting variables for the scope
George Mauer
I'm a bit unclear on all what's involved in setting the scope for your ServiceLocator. I suspect you'd have to find some way to directly inject those variables. Sorry, I didn't fully grok the intent of your question.
Jim Mischel
Yeah, I can start a console even through just an explicit call to cmd.exe, but I have no idea how to inject that variable then. On the other hand, its pretty simple to inject them into scripts, but creating a console then would be a hassle
George Mauer
A: 

Take a look at this article: PowerShellTunnel - Script your App from PowerShell at Runtime

LBushkin
Haven't read it fully yet, but this seems to have to do with WCF. Mine is a desktop app - I don't want to be setting up WCF endpoints, I just access to one variable in the appdomain
George Mauer
@George Maur: You have to do some kind of IPC one way or another. It's easy enought to set up named pipe endpoints between both processes. Named pipes are fast, don't require anything that's not available to desktop apps, and are easy to work with.
LBushkin
Well that's not necessarily true, it's not necessary that the console run in a different process. Thanks for the advice though, I'll look into named Pipes - I've never done it before
George Mauer
A: 

The June 20 episode of the CodeCast podcast featured an interview with Jimmy Schementi of the Iron Python team, and he talked about an IronPython Interactive DLR Console in Silverlight. Here's the demo site: http://ironpython.net/ironpython/browser/examples/dlrconsole/

Brian Schroer
Heh, I saw that but haven't listened to it yet. Funny since I actually work for CoDE.
George Mauer