.NET Based OPC UA Client/Server SDK
3.3.0.530
|
The temporary file transfer allows either to generate a file by the server and transfer it to the client or to write a file from the client to the server and apply the file content. In both cases, the file is only available in the address space for the specific client while it is transferred.
Typical use cases for reading temporary files are providing specific reports, the current configuration of the system or a module, or the current log. The temporary file transfer allows the client to parameterize the file creation, for example defining the format of the report.
In order to provide temporary file transfer an object of TemporaryFileTransferType
or a subtype needs to be provided. In order to provide temporary file transfer an object of TemporaryFileTransferType
or a subtype needs to be provided. The client first calls GenerateFileForRead
(which may contain configuration parameters) and gets back a NodeId
and FileHandle
of an already opened file object. Then the client transfers the file by reading it. When closing the file, the file object is removed. Since the file generation may take some time, the GenerateFileForRead
may also return a state machine object indicating when the file is actually ready to be accessed.
A typical use case for writing temporary files is that a new configuration shall be applied to the server. The configuration might effect the whole system or just a specific part. Like for the read, the temporary file transfers allows the client to parameterize the file to be written, for example defining the configuration format.
Like for the read, an object of TemporaryFileTransferType
or a subtype needs to be provided. The client first calls GenerateFileForWrite
and gets back a NodeId
and FileHandle
of an already opened file object to be written. The client then writes the content into the file and afterwards calls CloseAndCommit
. This method either directly returns a status if the operation was successful, or in case the deployment takes some time a state machine object that finally returns the status of the operation.
The demo server provides an example of the temporary file transfer for reading a parameterized file, without returning a state machine, since the generation is fast.
In order to use parameterization, a subtype of TemporaryFileTransferType
needed to be created. This is done in the model (Model\demoserver.xml
) and code is generated for the new ObjectType SpecialTemporaryFileTransferModel
(Model\ModelClasses.cs
). The SpecialTemporaryFileTransferModel
has changed the GenerateFileForRead
method to take a string as GenerateOptions
.
The creation of an instance can be found in UnifiedAutomation.Demo.DemoNodeManager.SpecialTemporaryFileTransfer.cs.
The DemoManager
calls the SetupSpecialTemporaryFileTransfer
method during startup which creates the object TempFile
under Root -> Objects -> Demo -> 014_Files. You can access this object with the UaExpert and right click and select Read to local file ... to try out the mechanism.
The implementation of the methods can be found in Demo\DemoNodeManager.SpecialTemporaryFileTransfer.cs
. The implementation of GenerateFileForRead
is actually creating a local text file taking the generateOptions
string as content and uses the FileModel
as base to manage it as object in the server.
This is just used for demonstration purposes, in a real application you would generate something more reasonable. When the transfer is completed and the client closes the file, the server removes the temporary file object and deletes the temporary file created on disk.
The temporary file transfer object defines a timeout (ClientProcessingTimeout
). When the client is not accessing the file for the duration of the timeout, the server is supposed to remove the temporary file. The timeout is defined when creating the object.
The implementation resets the timeout each time the file is accessed (typically by calling the Read method).
If the timeout is hit, it removes the temporary file object and deletes the file created on disk.