Aras Innovator Platform

4.3 Content Generator Configuration

The Content Generator Method is specified in the Document Type (see Section 2). Content Generators can be configured as ‘dynamic’ or ‘static’. Static, the default, will result in the Content Generator executing when the Document Element is added to the document or when the author explicitly refreshes the Document Element using the context menu for the associated Document Element. Dynamic is set if the check box is selected in the Document Type. Dynamic Content Generators are executed when the Document Element is created or refreshed, but also when the Document is opened or saved. Depending on the complexity of the Content Generator, setting the Dynamic flag can affect performance.

4.3.1 Content Generator Parameters

Content Generator Methods can be passed parameters (or any type of input data) defined as a JSON-formatted string. Such an approach can be used to configure the execution of the Content Generator. The JSON is specified on the XML Schema Element for the specific Document Element.

The Generator Parameters input form is configured for displaying JSON content. Syntactical errors will be displayed if the text content does not conform to JSON formatting. It is important that the content be properly formatted JSON data, or it will not be converted to content that can be accessed in the C# Content Generator Method.

Note
JavaScript Object Notation (JSON) is used to serialize JavaScript Object data. It is used in the Technical Document Framework to enable complex configuration data for parameterizing Methods. A description of JSON, including how JSON can be represented via Collection classes in .Net, is outside the scope of this document.

4.3.2 Content Generator Example – Name / Value Pair

The following example shows how to configure and parse a single name/value pair for a Content Generator. In this example, a parameter ‘type’ can have one of two values: ‘product’ or ‘shipping’. The JSON formatted string is stored in the UI as follows:

The text is for this must be:

{
“type":"product”
}

Or

{
“type":"shipping”
}

Note the open and closing brackets (‘{‘ and ‘}’). The Content Generator Method can retrieve this information using the following example:

// The configured parameters should contain a single object with a

// type property with values of either ‘product’, or ‘shipping’ like:

//{"type":"product"}

if (!this.GenerationParameters.ContainsKey(“type”))

{

throw new InvalidOperationException(“‘type’ generation parameter was not configured.”);

}

string type = (string)this.GenerationParameters[“type”];

  1. Uses the public object GenerationParameters to check for the existence of the type variable. If it does not exist, it throws an InvalidOperationException with an appropriate message. If parameters are required, a similar mechanism should be used to warn the Technical Document Administrator that the Content Generator is not configured properly.
  2. The value for the type parameter is extracted as a string to be used in the subsequent logic of the Content Generator. Casting is required.

4.3.3 Content Generator Example – Lists

The following example shows how to configure and parse a list of name/value pairs for a Content Generator. In this example, a parameter ‘list’ can have multiple objects; each consisting of a name and value. The JSON formatted string for this is as follows:

{
“list":[{"name":"Prop 1", “value":"Prop 1 Value"},
{"name":"Prop 2", “value":"Prop 2 Value"},
{"name":"Prop 3", “value":"Prop 5 Value"}]
}

Note the open and closing brackets (‘{‘ and ‘}’) and the use of brackets for each list item. Variable names and values are specified as quoted strings. The Content Generator Method can retrieve this information using the following example:

// The configured parameters should contain an array labeled ‘list’

// that contains objects with name/value properties, like:

//{

// “list":[{"name":"Prop 1", “value":"Prop 1 Value"},

// {"name":"Prop 2", “value":"Prop 2 Value"},

// {"name":"Prop 3", “value":"Prop 5 Value"}]

//}

if (!this.GenerationParameters.ContainsKey(“list”))

{

throw new InvalidOperationException(“‘list’ generation parameter was not configured.”);

}

// Create List Items based on given Name/Value pairs

System.Collections.Generic.List<object> list = (System.Collections.Generic.List<object>) this.GenerationParameters[“list”];

foreach(System.Collections.Generic.Dictionary<string, object> listItem in list)

{

string name = (string)listItem[“name”];

string value = (string)listItem[“value”];

  1. Uses the public object GenerationParameters to check for the existence of the list variable. If it does not exist, it throws an InvalidOperationException with an appropriate message. If parameters are required, a similar mechanism should be used to warn the Technical Document Administrator that the Content Generator is not configured properly.
  2. The value for the list parameter is extracted as a Generic.List to be used in the subsequent logic of the Content Generator. Casting is required.
  3. Loop over the contents of the List. Note the use of a Generic.Dictionary in this example.
  4. The name and value are extracted using array notation.