gSharp Context Migration
In certain scenarios, contexts from one instance of gSharp need to be migrated to another. The most common case is moving contexts that have been developed and tested in a development environment to a production environment.
This document provides step-by-step instructions for migrating gSharp contexts. The current version of gSharp supports context migration exclusively via the command line.
Exporting gSharp Contexts
To export contexts, navigate to the folder where the gSharp admin app is installed and run GHost.GSharp.AdminConsole.exe. This will launch the gSharp admin console.

Enter the name or number of a gSharp server in the list and press <Enter>. If the required server is not listed, select the New Server option and follow the prompts to add a new server to connect to.
At the Command> prompt, enter ExportContexts and press <Enter>.

Selecting Assemblies for Export
A list of available assemblies is displayed, with options to specify which ones to export using a comma-separated list of assembly names, numbers, or ranges. For example:
1,3-5,MyAssembly
This selection exports contexts from:
- Assembly 1
- Assemblies 3, 4, and 5 (range 3-5)
- Assembly MyAssembly
If there is an overlap, contexts will only be exported once. For example, specifying 2,1-3 will export assemblies 1, 2, and 3, without duplicating 2.
Individual modules and contexts cannot be selected.
Specifying the Export Destination
The exported contexts can be written to a file or displayed directly in the console. Exporting to a file is recommended, especially when transferring contexts to another server or dealing with a large number of contexts.
Enter the full path and filename for the export file. For example:
C:\Temp\GSharpContexts\SVRGSDEV_GSharpTankDemo.json
- The
.jsonextension is not required but is recommended since the output is in JSON format. Using.jsonensures better compatibility with applications like Notepad++. - If the specified path does not exist, the app will attempt to create the necessary folders.
- If a relative path or no path is provided, the file will be saved relative to the location of the console app.
If <Enter> is pressed without specifying a filename, the exported contexts are displayed in the console. This output can be selected and copied, but the console has a limit on the number of lines it retains, which may result in truncation for large context exports.
Exported Context Data Format
The exported JSON data follows this structure:
{
"User": "TESTDOMAIN\\TestUser",
"Source": "WKS12345",
"SourceVersion": "1.2.42.10",
"ReferencedServers": {
"SVRPIDEV": "%ContextServer1%"
},
"Assemblies": [
{
"AssemblyName": "GSharpTankDemo",
"Version": "1.0.0.0",
"Modules": [
{
"ModuleName": "TankVolume",
"FullModuleName": "GSharpTankDemo.TankVolume",
"Points": [
{
"PointId": 51260,
"PointName": "Diameter_cnst",
"Descriptor": "|Diameter"
},
. . .
],
"Contexts": [
{
"ContextName": "Tank 000",
"Descriptor": "\\\\%ContextServer1%\\Database\\Element\\Path\\To\\Context",
"Schedules": [
{
"ScheduleType": 1,
"Interval": "15s",
"RunStatus": 1
}
]
},
. . .
]
},
. . .
]
}
]
}
The exported file can be modified before importing it into another server. If necessary, specific modules or contexts can be excluded by removing the corresponding JSON objects.
Editing the Exported File
When modifying the exported JSON file, keep the following in mind:
- Do not alter actual data. Editing is only intended for removing modules or contexts, not for modifying values.
- Ensure JSON validity. Any syntax errors will cause the import process to fail.
Following these steps ensures the successful migration of gSharp contexts between instances.
Importing gSharp Contexts
To import contexts, navigate to the folder where the gSharp admin app is installed and run GHost.GSharp.AdminConsole.exe. This will launch the gSharp admin console.

Enter the name or number of a gSharp server in the list and press <Enter>. If the required server is not listed, select the New Server option and follow the prompts to add a new server to connect to.
At the Command> prompt, enter ImportContexts and press <Enter>.

Enter the full path and filename containing the context data that is to be imported. For example:
C:\Temp\GSharpContexts\SVRGSDEV_GSharpTankDemo.json
- If a relative path or no path is provided, the file will be resolved relative to the location of the console app.
Alternatively, context data can be pasted into the console window by pressing <Enter> and pasting the data from the clipboard.
- To complete the entry of context data, press <Ctrl + Enter> on a blank line.
- To cancel the entry of context data, press <Escape> on a blank line. This will discard any data already entered and exit the ImportContexts function.
Specifying Data Servers
The context data being imported will likely have references to data servers (such as a PI-AF server). These references will need to be updated to the data server(s) used by the importing gSharp server. The application will request a data server name mapping for each data server it finds in the imported data.
Example
Consider a set of contexts to be migrated from a development gSharp server SVRGSDEV to a production gSharp server SVGSPRD. The development gSharp server typically references a development PI server SVRPIDEV, and therefore most of its contexts reference that PI server name:
\\SVRPIDEV\Database\Element\Path\To\Context
These contexts must be given a mapping from the dev PI server SVRPIDEV to the production PI server SVRPIPRD. This is done by entering the corresponding data server name of the importing gSharp server for each data server in the export data.
Import Progress
Once the data server mappings have been entered, the ImportContexts function will begin importing the data. It will not show progress because the import process occurs on the server. Instead, progress can be seen in the gSharp server log.
The logs do not show individual contexts that are imported unless the Administration log level is set to Debug. This must be done before the import function is executed. See Log Settings for more information about setting log levels.
