CargoWriter Component

Properties   Methods   Events   Config Settings   Errors  

The CargoWriter component is optimized for Cargo-IMP documents, providing a simple way to create Cargo-IMP documents.

Syntax

nsoftware.IPWorksEDITranslator.Cargowriter

Remarks

The component allows you to create a document from scratch by writing one value at a time. Here's how a document would normally be created:

  1. Call LoadSchema to load the schema for the message type you want to write.
  2. Call Write once per value to add values to the message.
  3. Once the message is complete, call Finish.

Example CargoWriter Code:

Cargowriter writer = new Cargowriter(); writer.LoadSchema("C:\\cargoimp_schemas\\FSU.json"); writer.Write("1.1", "FSU"); writer.Write("1.3", "15"); writer.Write("2.1.1", "057"); writer.Write("2.1.3", "12345675"); writer.Write("2.2.1", "YYZ"); writer.Write("2.2.2", "LYS"); writer.Write("2.3.2", "T"); writer.Write("2.3.3", "12"); writer.Write("23.1", "OCI"); writer.Write("23.3", "FR"); writer.Write("23.5", "IMP"); writer.Write("23.7", "M"); writer.Write("23.9", "07FR9876AB88901235"); writer.Write("23.5", "HWB"); writer.Write("23.7", "I"); writer.Write("23.9", "ABCD12345678"); writer.Finish();

Schemas are written in JSON format: { "name": "FSU", "desc": "FSU MESSAGE", "children": { "1": { "desc": "Standard Message Identification", "children": { "1.1": { "desc": "Standard Message Identifier", "value": "FSU" }, "1.2": { "value": "/" }, "1.3": { "desc": "Message Type Version Number", "format": "n[...3]" }, "1.4": { "value": "\r\n" } } }, "2": { ... For example schemas and questions, please contact support@nsoftware.com.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

OutputDataContains the output data.
OutputFileSpecifies the name of the file to write to.
OverwriteWhether to overwrite the file.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

ConfigSets or retrieves a configuration setting.
FinishCompletes the current message.
LoadSchemaLoads a schema file describing a Message type.
ResetResets the component.
SetOutputStreamThe stream to which the component will write the data.
WriteWrites a value to the Cargo-IMP message.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ErrorInformation about errors during data delivery.
OutputFires whenever a segment is complete.
ResolveSchemaFires whenever a new Cargo-Imp message is encountered and no schema is found for it.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

CloseStreamAfterProcessingSpecifies whether or not the OutputStream should be closed after processing.
BuildInfoInformation about the product's build.
GUIAvailableTells the component whether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
MaskSensitiveWhether sensitive data is masked in log messages.
UseFIPSCompliantAPITells the component whether or not to use FIPS certified APIs.
UseInternalSecurityAPITells the component whether or not to use the system security libraries or an internal implementation.

OutputData Property (CargoWriter Component)

Contains the output data.

Syntax

public string OutputData { get; set; }
Public Property OutputData As String

Default Value

""

Remarks

This property will be populated with the contents of the Cargo-IMP data as output by the component when no OutputFile has been specified and SetOutputStream has not been called with a valid output stream.

Input and Output Properties

The component will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

  • SetInputStream
  • InputFile
  • InputData
When a valid source is found the search stops. The order in which the output properties are checked is as follows:

This property is not available at design time.

OutputFile Property (CargoWriter Component)

Specifies the name of the file to write to.

Syntax

public string OutputFile { get; set; }
Public Property OutputFile As String

Default Value

""

Remarks

This property specifies the file to which the Cargo-IMP message will be written. This may be set to an absolute or relative path. This should be set before calling Write.

Input and Output Properties

The component will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

  • SetInputStream
  • InputFile
  • InputData
When a valid source is found the search stops. The order in which the output properties are checked is as follows:

This property is not available at design time.

Overwrite Property (CargoWriter Component)

Whether to overwrite the file.

Syntax

public bool Overwrite { get; set; }
Public Property Overwrite As Boolean

Default Value

False

Remarks

This property specifies whether the existing file will be overwritten when a new message is created. If set to False (default) the component throws an exception when attempting to write to a file which already exists. If set to True the component will overwrite the existing file.

Config Method (CargoWriter Component)

Sets or retrieves a configuration setting.

Syntax

public string Config(string configurationString);

Async Version
public async Task<string> Config(string configurationString);
public async Task<string> Config(string configurationString, CancellationToken cancellationToken);
Public Function Config(ByVal ConfigurationString As String) As String

Async Version
Public Function Config(ByVal ConfigurationString As String) As Task(Of String)
Public Function Config(ByVal ConfigurationString As String, cancellationToken As CancellationToken) As Task(Of String)

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

Finish Method (CargoWriter Component)

Completes the current message.

Syntax

public void Finish();

Async Version
public async Task Finish();
public async Task Finish(CancellationToken cancellationToken);
Public Sub Finish()

Async Version
Public Sub Finish() As Task
Public Sub Finish(cancellationToken As CancellationToken) As Task

Remarks

When this method is called, the component will finalize the current Cargo-IMP message.

LoadSchema Method (CargoWriter Component)

Loads a schema file describing a Message type.

Syntax

public void LoadSchema(string fileName);

Async Version
public async Task LoadSchema(string fileName);
public async Task LoadSchema(string fileName, CancellationToken cancellationToken);
Public Sub LoadSchema(ByVal FileName As String)

Async Version
Public Sub LoadSchema(ByVal FileName As String) As Task
Public Sub LoadSchema(ByVal FileName As String, cancellationToken As CancellationToken) As Task

Remarks

This method parses the File and loads it into an internal schema list.

If the schema file does not exist or cannot be parsed as an Cargo-IMP schema, the component throws an exception.

Schemas are written in JSON format: { "name": "FSU", "desc": "FSU MESSAGE", "children": { "1": { "desc": "Standard Message Identification", "children": { "1.1": { "desc": "Standard Message Identifier", "value": "FSU" }, "1.2": { "value": "/" }, "1.3": { "desc": "Message Type Version Number", "format": "n[...3]" }, "1.4": { "value": "\r\n" } } }, "2": { ... For example schemas and questions, please contact support@nsoftware.com.

Reset Method (CargoWriter Component)

Resets the component.

Syntax

public void Reset();

Async Version
public async Task Reset();
public async Task Reset(CancellationToken cancellationToken);
Public Sub Reset()

Async Version
Public Sub Reset() As Task
Public Sub Reset(cancellationToken As CancellationToken) As Task

Remarks

When called, the component initializes itself to its default state.

SetOutputStream Method (CargoWriter Component)

The stream to which the component will write the data.

Syntax

public void SetOutputStream(System.IO.Stream outputStream);

Async Version
public async Task SetOutputStream(System.IO.Stream outputStream);
public async Task SetOutputStream(System.IO.Stream outputStream, CancellationToken cancellationToken);
Public Sub SetOutputStream(ByVal OutputStream As System.IO.Stream)

Async Version
Public Sub SetOutputStream(ByVal OutputStream As System.IO.Stream) As Task
Public Sub SetOutputStream(ByVal OutputStream As System.IO.Stream, cancellationToken As CancellationToken) As Task

Remarks

This method sets the stream to which the component will write the translated data.

Output Properties

The component will determine the source of the output based on which properties are set.

The order in which the output properties are checked is as follows:

When a valid source is found the search stops.

Write Method (CargoWriter Component)

Writes a value to the Cargo-IMP message.

Syntax

public void Write(string name, string value);

Async Version
public async Task Write(string name, string value);
public async Task Write(string name, string value, CancellationToken cancellationToken);
Public Sub Write(ByVal Name As String, ByVal Value As String)

Async Version
Public Sub Write(ByVal Name As String, ByVal Value As String) As Task
Public Sub Write(ByVal Name As String, ByVal Value As String, cancellationToken As CancellationToken) As Task

Remarks

This method adds a value to the current Cargo-IMP message.

Example CargoWriter Code:

Cargowriter writer = new Cargowriter(); writer.LoadSchema("C:\\cargoimp_schemas\\FSU.json"); writer.Write("1.1", "FSU"); writer.Write("1.3", "15"); writer.Write("2.1.1", "057"); writer.Write("2.1.3", "12345675"); writer.Write("2.2.1", "YYZ"); writer.Write("2.2.2", "LYS"); writer.Write("2.3.2", "T"); writer.Write("2.3.3", "12"); writer.Write("23.1", "OCI"); writer.Write("23.3", "FR"); writer.Write("23.5", "IMP"); writer.Write("23.7", "M"); writer.Write("23.9", "07FR9876AB88901235"); writer.Write("23.5", "HWB"); writer.Write("23.7", "I"); writer.Write("23.9", "ABCD12345678"); writer.Finish();

Error Event (CargoWriter Component)

Information about errors during data delivery.

Syntax

public event OnErrorHandler OnError;

public delegate void OnErrorHandler(object sender, CargowriterErrorEventArgs e);

public class CargowriterErrorEventArgs : EventArgs {
  public int ErrorCode { get; }
  public string Description { get; }
}
Public Event OnError As OnErrorHandler

Public Delegate Sub OnErrorHandler(sender As Object, e As CargowriterErrorEventArgs)

Public Class CargowriterErrorEventArgs Inherits EventArgs
  Public ReadOnly Property ErrorCode As Integer
  Public ReadOnly Property Description As String
End Class

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the component throws an exception.

ErrorCode contains an error code and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

Output Event (CargoWriter Component)

Fires whenever a segment is complete.

Syntax

public event OnOutputHandler OnOutput;

public delegate void OnOutputHandler(object sender, CargowriterOutputEventArgs e);

public class CargowriterOutputEventArgs : EventArgs {
  public string OutputData { get; }
public byte[] OutputDataB { get; } }
Public Event OnOutput As OnOutputHandler

Public Delegate Sub OnOutputHandler(sender As Object, e As CargowriterOutputEventArgs)

Public Class CargowriterOutputEventArgs Inherits EventArgs
  Public ReadOnly Property OutputData As String
Public ReadOnly Property OutputDataB As Byte() End Class

Remarks

The Output event will fire when the writer completes a new segment and writes data to the output stream or buffer. The OutputData parameter contains the data bytes.

ResolveSchema Event (CargoWriter Component)

Fires whenever a new Cargo-Imp message is encountered and no schema is found for it.

Syntax

public event OnResolveSchemaHandler OnResolveSchema;

public delegate void OnResolveSchemaHandler(object sender, CargowriterResolveSchemaEventArgs e);

public class CargowriterResolveSchemaEventArgs : EventArgs {
  public string MessageIdentifier { get; }
  public string Version { get; }
}
Public Event OnResolveSchema As OnResolveSchemaHandler

Public Delegate Sub OnResolveSchemaHandler(sender As Object, e As CargowriterResolveSchemaEventArgs)

Public Class CargowriterResolveSchemaEventArgs Inherits EventArgs
  Public ReadOnly Property MessageIdentifier As String
  Public ReadOnly Property Version As String
End Class

Remarks

The ResolveSchema event will fire when a the component encounters a new Cargo-IMP message, but it finds no schema corresponding to it already loaded.

MessageIdentifier contains the message type, such as "FWB" or "FSU".

Version contains the version of the schema used by the message.

When processing this event, the caller can use LoadSchema() to load a new schema into the component that can be used to parse the transaction.

Config Settings (CargoWriter Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

CargoWriter Config Settings

CloseStreamAfterProcessing:   Specifies whether or not the OutputStream should be closed after processing.

By default this is True. Setting this to False keeps the stream open for further use.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

GUIAvailable:   Tells the component whether or not a message loop is available for processing events.

In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The component will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the component does not attempt to process external events.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
MaskSensitive:   Whether sensitive data is masked in log messages.

In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to true to mask sensitive data. The default is true.

This setting only works on these components: AS3Receiver, AS3Sender, Atom, Client(3DS), FTP, FTPServer, IMAP, OFTPClient, SSHClient, SCP, Server(3DS), Sexec, SFTP, SFTPServer, SSHServer, TCPClient, TCPServer.

UseFIPSCompliantAPI:   Tells the component whether or not to use FIPS certified APIs.

When set to true, the component will utilize the underlying operating system's certified APIs. Java editions, regardless of OS, utilize Bouncy Castle FIPS, while all the other Windows editions make use of Microsoft security libraries.

FIPS mode can be enabled by setting the UseFIPSCompliantAPI configuration setting to true. This is a static setting which applies to all instances of all components of the toolkit within the process. It is recommended to enable or disable this setting once before the component has been used to establish a connection. Enabling FIPS while an instance of the component is active and connected may result in unexpected behavior.

For more details please see the FIPS 140-2 Compliance article.

Note: This setting is only applicable on Windows.

Note: Enabling FIPS-compliance requires a special license; please contact sales@nsoftware.com for details.

UseInternalSecurityAPI:   Tells the component whether or not to use the system security libraries or an internal implementation.

When set to false, the component will use the system security libraries by default to perform cryptographic functions where applicable. In this case, calls to unmanaged code will be made. In certain environments this is not desirable. To use a completely managed security implementation set this setting to true.

Setting this setting to true tells the component to use the internal implementation instead of using the system security libraries.

On Windows, this setting is set to false by default. On Linux/macOS, this setting is set to true by default.

If using the .NET Standard Library, this setting will be true on all platforms. The .NET Standard library does not support using the system security libraries.

Note: This setting is static. The value set is applicable to all components used in the application.

When this value is set the product's system DLL is no longer required as a reference, as all unmanaged code is stored in that file.

Trappable Errors (CargoWriter Component)

CargoWriter Errors

304   Could not write to file.
1000   Invalid schema file.
1001   No schema found.
1002   Schema format error.
1003   Line or message was too long.
1004   Failed to parse the message version.
1005   Element is not in the schema file or is not a simple element.
1006   Could not find the element.