JDP Science Tools

cancel
Showing results for 
Search instead for 
Did you mean: 

Config File Sync

I'm exploring the use of JSONText with the Config File class as a universal reusable tool for handling configuration files.

My configuration actor will receive JSON objects from other actors and compile them into one JSON object for saving to file.

But also I want to recognise when the user has manually edited the JSON file itself and load those changes.

I remember that the JSONText Config class uses Differencing to recognise file changes and merge (where no conflict), which is great.

However, I'm not sure I fully appreciate how to wrap the methods "Read Config from File.vi" and "Write Config Changes to File.vi" such that I can efficiently achieve what I want.

 

Let me explain -

"Read Config file File.vi" reads the file into memory and stores certain info in the Config File class. Perfect during app initialisation and loading the configuration in.

"Write Config Changes to File.vi" write any changes you've made to your JSON to the file. Great for when your user has edited some settings within your application and you wish to commit them to disk. Beautifully it also preserves any unexpected file changes, and provides the new merged JSON content back. Use JSONText Difference.vi and you can see the new unexpected JSON content and act on that (propagate it throughout your app).

BUT, there's a scenario that I can't get working - "Write Config Changes to File.vi" does nothing when you haven't edited your JSON content because it recognises that there are no changes to the JSON in memory, and therefore it doesn't load the file. If there are file content changes they don't get loaded.

You could say "just call the Read vi?" but then I might lose local changes, because this doesn't merge like Write does.

How can I check if my local JSON is unchanged? Well, I could just store a simple flag and set it to True whenever I adjust the content, but that seems dirty when there's built in functionality in JSONtext. 

Am I misunderstanding how to call Read and Write Config File to ensure I can sync my JSON in memory with any local file changes? I feel like I'm missing the simple Resync Config File method which will reload the file and ensure we capture any changes there, whilst also commiting local changes to disk.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 1 of 2
(21 Views)

Hi Richard,

I am unfortunately on holiday this next week and I can't check the code right now, but I have not previously made an "update-on-the-fly" configuration system like you are trying to make.  Thus I may be lacking a method that you need, that detects changes to the config file that we can react to.  If you prompt me the week after next, I will have a look.

Question: are you able to make a child class of the config class to add this functionality yourself?  I am interested in allowing people to easily make their own extensions and may want to add a protected method or two that allows this.

0 Kudos
Message 2 of 2
(4 Views)