Using the Working Data Store (WDS)

When creating a plugin, report, or script in O-Calc Pro it is helpful to be able to store information such as state, history, or keys identifying external data sources directly in the PPLX elements. O-Calc Pro provides a mechanism for this in the form of the Working Data Store (WDS).

The WDS is a free form dictionary that lives on every element within your model and allows you as a developer to store any data you wish for later retrieval or manipulation. The WDS is not visible to your users and is strictly used for adding data to a model to allow you to implement functionality.

A value can be embedded into an element (any class derived from PPLElement) by using the method public void “WriteWorkingDataStore(String pKey, String pValue)” and similarly can retrieve that value in the future using “public String ReadWorkingDataStore(String pKey)”.

Here is a very simple example that adds two values to an element and all of its children as a test…

  1. private void SetWorkingStore(PPLElement pElem)
  2. {
  3. pElem.WriteWorkingDataStore("Alpha", "This is the alpha data");
  4. pElem.WriteWorkingDataStore("Beta", "This is the beta data");
  5. foreach (PPLElement elem in pElem.Children)
  6. {
  7. SetWorkingStore(elem);
  8. }
  9. }

After doing that we can save and then reload the structure and then verify that, in fact, the data was stored and is still available.

  1. private bool TestWorkingStore(PPLElement pElem)
  2. {
  3. if (pElem.ReadWorkingDataStore("Alpha") != "This is the alpha data") return false;
  4. if (pElem.ReadWorkingDataStore("Beta") != "This is the beta data") return false;
  5. foreach (PPLElement elem in pElem.Children)
  6. {
  7. if (!TestWorkingStore(elem)) return false;
  8. }
  9. return true;
  10. }

Obviously this is a very simple example but in an actual plugin or report there are many times where storing additional data tightly bound to elements in the analysis model are useful to save state, or to bind that element to other data or processes within an organization.

Facebooktwitterlinkedinmail