(picture)

April 08, 2003

About SendTo

Here's a brief description of what this SendTo code is and how it works.

This is string-and-glue tech. There's no compiled code here: it's all JavaScript and HTML. Which is to say: it works, and debugging is very easy, but I wouldn't necessarily recommend deploying a solution this way...!
The pieces are:

  • a JavaScript library (.js) which defines "classes" (almost everything in JavaScript is a hashtable, so a "class" is an object with named properties which are its method functions) which implement the SOAP interface. The class structure is quite closely modeled on the WSDL definitions provided for GWS.
  • a HTML Application (.HTA) in my startup. This does the heavy lifting. At startup it looks into Groove and walks through my shared spaces, looking for files tools. It also scans contacts. Then it sets up subscriptions, and a timer on which we'll ask Groove whether there are any queued events (new or modified tools, new shared spaces, and so on).
  • For each contact it creates a shortcut, in a folder under the Start menu, The shortcut icon shows whether the contact is online or offline. The target for the shortcut is another .HTA: when you click the shortcut, it sends the contact's URL to the launcher HTA, which then tells Groove (using the "Transceiver" web service) to pop up the instant-message UI addressed to this person. If the contact subscription fires an event, we recreate the shortcut, to show the current awareness state in its icon.
  • For each files tool it creates a shortcut, in a folder under the SendTo menu. The folder gets a desktop.ini pointing at an appropriate icon. The shortcut points at a batch file, which... (this is where things get complicated!).

SendTo is more complicated, unfortunately. When you click a SendTo shortcut, you're effectively initiating a drag-and-drop operation (as if you'd dropped the file onto an application or a folder). Now, HTA applications aren't usually "drop targets", but batch files are (so I don't need to write code implementing IDropTarget). So each drop target -- the target of the SendTo shortcut -- is a little batch file which launches a helper HTA with some appropriate parameters.
The parameters are: obviously the path of the file you just dropped on the shortcut; but also, the URL of the Files tool where the file should be delivered. So the batch files get that URL written into them when they're created. Then there's one batch file per tool, corresponding to the shortcut file. It's clunky.

The launcher application ("GWSSendTo.hta") is really really simple. All it needs to do is: read the commandline parameters, open the file, and stream the file into the Groove tool. The code is this.

// commandline gives us:
// sIdentityURL (the current Groove user),
// sToolDataURI (the address of the Groove files tool) and
// sFilePath (the file we had dropped)

// Initialize the GWS context for localhost SOAP
pCtx = g.CreateLocalContext( GetGrooveNonce(), GetGroovePort() );
pCtx.SetIdentity( sIdentityURL );

// Set up our reference to the tool
var pFilesData = new g.GrooveFilesData()
pFilesData.SetContext( pCtx );
pFilesData.SetURI( sToolDataURI );

// Create a descriptor for the new file in Groove
var pNewFile = new g.GrooveFileDescriptor( sFilePath );

// Create the new file in Groove
pFilesData.Create( pNewFile );

That's it. A dozen lines of code.