Search Results for

    Show / Hide Table of Contents

    Class AbstractFeaturePage

    • C#
    • Visual Basic
    public abstract class AbstractFeaturePage : IFeaturePage
    Public MustInherit Class AbstractFeaturePage
        Implements IFeaturePage
    Inheritance
    System.Object
    AbstractFeaturePage
    Implements
    IFeaturePage
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    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

    • AbstractFeaturePage.Title
    • AbstractFeaturePage.FileName
    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 Source

    AbstractFeaturePage()

    Create a new instance of an AbstractFeaturePage. Register the IsAlive(JsonRequest) method for feature page access validation.

    Declaration
    • C#
    • Visual Basic
    protected AbstractFeaturePage()
    Protected Sub New

    Fields

    View Source

    RequestKeyIsAlive

    Declaration
    • C#
    • Visual Basic
    const string RequestKeyIsAlive = "isalive"
    Const RequestKeyIsAlive As String = "isalive"
    Field Value
    Type Description
    System.String

    Properties

    View Source

    FileName

    The name of the HTML file that backs this feature page. Ex "my-feature.html"

    Declaration
    • C#
    • Visual Basic
    public abstract string FileName { get; set; }
    Public MustOverride Property FileName As String
    Property Value
    Type Description
    System.String
    View Source

    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
    • C#
    • Visual Basic
    protected Dictionary<string, Func<JsonRequest, JsonResponse>> RequestMap { get; set; }
    Protected Property RequestMap As Dictionary(Of String, Func(Of JsonRequest, JsonResponse))
    Property Value
    Type Description
    System.Collections.Generic.Dictionary<System.String, System.Func<JsonRequest, JsonResponse>>
    View Source

    Title

    The title of the page. Displayed in the plugin menu and by the browser client.

    Declaration
    • C#
    • Visual Basic
    public abstract string Title { get; set; }
    Public MustOverride Property Title As String
    Property Value
    Type Description
    System.String

    Methods

    View Source

    GetHtmlFragment(String)

    Get a fragment of HTML attached to a particular ID.

    Declaration
    • C#
    • Visual Basic
    public virtual string GetHtmlFragment(string fragmentId)
    Public Overridable Function GetHtmlFragment(fragmentId As String) As String
    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.

    View Source

    IsAlive(JsonRequest)

    A sample callback method that can be used to validate that a page is up and responding to POSTs

    Declaration
    • C#
    • Visual Basic
    JsonResponse IsAlive(JsonRequest request)
    Function IsAlive(request As JsonRequest) As JsonResponse
    Parameters
    Type Name Description
    JsonRequest request

    The request data submitted in the POST

    Returns
    Type Description
    JsonResponse

    Response message of "Title is alive"

    View Source

    PostBackProc(String, String, Int32)

    Respond to an HTTP POST directed at this page.

    Declaration
    • C#
    • Visual Basic
    public virtual string PostBackProc(string data, string user, int userRights)
    Public Overridable Function PostBackProc(data As String, user As String, userRights As Integer) As String
    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.

    View Source

    RegisterRequestCallback(String, Func<JsonRequest, JsonResponse>)

    Register a callback method to be invoked when a POST request is submitted using a specific key.

    Declaration
    • C#
    • Visual Basic
    protected void RegisterRequestCallback(string requestKey, Func<JsonRequest, JsonResponse> callback)
    Protected Sub RegisterRequestCallback(requestKey As String, callback As Func(Of JsonRequest, JsonResponse))
    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.

    View Source

    UnregisterRequestCallback(String)

    Unregister an existing callback method so it will not longer be executed when a request is submitted using a particular key.

    Declaration
    • C#
    • Visual Basic
    protected void UnregisterRequestCallback(string requestKey)
    Protected Sub UnregisterRequestCallback(requestKey As String)
    Parameters
    Type Name Description
    System.String requestKey

    The key to stop responding to

    Implements

    IFeaturePage
    • View Source
    In This Article
    Back to top HomeSeer Technologies