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…
- private void SetWorkingStore(PPLElement pElem)
- {
- pElem.WriteWorkingDataStore("Alpha", "This is the alpha data");
- pElem.WriteWorkingDataStore("Beta", "This is the beta data");
- foreach (PPLElement elem in pElem.Children)
- {
- SetWorkingStore(elem);
- }
- }
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.
- private bool TestWorkingStore(PPLElement pElem)
- {
- if (pElem.ReadWorkingDataStore("Alpha") != "This is the alpha data") return false;
- if (pElem.ReadWorkingDataStore("Beta") != "This is the beta data") return false;
- foreach (PPLElement elem in pElem.Children)
- {
- if (!TestWorkingStore(elem)) return false;
- }
- return true;
- }
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.
Recent Comments