Export of an Object Model into JSON Format

The object model importer implements the software interface IObjectModelExport that can be used to export a Data Point Type and the related object model configuration into JSON format.

The interface IObjectModelExport is implemented by the class ObjectModelExport and contains the synchronous methods described below.

The export algorithm invokes the WinCC OA ASCII Manager to retrieve some Data Point Type data, so – by design – this feature can operate only on the server machine where the WinCC OA is installed.

 

Information

The object model data exported corresponds with the configuration of the higher customization level. This customization level is the one where the object model was originally created and where the object model can be re-imported. For example, if an object model was created at L1-Headquarter and then customized at L4-Project, the object model data exported will be the ones of the L1-Headquarter level.

 

Initialize

This method initializes the export functionality. This means that it initializes the ObjectModelExport class attributes and creates the classes used to interact with WinCC OA and to trace the logs.

bool Initialize( ContextOperation contextUserOperation,

            ContextOperation contextEngineeringOperation,

            string clientName,

            DpIdentifier systemDp)

The parameters and the returned value of the method are described in the following tables.

Initialize Parameters

Type

Name

Description

ContextOperation

contextUserOperation

User context operation (normal mode).

ContextOperation

contextEngineeringOperation

Engineering context operation (internal mode).

string

clientName

Component name.

DpIdentifier

systemDp

Current System identifier.

Initialize Returned Value

Type

Description

bool

False, in case an error occurs during the initialization.

Export

This method exports a Data Point Type and the related object model configuration.

MemoryStream Export( string objectModel,

                string[] textGroups,

                out int errorCode,

                out string errorLogs)

 

The parameters and the returned value of the method are described in the following tables.

Export Parameters

Type

Name

Description

string

objectModel

Name of the object model that must be exported.

string[ ]

textGroups

Array of text groups names that must be exported. If the array is empty or the parameter is null, no text groups will be exported.

out int

errorCode

Error code. The possible values are:

0 = no errors.

1 = errors during the export.

2 = warnings during the export.

out string

errorLogs

String containing the logs of the errors or warnings.

Export Returned Value

Type

Description

MemoryStream

Stream in memory containing the object model exported into JSON format.

Example

The following example shows how to use the interface IObjectModelExport.

The library Siemens.Gms.Importer.ObjectModelImporter.dll must be referenced.

 

public void ExportObjectModel(ContextOperation userContext, ContextOperation engContext,

DpIdentifier systemDpId)

{

    ObjectModelExport objectModelExporter = null;

    try

    {

        int errorCode;

        string errorLogs;

        // Create an instance of the exporter

        objectModelExporter = new ObjectModelExport();

        // Initialize the exporter

        if (!objectModelExporter.Initialize(userContext, engContext, "MyAppl_ObjectModelExport",

systemDpId))

        {

            MessageBox.Show("Error during initialization.");

            return;

        }

        // Export the object model data

        string objectModelName = "Test_NormalPoint";

        string[] textGroups = new string[] { "MyText" };

        var memoryStream = objectModelExporter.Export(objectModelName, textGroups,

out errorCode, out errorLogs);

        // Evaluate the error code

        // .......

        // Other code

        // .......

    }

    catch(Exception)

    {

        MessageBox.Show("Generic error during the export.", "Severe Error", MessageBoxButtons.OK,

MessageBoxIcon.Error);

    }

    finally

    {

        if(objectModelExporter != null)

        {

            objectModelExporter.Dispose();

            objectModelExporter = null;

        }

    }

}

 

Notes About the Object Model Exported into JSON Format

The object model exported data is formatted according to what described for the JSON format.

However, some differences with respect to the JSON import format must be considered:

  • All the object model configuration data is exported, regardless of whether this data is mandatory or optional in the import file.
  • Similarly, all the configuration data of each Data Point Element is exported, regardless of whether this data is mandatory or optional in the import file.
  • The possible mandatory Data Point Elements are listed together with the other DPEs of the object model and are not included into a separate section.
  • All the specified text groups are exported, even if they are not used by the exported object model.
  • It is not possible to export the text groups only. It is mandatory to specify the object model to export otherwise the export process fails.
  • If any Data Point Element of reference type is present, all the data of the referenced object model is exported.
  • As each Data Point Type must have references to _GmsRelatedItems and _GmsStatusPropagation, those referenced Data Point Types are not exported.
  • The commands exported contains the Guid automatically assigned by the system. This value must not be changed otherwise the command can no longer be identified in case of re-import.