Testing your CommandProxy-based AIR app.
I watched a Battlestar Galactica episode recently, and I got to wondering what that soupy bathwater is that the cylons keep waking up in. Sometimes, I feel like all AIR developers are drifting asleep in that same soupy spa, dreaming of the day they can launch processes directly from AIR.
But most AIR developers have woken up gasping and screaming like on the TV show (why can’t they just shake them gently and say “you’ve been downloaded and reborn…there there…want some toast?”) with the realization that AIR does not let you do things like launch processes or have command-line access.
Personally I think the AIR team will someday address this issue, but until then you’ll need to use something like the CommandProxy pattern as suggested by Mike Chambers.
Chamber’s code will get you up-and-running, you just need to figure out how to compile it within C# and use the command classes he’s suggested for communicating with the proxy. (As well as think about the security issues some have raised, see Chamber’s follow-up post.)
However, using the CommandProxy will affect your testing if you chose to run your AIR app with the AIR Debug Launcher (ADL).
As most of you probably know, you can get debug messages out of an installed AIR app by running it via ADL. You’ll have to:
- Make sure the ADL.exe is in your classpath
- Add the AIR .xml application description file to your installation directory if it’s not already there
- Run the app not by clicking the .exe but by typing “ADL myAppName-app.xml”
But remember, these days you’re floating in soupy bathwater: if you’re using CommandProxy, you have to change the launch code inside the proxy to get ADL to launch your app.
To this, modify the lines in the LaunchAndRun() method in the CommandProxy.cs file to get the proxy to launch ADL rather than the .exe directly.
I did this by simply changing the processPath variable to “adl.exe”
processPath = "adl.exe";
and then modifying the following line
p.StartInfo.Arguments = authToken + " " + port;
to this…
p.StartInfo.Arguments = "myApp-app.xml -- " + authToken + " " + port;
You could probably figure out a cleaner way to do this — perhaps setting a boolean in your csproxy.cs class to quickly switch between testing to implementation builds of the CommandProxy.
Explore posts in the same categories: Uncategorized
June 6th, 2009 at 8:42 pm
Nice tip on ADL. For the benefit of newbs like me, if you have a working AIR sample app that uses the AS3 libraries, it’d be super sweet if you could share it. Thanks in advance.
June 8th, 2009 at 11:37 am
Bill,
Thanks for the note. I can’t share the entire project, but if you’re looking to run your app through ADL when using the CommandProxy.exe approach, all you need to do is :
1) Make sure you have the AIR SDK installed and the ADL.exe in your path
2) Change up the code in the CommandProxy.cs file (by Mike Chambers) to launch YourAirApp.exe via ADL rather than directly.
3) Compile your C# project twice, once for the regular CommandProxy.exe and once for your “run it through ADL” proxy, which I call CommandProxyDebugger.exe
So, to do steps two and three,
– add this line to your CommandProxy.cs file in the class declarations section (I added mine around line 65)
private bool testingMode = false
Then modify the LaunchAndRun function like so…
public void LaunchAndRun(string processPath)
{
try
{
//DMcQ: If we’re testing, don’t use usual path…instead launch program through ADL for debugging info
if (testingMode == true)
{
processPath = “adl.exe”;
}
//create process to start the AIR app
Process p = new Process();
//set path to air app
p.StartInfo.FileName = processPath;
Console.WriteLine(authToken + ” ” + port);
//If we’re testing, we have to pass in arguments a little different…. first argument is xml descriptor for ADL, then two dashes before normal arguments
if (testingMode == true)
{
p.StartInfo.Arguments = “application.xml — ” + authToken + ” ” + port;
}
else
{
//sdet command line arguments. pass in authToken and port to use
p.StartInfo.Arguments = authToken + ” ” + port;
}
p.StartInfo.UseShellExecute = true;
Console.WriteLine(”starting : ” + processPath);
//start process
p.Start();
//start the run loop
Run();
}
catch (Exception e)
{
Console.WriteLine(”error : ” + e.Message);
Quit();
//todo: should we throw an error here?
throw e;
}
}
Then, compile two versions of your CommandProxy.exe, setting the testingMode to false for CommandProxy.exe and to true for a CommandProxy.exe that runs through ADL (I rename mine to CommandProxyDebugger.exe)
FINALLY…important note. ADL wants the application.xml file to be in the root directory, so COPY (not move) application.xml from [your apps install directory]\META-INF\AIR\application.xml to [your app's install directory]\application.xml
This might all look like craziness to somebody who uses C# and VisualStudio regularly, but it was enough to get the job done for me.
BTW .. original code is from Mike Chambers. See his blog posts (mentioned in my post above) for original code.
June 10th, 2009 at 6:30 am
Thanks, that was help info in ADL. But I am still stuck on how to properly use the .as code from an AIR app (since no usage exampe was provided in the original code, I had expected something like a simple AIR app that displays a screen capture).