Today I started writing an API which allows me to easily access Gadget "packages" programmatically. Here's a little snippet of my sample code that uses my API:
// Open a Gadget package and returns it as a strongly-typed object model.
Gadget gadget = Gadget.Open(existingGadgetPath);
// displays the name in the manifest file
Console.WriteLine(gadget.Manifest.Name);
foreach (GadgetFile file in gadget.Files) {
if (file.FileName == "main.js") {
string js = file.Text;
file.Text = UpdatePersonalizationKey(file);
}
}
Gadget.Create(gadget, newGadgetPath);
This code opens an existing Gadget, updates some of the JavaScript in the main .js file, and then saves the files back as a new package.
Code such as this would be really useful for personalizable gadgets, picture the following scenario:
You have created a gadget that will be downloaded from your website. Users fill in a form and then get access to the gadget - maybe it's a valuable gadget such as a custom financial investment research gadget.
Now you want to be able to track usage of the gadget and potentially push some targetted advertising down into the gadget as well. Using the above gadget packaging API code you could easily embed a personalization key into the gadget which would then get passed along with each web service call made by the gadget. This would allow you to easily track gadget usage and to provide personalized services and ad views to the gadget user.
Now that I'm creating my gadget API I'm also thinking about building a small IDE which will allow people to easily create new gadgets and browse existing ones. I'm thinking that you could easily create something which gives people a simple File|New or File|Edit experience over gadgets.