Custom Handler

If functionality is needed that isn't included in the built-in modules or extensions, the hybrid integration can be extended to provide custom modules with properties, methods, and events.

Contact sales@wisej.com to get a quote for custom integrations.

Handlers

Handlers are used to link the server-side and client-side (MAUI) integrations. Handlers implement the IClientHandler interface and provide several methods for processing requests from a Wisej.NET application which can be used to wire custom properties, methods, and events.

Example Client-Side Handler Integration

/// <summary>
/// Client-side integration for mathematical operations.
/// </summary>
internal class MathHandler : IClientHandler
{
	string IClientHandler.Identifier => "math";

	bool IClientHandler.ProcessRequest(DeviceRequest request)
	{
		var num1 = request.Arguments[0];
		var num2 = request.Arguments[1];
	
		switch (request.Action)
		{
			case "add":
				App.FireModalResponse(Add(num1, num2));
				return true;

			case "subtract":
				App.FireModalResponse(Subtract(num1, num2));
				return true;

			default:
				return false;
		}
	}

	void IClientHandler.Reset()
	{
		// reset the UI changes.
	}

	private DeviceResponse Add(int num1, int num2)
	{
		return new DeviceResponse(num1 + num2);			
	}

	private DeviceResponse Subtract(int num1, int num2) 
	{
		return new DeviceResponse(num1 - num2);			
	}
}

Registering Client-Side Handler

App.

Example Usage on Server

var result = Device.PostModalMessage("math", "add", 1, 2);

Information Providers

Information providers are used to extend the Device.Info member. They provide information on startup about the client hybrid device and its capabilities. New information providers can be registered by adding a new IClientInfoProvider.

Example Client-Side Information Provider

/// <summary>
/// Provides a random Guid on startup.
/// </summary>
public class GuidInfoProvider : IClientInfoProvider
{
	/// <summary>
	/// Creates a new instance of <see cref="GuidInfoProvider"/>.
	/// </summary>
	public GuidInfoProvider() { }

	Dictionary<string, string> IClientInfoProvider.ProvideConfiguration()
	{
		var config = new Dictionary<string, string>();

		foreach (var property in typeof(VersionTracking).GetProperties())
		{
			config.Add("guid", Guid.NewGuid().ToString());
		}

		return config;
	}
}

Example Implementation on Server

public class DeviceGuidInfo
{
	public DeviceGuidInfo()
	{
		var base64 = Application.QueryString["info"];
		using (var stream = new MemoryStream(Convert.FromBase64String(base64)))
		{
			var info = JSON.Parse(stream);

			this.Guid = info.guid;
		}
	}
	
	/// A random guid.
	public string Guid
	{
		get;
		internal set;
	}
}

Example Usage on Server

var guid = Device.Info.Get<DeviceGuidInfo>().Guid;

Last updated