State
A state extension is a component that can trigger custom events during a web form session. A state extension works in much the same way as a Delivery Extension but is triggered when the ‘Next’ and ‘Save’ buttons are used rather than upon the completion of a web form.
Information
There are no packaged State Extensions in Infiniti. Most tasks can be handled by other out-of-box features.
Important
This guide is not a real-world example of something you would want to implement but provides an idea of how the code could work. If you feel that a State Extension is required for your project, determine what you need and contact your account representative for technical assistance.
Extension Development Walkthrough
The walkthroughs below have been created using Microsoft’s Visual Studio 2017. All sample code is based version 7.0 of the C# language and version 4.6.2 of the .NET Framework.
For this "SimpleState" state extension we will save a backup copy of the answer file to another system each time the user navigates through a form. A third party system could retrieve it and reuse in the future.
Note:
In the example below, the standard save is set to true, no UI is returned and the changing page method saves a file to disk by.
- Open Visual Studio and create a new Class Library Project and give it a meaningful name. For this example, we will use ‘SampleStateExtension’. Ensure that the .NET Framework 4.6.2 is selected.
- Rename Class1 to something more meaningful such as ‘SimpleState’.
- Click ‘Yes’ to the rename all references prompt.
- Add the following references to the project.
Intelledox.Extension.dll
Intelledox.Extension.State.dll
Intelledox.QAWizard.dll
Intelledox.QAWizard.Design.dll
Intelledox.Model.dll
Note
Infiniti References (usually located
C:\inetpub\wwwroot\Infiniti\Produce\bin
).
Good Practice
- Reference Paths point to correct Infiniti deployment path.
- Copy Local property should be set to
False
for all Infiniti References, as this could corrupt your instance if an older reference is copied to an upgraded site.
- Inherit the
Intelledox.Extension.State.StateExtension
and override necessary StateExtension methods, as per the sample below.
using System;
using System.IO;
using Intelledox.Extension.State;
using Intelledox.QAWizard;
namespace SampleStateExtension
{
public class SimpleState : StateExtension
{
public override ExtensionIdentity ExtensionIdentity
{
get => throw new NotImplementedException(); protected set => throw new NotImplementedException();
}
public override void AnswerFileSaving(StateProperties properties)
{
throw new NotImplementedException();
}
public override void ChangingPage(StateProperties properties, PageChangeArguments direction)
{
throw new NotImplementedException();
}
public override bool UseStandardSave(StateProperties properties)
{
throw new NotImplementedException();
}
public override void WriteHtml(StateProperties properties, TextWriter writer)
{
throw new NotImplementedException();
}
}
}
Method | Description |
---|---|
AnswerFileSaving | Called when a user clicks the save button during a web form. |
UseStandardSave | A flag indicating if Infiniti should carry out its regular save routine when the user clicks save. I.e. if a custom save feature has been implemented it may be appropriate to ‘turn off’ the standard Infiniti save. |
ChangingPage | Called when a user navigates forward or backward through the form’s Pages |
WriteHtml | Allows a custom UI such as a button to be displayed in the form |
Build Successfully
The project should build at this point without error.
- Implement the
ExtensionIdentity
property so that it initializes theExtensionIdentity
object containing anId
and aName
to register the State within Infiniti. TheId
needs to be unique and theName
is displayed to the user in Design.
public override ExtensionIdentity ExtensionIdentity { get; protected set; } = new ExtensionIdentity()
{
Id = new Guid("E69C5643-F9B1-4DAC-935F-89A256D4441F"),
Name = "Infiniti Simple State Extension"
};
- Implement the
ChangingPage()
method as per sample below.
public override void ChangingPage(StateProperties properties, PageChangeArguments direction)
{
File.WriteAllText(@"c:\Temp\" + properties.Context.Wizard.WizardSession.Variables.RunId + ".xml", properties.GetAnswerFile());
}
Deploying a State Extension
State Extensions are deployed to an Infiniti environment by copying the State Extension dll file to the Produce bin directory and referencing it within Produce’s appsettings.json
file.
-
Locate your
SampleStateExtension.dll
file and copy it to the Produce bin directory (usually locatedC:\inetpub\wwwroot\Infiniti\Produce\bin
). -
Open the produce
appsettings.json
file and locate the “Extensions” section of the file. -
Add a new State extension element using the following syntax to the
appsettings.json
"ClassName (including namespace), AssemblyName"
Examle:
"Extensions": [
"Intelledox.Extension.ActionBuiltin.PrintAction, Intelledox.Extension.ActionBuiltin",
"Intelledox.Extension.ActionBuiltin.UserAction, Intelledox.Extension.ActionBuiltin",
"Intelledox.Extension.ActionBuiltin.WebhookAction, Intelledox.Extension.ActionBuiltin",
"Intelledox.Extension.ActionBuiltin.RESTAction, Intelledox.Extension.ActionBuiltin",
"Intelledox.Extension.ActionBuiltin.OracleAction, Intelledox.Extension.ActionBuiltin",
"Intelledox.Extension.ActionBuiltin.PushNotificationAction, Intelledox.Extension.ActionBuiltin",
"Intelledox.Extension.EscalationBuiltin.EmailEscalation, Intelledox.Extension.EscalationBuiltin",
"Intelledox.Extension.EscalationBuiltin.ReassignmentEscalation, Intelledox.Extension.EscalationBuiltin",
"Intelledox.Extension.EscalationBuiltin.PushNotificationEscalation, Intelledox.Extension.EscalationBuiltin",
"SampleStateExtensions.SimpleState, SampleStateExtensions"
],
- Save the
appsettings.json
file. - Navigate to Produce in your browser, an absence of error messages suggests the State Extension has installed correctly.
- Open an existing form in Infiniti Produce and run. Make sure it saves answer files in C:\temp as expected as users navigate through the form.
More Examples
More examples are available in Intelledox Github account
Debugging State Extension
After deploying a State Extension, it can be debugged by attaching Visual Studio to the w3wp.exe process and triggering the State Extension from Produce, in this case navigating through a web form.
Azure PaaS
Final Full Code
using System;
using System.IO;
using Intelledox.Extension.State;
using Intelledox.QAWizard;
namespace SampleStateExtension
{
public class SimpleState : StateExtension
{
public override ExtensionIdentity ExtensionIdentity { get; protected set; } = new ExtensionIdentity()
{
Id = new Guid("E69C5643-F9B1-4DAC-935F-89A256D4441F"),
Name = "Infiniti Simple State Extension"
};
public override void AnswerFileSaving(StateProperties properties)
{
// Called when the user is saving an answer file in the form
// properties.GetAnswerFile();
throw new NotImplementedException();
}
public override void ChangingPage(StateProperties properties, PageChangeArguments direction)
{
// Called each time the user navigates to a different page in the form. Either
// forwards or backwards
File.WriteAllText(@"c:\Temp\" + properties.Context.Wizard.WizardSession.Variables.RunId + ".xml", properties.GetAnswerFile());
}
public override bool UseStandardSave(StateProperties properties)
{
// Whether Infiniti should carry out its regular save routine when the user clicks save
throw new NotImplementedException();
}
public override void WriteHtml(StateProperties properties, TextWriter writer)
{
// Allows a custom UI such as a button to be displayed in the form.
throw new NotImplementedException();
}
}
}
Updated over 6 years ago