ThirdMomentQuantX

Writing a data store

Contents
  1. 1. Build the plug-in
  2. 2. Implement the factory and the stores
  3. 3. Write the manifest
  4. 4. Install it
  5. 5. Check it
  6. How a plug-in is loaded
  7. A store without administration, or read-only

Status: contract version 1.

A client's IT team can keep QuantX' data in their own database by writing a data store plug-in: a .NET class library that implements the data store contract and is installed in a folder the settings file names. The desktop application, the Excel add-in and the provider executables then open it like the bundled SQLite store, without being rebuilt.

1. Build the plug-in

Create a .NET 10 class library that references QuantX.dll, the copy installed with the application, without copying it:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="QuantX">
      <HintPath>C:\Program Files\QuantX\QuantX.dll</HintPath>
      <Private>false</Private>
    </Reference>
  </ItemGroup>
</Project>

EnableDynamicLoading copies the plug-in's own dependencies (a database driver, for example) next to it and lists them in its .deps.json.

2. Implement the factory and the stores

Write one public class with a public constructor taking no arguments that implements QuantX.Storage.IDataStoreFactory:

  • Name: the name users choose in the settings, such as Acme warehouse. It must equal the name in the manifest.
  • Description: one or two sentences for the settings page.
  • Options: what the store needs, as FieldDefinitions (server, database, user, password). An option of kind FieldKind.Secret is never written in a settings file: the file holds the name of a secret each user saves on their machine, and the factory receives the secret itself.
  • OpenAsync(options): connects and returns a DataStoreConnection holding the four stores (IDocumentStore, IMarketDataStore, IDataSeriesStore and the optional IStoreAdministration), whether the store is read-only, a description, a location for the settings page, an optional size, and the object to dispose when the connection is closed.

The options arrive checked against their definitions. Throw ArgumentException or InvalidOperationException with a message the user can act on when the store cannot be opened; never put a secret in a message.

3. Write the manifest

Put a quantx-plugin.json beside the assembly (schema: plugin-manifest.schema.json):

{
  "contractVersion": 1,
  "kind": "store",
  "name": "Acme warehouse",
  "description": "The Acme data warehouse, on the treasury's SQL Server.",
  "assembly": "Acme.QuantXStore.dll",
  "type": "Acme.QuantXStore.AcmeStoreFactory"
}

assembly is a file of the manifest's folder; type is the factory's full name. A manifest of another contract version is refused.

4. Install it

Copy the build output, without any QuantX*.dll, into a folder of its own, for example C:\Program Files\Acme\QuantXStores\Acme.QuantXStore\, and name the parent folder in the settings file:

{
  "contractVersion": 1,
  "store": { "type": "Acme warehouse", "options": { "Server": "db01", "Password": "acme-password" } },
  "plugins": { "folders": ["C:\\Program Files\\Acme\\QuantXStores"] }
}

A plug-in folder holds one manifest directly, or one plug-in per immediate subfolder. QuantX looks for plug-ins nowhere else.

5. Check it

Run the conformance kit, shipped in the sdk folder of the desktop application, against a new, empty store that can be thrown away:

sdk\QuantX.DataStores.Conformance.exe store --settings C:\Temp\acme-test.json

It prints one line per rule of the contract (PASS, FAIL with the reason, or SKIP for the administration checks of a store without one) and exits with 0 when every check passes, 1 when one fails and 2 when it cannot run. It opens read-only stores and stores without an administration too. The sdk folder holds its own copy of QuantX.dll and the bundled stores: it is a separate program, so leave them there. The bundled SQLite store, the scratch store in memory and a sample plug-in pass it in every build.

How a plug-in is loaded

Each plug-in is loaded into its own AssemblyLoadContext:

  • QuantX and every QuantX.* assembly other than the plug-in's own resolve to the copies the host already loaded (inside Excel, the add-in's own context), so that the plug-in implements the host's own IDataStoreFactory. A plug-in folder carrying its own copy of one is refused.
  • Any other assembly resolves through the plug-in's .deps.json to its folder, native libraries included; the .NET framework comes from the host.

A plug-in that cannot be loaded is left out and reported, with its manifest file and the reason; the other stores stay available. A plug-in runs with the rights of the user running QuantX.

A store without administration, or read-only

A store whose connection has no IStoreAdministration opens like any other: pricing, markets and series read from it, and the desktop's admin pages say they are not available for it. A read-only store (IsReadOnly) is never written by an import or a snapshot; the Import page says so. The document kinds say what the documents hold, and the provider protocol how providers fill a store.

Reconnecting Connection paused Could not reconnect Could not resume Session expired

The connection to the server was lost. Trying to restore it. Next attempt in 0s. The connection was paused. It will resume on its own. The server did not answer. Your work is still here. The paused session could not be resumed. The server could not restore this session. Reloading will start a new one.

An unhandled error has occurred. Reload 🗙