This post is, obviously, for developers out there looking for next big opportunity, more specific, for .net developers because iPDF is developed in C# - our favored language.
Essentially, iPDF is not yet another office productivity app. It's a platform. A third party developer, which literally means you, can develop plugins to extend its capabilities. iPDF provides the infrastructures like the ribbon user interface, adding items to the data grid, processing them, notifying user when done, etc. You only have to focus on specific functionality you intend to implement.
In iPDF 1.0, third party developer can only add web service to the services gallery on the Publish tab. With next release, which is due out in August, you will be able to add tabs, add galleries, pop up a notification to user, add your own column to the data grid, scripting iPDF using a BOO like language, and more. Oh, one side note, we are going to use MEF (Managed Extensibility Framework). Stay tuned.
Okay, enough for the next release. This post is primarily about how to develop a web service plugin for the Services gallery on the Publish tab. Let's get started!
First, let's dive into how iPDF loads those web services plugins. On startup, iPDF scan the 'Services' folder in the iPDF installation directory for DLL files in a background thread. For each dll, iPDF uses .net reflection API to determine if it contains one class which inherits from a certain class called CloudService. If it does, then iPDF will instantiate one instance of that class, adds it to the services gallery with an icon supplied by that class. And when user does a certain action on the Publish tab, the action will be delegated to the current selected service instance to do something about. And that's pretty much it.
You probably are wondering what this CloudService class looks like. Well, read on.
The below is how it looks like in .NET Reflector. Of course, I decorated it a bit.
public abstract class CloudService : IDisposable
{
//Methods
//return if a folder with a given name exists. optional
public virtual bool ContainsFolder(string folderName);
//return if a folder with a given name exists in a group of folders. optional
public virtual bool ContainsFolder(string folderName, IEnumerable<object> folders);
public virtual void Dispose();
//login. required
protected abstract void Login(NetworkCredential token);
//logout. required
public virtual void Logout();
//make a new folder with the cloud service. optional
public virtual void MakeNewFolder(string folderName);
//reload all folders. optional
public void ReloadFolders();
//search a keyword in the folders. optional
public virtual List<object> SearchFolders(string keyword);
//upload file. required
public virtual void Upload(string fileName);
// Properties
//access control level of the web service. optional
public AccessControl AccessControlLevel { get; set; }
//the web url of the web service
public Uri CloudUrl { get; protected set; }
//the user credential of a certain user. required
public NetworkCredential Credential { get; set; }
// the folders of a certain user on the web service. optional
public virtual object[] Folders { get; protected set; }
//the icon of the web service
public virtual Image Icon { get; protected set; }
//indicate whether the current user is logged in the web service
protected bool LoggedIn { get; set; }
//the name of the web service
public string Name { get; protected set; }
//the user selected folder to upload files into
public object SelectedFolder { get; set; }
//indicate whether the plugin supports access control
public bool SupportAccessControl { get; set; }
//indicate whether folder is supported by the plugin
public bool SupportFolder { get; protected set; }
//indicate whether the web service supports making new folder
public bool SupportNewFolder { get; protected set; }
//the file formats supported by the web service
public List<FileFormat> SupportedFormats { get; protected set; }
//the validator to validate if a password is valid for the web service. optional. If omitted,
//the default one is used
public virtual IValidator UsernameValidator { get; }
//the validator to validate if a password is valid for the web service. optional. If omitted,
//the default one is used
public virtual IValidator PasswordValidator { get; }
}
As a plugin developer, you have to implement a class that inherits from the CloudService and plug into iPDF by placing your assembly in the 'Service' folder. And that's it.