How to run stuff with custom enviroment variables in C#

Programming has changed allot since I got started, it used to take forever to create compelling user interfaces Microsoft made that better by providing common controls, and then tools to build basic UIs on those common controls (Visual Basic, MFC, and later WinForms).

This is all fantastic, but along the way people stopped creating compelling command line interfaces (CLIs) for applications. There are lots of reasons for this, clearly one of which is that most users today don't use the command line and most can't script.

The problem is I can and do, it’s a great way to automate the mundane (which computers are good for after all).

This rant had me thinking about one of the feature requests I have for My Movies; specifically I want the ability to invoke external applications for specific scenarios. It actually does this today for Daemon Tools and TheaterTek integration but I would like it to be generalized so that it is event based.

Basically I think there should be scenario based events exposed in the add-in, for example there might be:

1.     Add Movie:Begin - Invoked when a movie add has begun.

2.     Add Movie:Complete - Invoked when a movie has been successfully added to the database.

3.     Play Movie:Begin - Invoked before a move is to be played.

#2 would accommodate scenarios like Daemon Tools and TheaterTek while #1 would allow me to make My Movies the 1st step (possibly only step) involved in adding titles to my collection.

How would this work? Well I would imagine there being a advanced setting that allows me to specify what command  line to invoke for these events, I might even be able to specify a series of them to complete one right after another.

What this logic would do is identify key meta data that would be useful to a script invoked at this time, for example for Add Movie I would want to know information about what movie was just added maybe the data would include:

  • MYMOVIES_DB_PATH - The path of the My Movies database.
  • MYMOVIES_MOVIE_ID - The unique id (in the database) for the movie that was just acted against.

My Movies would set these values via ProcessStartInfo as well as some other settings, for example:

It would also not invoke the script directly instead it would invoke cmd.exe with some arguments, specifically the /C argument which says run the following command and exit (e.g. 'cmd.exe /c "cscript foo.vbs"' runns cscript foo.vbs within a command session").

Arguments can be set via the ProcessStartInfo.Arguments property, this is how you would set "/c" and "cscript foo.vbs".

The only thing missing for this to work generically is to be able to have the script communicate errors back to My Movies, to do this you would just listen for the ExitCode to be a non-zero value and if it did take the StandardError output and include it in my My Movies log file.

Well now we know how we could add this functionality but what would we use it for?

Well it depends on the event, let’s look at some ideas for Play Movie:Begin:

1.     Script could look at meta data for the title to determine how to invoke the player, for example maybe it could look in the database to see the title is a particular aspect ratio and invoke the player in the best way given that aspect ratio.

2.     Script could be written to integrate alternatives to Daemon Tools, this assumes this is how Daemon Tools itself was integrated.

3.     Script could be written to integrate alternatives to TheaterTek, this assumes this is how TheaterTek itself was integrated.

4.     Script could be used to integrate with displays utilities like FrontView.

For Add Movie:Begin, you could stop any programs that interfere with the addition of a movie.

For Add Movie:Complete, some options are:

1.     Could undo anything done in the Add Movie:Begin phase.

2.     Could be used to rip copy a movie into the location specified in the collection management experience.

3.     Could be used to keep the folder art in the shell in sync my movies.

4.     Could be used to create dvdid.xml files for movies added into my movies.

Extensibility is a great way to build community support for a program, it makes folks feel like it is their own.

Well that the end of my rant on this today,

 

Print | posted on Sunday, March 18, 2007 12:19 PM

Feedback

No comments posted yet.
Title  
Name  
Email
Url
Comments   
Please add 6 and 8 and type the answer here: