NBoomackClient
Show / Hide Table of Contents

Evaluation Request

Evaluation requests send JavaScript code to the Boomack Server, which passes it along to every connected web client — web browser window or tab, showing a specific panel — for evaluation.

The script is not stored on the server but only passed along to connected web clients. If no web client is connected the script is discarded with no effect.

The following examples assume you already have a configured BoomackClient instance in the variable client. See Get Started if you do not know how to configure a BoomackClient instance.

Sending a String

Basic style:

var request = new EvaluationRequest()
{
    Panel = "my-panel",
    Script = "window.alert('Hello World!');",
};
await client.Evaluate(request);

Fluent style:

await client.Evaluate(builder => builder
    .Target("my-panel")
    .Script("window.alert('Hello World!');"));

Sending a Stream

Sending a stream is an allpurpose tool of course, but particularly useful for embedded manifest resources.

Important: A stream passed inside an evaluation request is disposed automatically by the Boomack client.

In order to use this approach, you include a JavaScript file into your project and set the build action in the properties to embedded resource. Then you can open the stream by building a name with the namespace and location of the file inside the project folder. Path separators are converted from slashes into dots. Instead of concatenating the namespace prefix yourself, you can pass a type, in order to use its namespace as prefix.

Example:

  • Project Root
    • MyProject.csproj
    • ClientScripts
      • Hello.js

Assuming the default namespace of your project is MyDemo.Boomack you can use the following code to open a stream to embedded resources in the ClientScripts folder.

namespace MyDemo.Boomack
{
    internal static class ClientResources
    {
        public Stream OpenClientScriptStream(string name)
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            // looks up the manifest resource MyDemo.Boomack.ClientScripts.Hello.js
            return assembly.GetManifestResourceStream(
                typeof(ClientResources), "ClientScripts." + name)
                ?? throw new ArgumentException("Resource not found", nameof(name));
        }
    }
}

Basic style:

var request = new EvaluationRequest()
{
    Panel = "my-panel",
    Stream = ClientResources.OpenClientScriptStream("Hello.js");
};
await client.Evaluate(request);

Fluent style:

await client.Evaluate(builder => builder
    .Target("my-panel")
    .Stream(ClientResources.OpenClientScriptStream("Hello.js")));

Sending a Local File

Basic style:

var request = new EvaluationRequest()
{
    Panel = "my-panel",
    Stream = File.OpenRead("my-script-file.js"),
};
await client.Evaluate(request);

Fluent style:

await client.Evaluate(builder => builder
    .Target("my-panel")
    .LocalScriptFile("my-script-file.js"));

Evaluation Request Builder

The comfort of the fluent API comes from the interface IEvaluationRequestBuilder and extension methods from DefaultEvaluationRequestBuilderExtensions.

The builder comes with convenience methods for setting metadata, as well as methods for specifying the source of the JavaScript code.

Metadata

  • Target(string panel = null)
    Sets the target panel.

Content

The following methods belong directly to the IEvaluationRequestBuilder interface:

  • Script(string script)
    Sets the given string as script code.
  • Stream(Stream stream)
    Sets the given stream as script source.

The following methods are implemented as extension methods:

  • LocalScriptFile(string path)
    Stream a local file as JavaScript code.

Next: Panel Management

In This Article
Back to top
Boomack Homepage