Class AbstractFeaturePage
public abstract class AbstractFeaturePage : IFeaturePage
Inheritance
Implements
Inherited Members
Namespace: HomeSeer.PluginSdk.Features
Assembly: PluginSdk.dll
An abstract implementation of the IFeaturePage interface establishing a basic structure to build a feature page from.
Basic Usage
The AbstractFeaturePage is a simple implementation for a feature page that accepts POST data as a serialized JsonRequest
and responds with JsonRsponse
.
Define a class in your plugin that inherits from AbstractFeaturePage
and implements the required members
public class MyFeaturePage : AbstractFeaturePage {
public override string Title { get; set; } = "My Feature Page";
public override string FileName { get; set; } = "feature-page.html";
}
In the constructor for your class, call AbstractFeaturePage.RegisterRequestCallback()
for each JsonRequest.Request
keyword you want to listen for.
public class MyFeaturePage : AbstractFeaturePage {
private const string LoadPageKey = "load-page";
public override string Title { get; set; } = "My Feature Page";
public override string FileName { get; set; } = "feature-page.html";
public MyFeaturePage() {
RegisterRequestCallback(LoadPageKey, LoadPage);
}
private JsonResponse LoadPage(JsonRequest request) {
try {
return new JsonResponse(request, "page loaded successfully");
}
catch (Exception exception) {
exception.Log();
throw;
}
}
}
See PageActionResponse
for default actions that you can execute through JavaScript from your plugin application.
Constructors
View SourceAbstractFeaturePage()
Create a new instance of an AbstractFeaturePage. Register the IsAlive(JsonRequest) method for feature page access validation.
Declaration
protected AbstractFeaturePage()
Fields
View SourceRequestKeyIsAlive
Declaration
const string RequestKeyIsAlive = "isalive"
Field Value
Type | Description |
---|---|
System.String |
Properties
View SourceFileName
The name of the HTML file that backs this feature page. Ex "my-feature.html"
Declaration
public abstract string FileName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
RequestMap
A map of keys and methods used as callbacks for requests that match their key. Use RegisterRequestCallback(String, Func<JsonRequest, JsonResponse>) and UnregisterRequestCallback(String).
Declaration
protected Dictionary<string, Func<JsonRequest, JsonResponse>> RequestMap { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Func<JsonRequest, JsonResponse>> |
Title
The title of the page. Displayed in the plugin menu and by the browser client.
Declaration
public abstract string Title { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Methods
View SourceGetHtmlFragment(String)
Get a fragment of HTML attached to a particular ID.
Declaration
public virtual string GetHtmlFragment(string fragmentId)
Parameters
Type | Name | Description |
---|---|---|
System.String | fragmentId | The ID of the fragment to get |
Returns
Type | Description |
---|---|
System.String | A fragment of HTML |
Remarks
Used by Scriban.
IsAlive(JsonRequest)
A sample callback method that can be used to validate that a page is up and responding to POSTs
Declaration
JsonResponse IsAlive(JsonRequest request)
Parameters
Type | Name | Description |
---|---|---|
JsonRequest | request | The request data submitted in the POST |
Returns
Type | Description |
---|---|
JsonResponse | Response message of "Title is alive" |
PostBackProc(String, String, Int32)
Respond to an HTTP POST directed at this page.
Declaration
public virtual string PostBackProc(string data, string user, int userRights)
Parameters
Type | Name | Description |
---|---|---|
System.String | data | The body of data attached to the POST |
System.String | user | |
System.Int32 | userRights |
Returns
Type | Description |
---|---|
System.String | The data to return as a string. Use JSON. |
RegisterRequestCallback(String, Func<JsonRequest, JsonResponse>)
Register a callback method to be invoked when a POST request is submitted using a specific key.
Declaration
protected void RegisterRequestCallback(string requestKey, Func<JsonRequest, JsonResponse> callback)
Parameters
Type | Name | Description |
---|---|---|
System.String | requestKey | The key to match the callback method to |
System.Func<JsonRequest, JsonResponse> | callback | A method that takes a JsonRequest as a single parameter and returns a JsonResponse |
Remarks
Calling this successive times with the same key will replace any existing callback method tied to that key.
UnregisterRequestCallback(String)
Unregister an existing callback method so it will not longer be executed when a request is submitted using a particular key.
Declaration
protected void UnregisterRequestCallback(string requestKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | requestKey | The key to stop responding to |