.NET Based OPC UA Client/Server SDK  2.6.1.422
UnifiedAutomation.UaServer.FileModel Class Reference

An object that represents a file that can be accessed via the server. More...

Inherits UnifiedAutomation.UaServer.BaseObjectModel, UnifiedAutomation.UaServer.IMethodDispatcher, UnifiedAutomation.UaServer.IFileMethods, and IDisposable.

Inherited by UnifiedAutomation.UaServer.AddressSpaceFileModel, and UnifiedAutomation.UaServer.TrustListModel.

Classes

class  OpenFileHandle
 Caches information about an open file handle. More...
 

Public Member Functions

void Dispose ()
 Frees any unmanaged resources. More...
 
virtual StatusCode Open (RequestContext context, FileModel model, byte mode, out uint fileHandle)
 Used to open a file represented by an Object of FileType. More...
 
virtual StatusCode Close (RequestContext context, FileModel model, uint fileHandle)
 Closes a file represented by a FileType. More...
 
virtual StatusCode Read (RequestContext context, FileModel model, uint fileHandle, int length, out byte[] data)
 Reads a part of the file starting from the current file position. More...
 
virtual StatusCode Write (RequestContext context, FileModel model, uint fileHandle, byte[] data)
 Writes a part of the file starting from the current file position. More...
 
virtual StatusCode SetPosition (RequestContext context, FileModel model, uint fileHandle, ulong position)
 Used to set the current position of the FileHandle. More...
 
virtual StatusCode GetPosition (RequestContext context, FileModel model, uint fileHandle, out ulong position)
 Provides the current position of the FileHandle. More...
 
 FileModel ()
 Initializes a new instance of the FileModel class. More...
 
 FileModel (FileModel template)
 Initializes a new instance of the FileModel class. More...
 
virtual CallMethodEventHandler GetMethodDispatcher (RequestContext context, NodeId objectId, NodeId methodId)
 Gets the method dispatcher. More...
 
virtual StatusCode DispatchMethod (RequestContext context, MethodHandle methodHandle, IList< Variant > inputArguments, List< StatusCode > inputArgumentResults, List< Variant > outputArguments)
 Dispatches the method. More...
 
- Public Member Functions inherited from UnifiedAutomation.UaServer.BaseObjectModel
 BaseObjectModel ()
 Initializes a new instance of the BaseObjectModel class. More...
 
 BaseObjectModel (BaseObjectModel template)
 Initializes a new instance of the BaseObjectModel class. More...
 
- Public Member Functions inherited from UnifiedAutomation.UaServer.ModelControllerBase
virtual ModelHandle GetModelHandle (StringTable namespaceUris, object instance)
 Gets the metadata handle. More...
 
virtual DataValue GetValue (IMapperContext context, ModelMapping mapping)
 Gets the value associated with the mapping. More...
 
virtual bool SetValue (IMapperContext context, ModelMapping mapping, DataValue value)
 Sets the value associated with the mapping. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 An overrideable version of the Dispose. More...
 
virtual bool HasAccess (RequestContext context, UserAccessMask accessMasks)
 Determines whether the current context has specified access to the file. More...
 
void CleanupExpiredHandles ()
 Cleans up any expired handles. More...
 
StatusCode OpenStream (OpenFileHandle handle)
 Opens a stream for the file referenced by FileOnDisk. More...
 
OpenFileHandle FindHandle (RequestContext context, uint fileHandle)
 Finds the handle. More...
 
void SaveHandle (OpenFileHandle handle)
 Assigns a unique id to the handle and saves the handle. More...
 
void CloseHandle (OpenFileHandle handle)
 Closes the stream associated with the handle and sets the size of the File object. More...
 

Protected Attributes

object Lock = new object()
 An object used to synchronize access to the file object. More...
 

Properties

FileInfo FileOnDisk [get, set]
 Gets or sets the disk file which can be accessed via the file object. More...
 
int MaxFileSize [get, set]
 Gets or sets the maximum size of the file in bytes. More...
 
INodeAccessInfo NodeAccessInfo [get, set]
 Gets or sets the NodeAccessInfo to specify user access in Open method. More...
 
uint NextFileHandle [get, set]
 Gets or sets the next file handle to assign. More...
 
string MimeType [get, set]
 Contains the media type of the file based on RFC 2046. More...
 
ushort OpenCount [get, set]
 Indicates the number of currently valid file handles on the file. More...
 
ulong Size [get, set]
 Defines the size of the file in Bytes. More...
 
bool UserWritable [get, set]
 Indicates whether the file is writable, taking user access rights into account. More...
 
bool Writable [get, set]
 Indicates whether the file is writable. More...
 
IFileMethods FileMethods [get, set]
 Gets or sets the File methods. More...
 
- Properties inherited from UnifiedAutomation.UaServer.ModelControllerBase
ModelHandle ModelHandle [get, set]
 Gets or sets the metadata handle. More...
 
object UserData [get, set]
 Gets or sets the user data. More...
 

Events

EventHandler< OpenFileEventArgsOpenRequested
 Occurs when the file is opened. More...
 
EventHandler< CloseFileEventArgsCloseRequested
 Occurs when the file is closed. More...
 

Detailed Description

An object that represents a file that can be accessed via the server.

This ObjectType defines a type for files.

This class implements support for the FileType object on the server side.

Any number of open read handles is allowed but only one handle may be open for write at a time. Subclasses may be used to replace the FileStream with other abstract stream implementations. There are two events (OpenRequested and CloseRequested) which can be used to determine permissions.

See FileModel Example for example code.

Note that all methods on a file require a FileHandle, which is returned in the UnifiedAutomation.UaServer.IFileMethods.Open method.

Constructor & Destructor Documentation

UnifiedAutomation.UaServer.FileModel.FileModel ( )
inline

Initializes a new instance of the FileModel class.

UnifiedAutomation.UaServer.FileModel.FileModel ( FileModel  template)
inline

Initializes a new instance of the FileModel class.

Parameters
templateThe template.

Member Function Documentation

void UnifiedAutomation.UaServer.FileModel.CleanupExpiredHandles ( )
inlineprotected

Cleans up any expired handles.

virtual StatusCode UnifiedAutomation.UaServer.FileModel.Close ( RequestContext  context,
FileModel  model,
uint  fileHandle 
)
inlinevirtual

Closes a file represented by a FileType.

When a client closes a file, the handle becomes invalid.

Parameters
context
model
fileHandleA handle returned by the Open method, indicating the access request and thus indirectly the position inside the file.
Returns
The result of the operation.

Implements UnifiedAutomation.UaServer.IFileMethods.

void UnifiedAutomation.UaServer.FileModel.CloseHandle ( OpenFileHandle  handle)
inlineprotected

Closes the stream associated with the handle and sets the size of the File object.

Parameters
handleThe handle.
virtual StatusCode UnifiedAutomation.UaServer.FileModel.DispatchMethod ( RequestContext  context,
MethodHandle  methodHandle,
IList< Variant inputArguments,
List< StatusCode inputArgumentResults,
List< Variant outputArguments 
)
inlinevirtual

Dispatches the method.

Parameters
contextThe context.
methodHandleThe method handle.
inputArgumentsThe input arguments.
inputArgumentResultsThe input argument results.
outputArgumentsThe output arguments.
Returns

Reimplemented in UnifiedAutomation.UaServer.TrustListModel, and UnifiedAutomation.UaServer.AddressSpaceFileModel.

void UnifiedAutomation.UaServer.FileModel.Dispose ( )
inline

Frees any unmanaged resources.

virtual void UnifiedAutomation.UaServer.FileModel.Dispose ( bool  disposing)
inlineprotectedvirtual

An overrideable version of the Dispose.

OpenFileHandle UnifiedAutomation.UaServer.FileModel.FindHandle ( RequestContext  context,
uint  fileHandle 
)
inlineprotected

Finds the handle.

Parameters
contextThe context.
fileHandleThe file handle.
Returns
An open handle.
virtual CallMethodEventHandler UnifiedAutomation.UaServer.FileModel.GetMethodDispatcher ( RequestContext  context,
NodeId  objectId,
NodeId  methodId 
)
inlinevirtual

Gets the method dispatcher.

Parameters
contextThe context.
objectIdThe object id.
methodIdThe method id.
Returns

Implements UnifiedAutomation.UaServer.IMethodDispatcher.

Reimplemented in UnifiedAutomation.UaServer.TrustListModel, and UnifiedAutomation.UaServer.AddressSpaceFileModel.

virtual StatusCode UnifiedAutomation.UaServer.FileModel.GetPosition ( RequestContext  context,
FileModel  model,
uint  fileHandle,
out ulong  position 
)
inlinevirtual

Provides the current position of the FileHandle.

Parameters
contextThe context.
modelThe file model.
fileHandleA handle returned by the Open method, indicating the access request and thus indirectly the position inside the file.
positionThe position of the FileHandle in the file. If UnifiedAutomation.UaServer.IFileMethods.Read or UnifiedAutomation.UaServer.IFileMethods.Write is called, it starts at that position.
Returns
The result of the operation.

Implements UnifiedAutomation.UaServer.IFileMethods.

virtual bool UnifiedAutomation.UaServer.FileModel.HasAccess ( RequestContext  context,
UserAccessMask  accessMasks 
)
inlineprotectedvirtual

Determines whether the current context has specified access to the file.

Parameters
contextThe request context.
accessMasksThe desired access masks. UserAccessMask.Read and UserAccessMask.Write will be evaluated.
Returns
true, if the specified context has access; otherwise, false.
virtual StatusCode UnifiedAutomation.UaServer.FileModel.Open ( RequestContext  context,
FileModel  model,
byte  mode,
out uint  fileHandle 
)
inlinevirtual

Used to open a file represented by an Object of FileType.

When a client opens a file, it gets a FileHandle that is valid while the session is open. Clients shall use the UnifiedAutomation.UaServer.IFileMethods.Close Method to release the handle when they do not need access to the file anymore. Clients can open the same file several times for reading. A request to open for writing shall return Bad_NotWritable when the file is already opened.

Parameters
contextThe context.
modelThe model.
modeIndicates whether the file should be opened only for read operations or for read and write operations and where the initial position is set. The mode is an 8-bit unsigned integer used as bit mask with the structure defined in the following table:
Field Bit Description
Read 0 The file is opened for reading. If this bit is not set the UnifiedAutomation.UaServer.IFileMethods.Read Method cannot be executed.
Write 1 The file is opened for writing. If this bit is not set the UnifiedAutomation.UaServer.IFileMethods.Write Method cannot be executed.
EraseExisting 2 This bit can only be set if the file is opened for writing (Write bit is set). The existing content of the file is erased and an empty file is provided.
Append 3 When the Append bit is set the file is opened at end of the file, otherwise at begin of the file. The UnifiedAutomation.UaServer.IFileMethods.SetPosition Method can be used to change the position.
See also FileAccessModes enumeration.
fileHandleA handle for the file used in other method calls indicating not the file (this is done by the Object of the Method call) but the access request and thus the position in the file. The FileHandle is generated by the server and is unique for the Session. Clients cannot transfer the FileHandle to another Session but need to get a new FileHandle by calling the UnifiedAutomation.UaServer.IFileMethods.Open Method.
Returns
The result of the operation.

Implements UnifiedAutomation.UaServer.IFileMethods.

Reimplemented in UnifiedAutomation.UaServer.TrustListModel.

StatusCode UnifiedAutomation.UaServer.FileModel.OpenStream ( OpenFileHandle  handle)
inlineprotected

Opens a stream for the file referenced by FileOnDisk.

Parameters
handleThe handle.
Returns
If FileOnDisk is null, a memory stream is created.
virtual StatusCode UnifiedAutomation.UaServer.FileModel.Read ( RequestContext  context,
FileModel  model,
uint  fileHandle,
int  length,
out byte[]  data 
)
inlinevirtual

Reads a part of the file starting from the current file position.

The file position is advanced by the number of bytes read.

Parameters
contextThe context.
modelThe model.
fileHandleA handle returned by the Open method, indicating the access request and thus indirectly the position the file.
lengthDefines the length in byte that should be returned in data, starting from the current position of the file handle. If the end of file is reached, only all data till the end of the file are returned. If the specified length is longer than the maximum allowed message size of the communication, only those data fitting into the message size are returned. Only positive values are allowed.
dataContains the returned data of the file.
Returns
The result of the operation.

Implements UnifiedAutomation.UaServer.IFileMethods.

void UnifiedAutomation.UaServer.FileModel.SaveHandle ( OpenFileHandle  handle)
inlineprotected

Assigns a unique id to the handle and saves the handle.

Parameters
handleThe handle.
virtual StatusCode UnifiedAutomation.UaServer.FileModel.SetPosition ( RequestContext  context,
FileModel  model,
uint  fileHandle,
ulong  position 
)
inlinevirtual

Used to set the current position of the FileHandle.

Parameters
contextThe context.
modelThe file model.
fileHandleA handle returned by the Open method, indicating the access request and thus indirectly the position inside the file.
positionThe position to be set for the FileHandle in the file. If UnifiedAutomation.UaServer.IFileMethods.Read or UnifiedAutomation.UaServer.IFileMethods.Write is called, it starts at that position. If the position is higher than the file size, the position is set to the end of the file.
Returns
The result of the operation.

Implements UnifiedAutomation.UaServer.IFileMethods.

virtual StatusCode UnifiedAutomation.UaServer.FileModel.Write ( RequestContext  context,
FileModel  model,
uint  fileHandle,
byte[]  data 
)
inlinevirtual

Writes a part of the file starting from the current file position.

The file position is advanced by the number of bytes written

Parameters
contextThe context.
modelThe file model.
fileHandleA handle returned by the Open method, indicating the access request and thus indirectly the position inside the file.
dataContains the data to be written at the position of the file. It is server-dependent whether the written data are persistently stored if the session is ended without calling the UnifiedAutomation.UaServer.IFileMethods.Close Method with the FileHandle.
Returns
The result of the operation.

Implements UnifiedAutomation.UaServer.IFileMethods.

Member Data Documentation

object UnifiedAutomation.UaServer.FileModel.Lock = new object()
protected

An object used to synchronize access to the file object.

Property Documentation

IFileMethods UnifiedAutomation.UaServer.FileModel.FileMethods
getset

Gets or sets the File methods.

The File methods.

FileInfo UnifiedAutomation.UaServer.FileModel.FileOnDisk
getset

Gets or sets the disk file which can be accessed via the file object.

This should be null if a subclass implements a more complex I/O model.

int UnifiedAutomation.UaServer.FileModel.MaxFileSize
getset

Gets or sets the maximum size of the file in bytes.

string UnifiedAutomation.UaServer.FileModel.MimeType
getset

Contains the media type of the file based on RFC 2046.

uint UnifiedAutomation.UaServer.FileModel.NextFileHandle
getsetprotected

Gets or sets the next file handle to assign.

INodeAccessInfo UnifiedAutomation.UaServer.FileModel.NodeAccessInfo
getset

Gets or sets the NodeAccessInfo to specify user access in Open method.

ushort UnifiedAutomation.UaServer.FileModel.OpenCount
getset

Indicates the number of currently valid file handles on the file.

ulong UnifiedAutomation.UaServer.FileModel.Size
getset

Defines the size of the file in Bytes.

When a file is opened for writing the size might not be accurate.

bool UnifiedAutomation.UaServer.FileModel.UserWritable
getset

Indicates whether the file is writable, taking user access rights into account.

The Property does not take into account whether the file is currently opened for writing by another client and thus currently locked and not writable by others.

bool UnifiedAutomation.UaServer.FileModel.Writable
getset

Indicates whether the file is writable.

It does not take any user access rights into account, i.e. although the file is writable this may be restricted to a certain user/user group. The Property does not take into account whether the file is currently opened for writing by another client and thus currently locked and not writable by others.

Event Documentation

EventHandler<CloseFileEventArgs> UnifiedAutomation.UaServer.FileModel.CloseRequested

Occurs when the file is closed.

EventHandler<OpenFileEventArgs> UnifiedAutomation.UaServer.FileModel.OpenRequested

Occurs when the file is opened.


The documentation for this class was generated from the following files: