GitHub    Download    Forum
Overview
Tutorial
Database setup
Preparing the project
Establish the connection
Shut down the connection
DTDL types
Creating the schema
DADL classes
Entry point object
Write and read attributes
Write and read lists
Extending the schema
Modified entry point object
Write and read objects
Write and read object lists
C++ API
C# API
DTDL
DADL
Setup

Installation

You can develop solutions for DataFS with the compiler and IDE of your choice. In this tutorial, we will assume you are using Microsoft Visual Studio.
To prepare your computer, follow the instructions found on the DataFS SDK setup page.

DataFS setup with DataFSTools

Before we can start writing code, we need to create an instance of DataFS. To do that, we need to create a domain, a disk and then a storage. For detailed information, see DataFS setup.

Verify service is running

Verify that the 'DataFS Server' service is running (it is set to autostart by default). If it is not running, launch it from inside the Services app in Windows, or use PowerShell in admin mode and use the 'Start-Service -Name "DataFSServer"' command, or run cmd as an administrator and use the 'net start DataFSServer' command.

DataFS Tools

Go the installation folder (normally '%ProgramFiles%\Mobiland DataFS Server') and run DataFS_Tools.exe as an administrator. This will open a cmd-like panel where we will perform the next tasks.
Remarks: If the executing user is not an administrator on the machine that hosts the server program (not on the machine that runs the 'DataFS Tools'), you might get the error 0x80070040 (access denied) when you try to execute a command.

Connect

To allow client applications to connect, we must first establish a connection to the server program. We can type the "Open-Connection" command without additional parameters to connect to the local instance.
For more information about the parameters, refer to Connection.
Remarks: The server uses the address 127.0.0.1 and port 9012 for its configuration interface by default.
Open-Connection

Client connection

Next, we configure a binding. This will later allow our application to connect to this server to access the newly created DataFS instance. We use "Insert-Binding" to do this. The following example creates a binding without login or encryption activated on the port. (Type 1 means 'Client').
Insert-Binding -Type 1 -Address 127.0.0.1 -Port 9018
Remarks: After adding or removing bindings, the server needs to be restarted for the changes to take effect!

Create a domain

Every database instance is part of a domain. To create one, we use the following command.
Create-Domain -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}"
We should always use our own newly generated GUID but, for the purpose of this tutorial, you can just copy all the code from here. GUIDs can be generated in Visual Studio using "Tools > Create GUID > 4. Registry Format".
A newly created domain is not started automatically. We have to restart the service or start the domain manually. This can be done with the following command.
Start-Domain -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}"

Create a disk

Next, we need a disk. We create it with the following command. Note that the folder (here: C:\DataFS\) has to exist, and a file with such a name must not have already been created, otherwise we will get an error.
Create-Disk -DiskGuid "{4BE13A6D-315B-49EF-81CB-BFE5A5DE1E32}" -Path "C:\DataFS\data.datafs"

Create a storage

The main part of a database instance is the storage. That is where data is stored and is the part an application normally communicates with.
A storage can be created with the following command. We also pass the GUIDs from previous calls for the 'DiskGuid' and 'DomainGuid' parameters.
Create-Storage -StorageGuid "{6D7DD830-0482-4EA3-B694-25FDF9996413}" -DiskGuid "{4BE13A6D-315B-49EF-81CB-BFE5A5DE1E32}" -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}" -Name TestDatabase
A newly created storage is not started automatically. We have to restart the service or start the storage manually. This can be done with the following command.
Start-Storage -StorageGuid "{6D7DD830-0482-4EA3-B694-25FDF9996413}" -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}"
Now the server is ready to have a schema loaded to the storage. The schema can be extended by binding all the BDTD files that are generated when we compile our DTDL files. But we are going to look at that later on.
We should now have everything we need to finally write some code.
For more information about how to set up the server, check out DataFS Setup and DataFS Tools.

Disconnect

We can now close the connection and DataFS Tools.
Close-Connection
exit

Batch files

Note that we can also use batch files.
For now it might be unnecessary, but in later steps we might want to spare ourselves any tediousness. We can type all the code we just used inside DataFSTools in a single txt file and then pass it into DataFS inside the bat file like in the following example:
ServerSetup.txt
Open-Connection
Insert-Binding -Type 1 -Address 127.0.0.1 -Port 9018
Create-Domain -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}"
Start-Domain -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}"
Create-Disk -DiskGuid "{4BE13A6D-315B-49EF-81CB-BFE5A5DE1E32}" -Path "C:\DataFS\data.datafs"
Create-Storage -StorageGuid "{6D7DD830-0482-4EA3-B694-25FDF9996413}" -DiskGuid "{4BE13A6D-315B-49EF-81CB-BFE5A5DE1E32}" -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}" -Name "TestDatabase"
Start-Storage -StorageGuid "{6D7DD830-0482-4EA3-B694-25FDF9996413}" -DomainGuid "{E9F56A1D-4FD9-483E-A4FE-7522666AB7C6}"
Close-Connection
exit

ServerSetup.bat
net start DataFSServer
"C:\Program Files\Mobiland DataFS Server\DataFS_Tools.exe" < "ServerSetup.txt"
© 2022 Mobiland AG