The Portos eKasa Servis application stores its settings in a JSON text file. If your application should use the same
settings, load this file and pass its content to the constructor of the Client class. The service technician then
edits the settings in Portos eKasa Servis and your application picks them up.
Loading the configuration file in your application
- Build the file path
The
settings.jsonfile in the default working directoryNineDigit/Portos.eKasaunderEnvironment.SpecialFolder.CommonApplicationData. - Load the configuration
With the
JsonClientConfigurationFileDataSourcereader and itsLoad()method. - Pass it to the client
To the constructor of the
Clientclass, see Library instantiation.
// path to the default working directory that contains the configuration file
string ekasaWorkingDirectoryPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"NineDigit",
"Portos.eKasa");
// full path to the configuration file
string configurationFilePath = Path.Combine(ekasaWorkingDirectoryPath, "settings.json");
// create the configuration reader
IDataSource<ClientConfiguration> configurationDataSource = new JsonClientConfigurationFileDataSource(configurationFilePath);
// load the content of the configuration file into the configuration object,
// if the file does not exist, the default configuration is used
ClientConfiguration configuration = configurationDataSource.Load() ?? new ClientConfiguration();
// pass the configuration object to the client constructor,
// the client then uses the same settings as the Portos eKasa Servis application
Client client = new Client(configuration);
CommonApplicationData is the default working directory on Windows. On macOS and Linux it is
/etc/NineDigit/Portos.eKasa, because CommonApplicationData is not writable on macOS. EKasaPath.AppDataDirectoryPath
returns the path for the current platform:
string configurationFilePath = Path.Combine(EKasaPath.AppDataDirectoryPath, "settings.json");
| Configuration file | Load() returns |
The client uses |
|---|---|---|
| exists | the loaded configuration | the Portos eKasa Servis settings |
| does not exist | null |
the default configuration (new ClientConfiguration()) |
Namespaces and NuGet package
| Class | Namespace |
|---|---|
JsonClientConfigurationFileDataSource |
NineDigit.eKasa.Configuration.DataSources |
IDataSource<T> |
NineDigit.eKasa.Configuration.DataSources |
ClientConfiguration |
NineDigit.eKasa |
Since version 8 these classes are part of the NineDigit.eKasa NuGet package; in older versions they were in the
separate NineDigit.eKasa.Configuration package.
Editing another configuration file in Portos eKasa Servis
To edit a different configuration file in the Portos eKasa Servis application, change the path to it:
- Open the menu Click the menu button in the upper right corner of the application.
- Choose Nastavenia aplikácie In the menu, select Nastavenia aplikácie (Application settings).
- Enter the path Enter the path to the configuration file, or locate it with the browse button.