JSS-to-.NET Bridge Extensions

JSS-to-.NET bridge extensions may be used to call into .NET from JSS thus offering wide extensibility to the JSS platform. It might be used, for example, to wrap a simple .NET function so that it may be used in JSS or as a bridge between JSS and a .NET API for a web-service.

A JSS-to-.NET bridge extension is a .NET assembly (usually a DLL) that contains a class that extends the class EnterpriseDT.Net.FtpServer.Core.PlugIn and has one or more methods with the JavascriptInvokable attribute. The assembly can be developed in C#, VB.NET or any other .NET language. If you don't already have Visual Studio then you can use one of Microsoft's free Visual Studio Express or Community products.

Creating a JSS-to-.NET Bridge extension

General instructions on building CompleteFTP extensions may be found here.

JSS-to-.NET bridge extension classes must extend EnterpriseDT.Net.FtpServer.Core.PlugIn. Each method that is to be exposed to JSS must have a JavascriptInvokable attribute. If the JavascriptInvokable attribute specifies a name then this is the name by which the method must be called from JSS. If no name is specified then the name of the .NET method is used.

Arguments may be passed to a method and values returned. Javascript numbers will be cast to .NET doubles; Javascript string will be case to .NET strings; arrays will be cast to List<object>; and Javascript objects will be cast to Dictionary<string, object>.

Example

The following example implements methods that calculate hashes using two algorithms, MD5 and SHA1. Notice that the JavascriptInvokable attributes specify the names that should be used to call them from JSS, i.e. calculateMD5 and calculateSHA1.

using System;
using EnterpriseDT.Net.FtpServer.Http.Javascript;
using System.Web.Security;
using EnterpriseDT.Net.FtpServer.Core;

public class HashFunctions : PlugIn
{
	[JavascriptInvokable("calculateMD5")]
	public string CalcMD5(string s)
	{
		return FormsAuthentication.HashPasswordForStoringInConfigFile(s, "MD5");
	}
	
	[JavascriptInvokable("calculateSHA1")]
	public string CalcSHA1(string s)
	{
		return FormsAuthentication.HashPasswordForStoringInConfigFile(s, "SHA1");
	}
	public override void Dispose()
	{
		throw new NotImplementedException();
	}
	public override void Initialize(IPlugInInfo info)
	{
		throw new NotImplementedException();
	}
}