paiden/Nett

Coma: Clearing/Setting of TomlTables

Closed this issue · 1 comments

I have a datagridview which is the ui control to hold an inline table. I want to be able to add and remove rows. I am finding the following behaviour when removing rows:

With and 'app_settings.toml' and 'user_settings.toml' files where only the 'user' file contains the inline table, i.e.

[User.Variables.VariablesProperties]
fe = { Check = true, Name = "fe", Caption = "Fe", Unit = "%", Format = "#0.00" }
sio2 = { Check = true, Name = "sio2", Caption = "SiO2", Unit = "%", Format = "#0.00" }
al2o3 = { Check = true, Name = "al2o3", Caption = "Al2O3", Unit = "%", Format = "#0.00" }

and merged as follows...

        string appSettings = "C:\\app_settings.toml";
        string userSettings = "C:\\user_settings.toml";
        IConfigSource appSource = null;
        IConfigSource userSource = null;
        Config<Configuration> config = null;
        // merge into config object
        config = Config.CreateAs()
            .MappedToType(() => new Configuration())
            .StoredAs(store =>
                store.File(appSettings).AccessedBySource("app", out appSource).MergeWith(
                store.File(userSettings).AccessedBySource("user", out userSource)))
            .Initialize();

        _app = appSource;
        _user = userSource;
        return config;

It works ok.

However when I have and two additional files, i.e. 'C:\default\app_settings.toml' and 'C:\default\user_settings.toml' and merged as follows:

        config = Config.CreateAs()
            .MappedToType(() => new Configuration())
            .StoredAs(store =>
                store.File(defaultAppSettings).AccessedBySource("defaultApp", out defaultAppSource).MergeWith(
                store.File(defaultUserSettings).AccessedBySource("defaultUser", out defaultUserSource).MergeWith(
                    store.File(appSettings).AccessedBySource("app", out appSource).MergeWith(
                    store.File(userSettings).AccessedBySource("user", out userSource)))))
            .Initialize();

        _defaultApp = defaultAppSource;
        _defaultUser = defaultUserSource;
        _app = appSource;
        _user = userSource;
        return config;

I save the config to 'C:\user_settings.toml' after deletion using:

        ThisAddIn._config.Set(s => s.User.Variables.VariablesProperties, variablesProperties, userSource);

After I delete a row I check it is deleted ok by viewing the file, i.e.

[User.Variables.VariablesProperties]
fe = { Check = true, Name = "fe", Caption = "Fe", Unit = "%", Format = "#0.00" }
sio2 = { Check = true, Name = "sio2", Caption = "SiO2", Unit = "%", Format = "#0.00" }

I then load the config into the datagridview using:

        var variablesProperties = ThisAddIn._config.Get(s => s.User.Variables.VariablesProperties);

But when I load the datagridview again all three rows are loaded. So the deleted row is still held in the config somewhere.

Am I doing something that is not supported or missing a step?

Regards Don

Originally posted by @donvreug in #85 (comment)

Fixed in v0.15.0

If more features / improvements are needed, please open a new issue.