void IDisposable.Dispose()
 {
     // Multiple calls to dispose must be tolerated
     if (control != null)
     {
         control.EndUpdate();
         control = null;
         State   = null;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Applies the specified JSON data to the specified tracker state
        /// </summary>
        public void Process(JObject json, TrackerState state)
        {
            Dictionary <string, JToken> keyNodes = new Dictionary <string, JToken>();
            var nodeGetter = (NodeResolver) delegate(string path) {
                var association = new NodeAssociation(null, path);
                return(FindNode(json, keyNodes, association.KeyNode, association.Path));
            };
            var jsonGetter = (JsonValueGetterFunction) delegate(string path) {
                return((int)(nodeGetter(path) ?? 0));
            };

            // Identify our key nodes
            foreach (var node in this._KeyNodes)
            {
                //var jsonNode = FindNode(json, node.Path);
                var jsonNode = FindNode(json, null, null, node.Path);
                keyNodes.Add(node.Name, jsonNode);
            }

            // Find and apply our states
            foreach (var association in this._Associations)
            {
                if (association.Expression == null)
                {
                    var element = FindNode(json, keyNodes, association.KeyNode, association.Path);

                    var value = (int)(element ?? 0);
                    if (association.Filter != null)
                    {
                        value = association.Filter(association.Name, value);
                    }
                    state.SetIndicatorLevel(association.Name, value);
                }
                else
                {
                    var value = TrackerFunction.EvaluateExpression((JToken)association.Expression, nodeGetter);
                    if (value != null)
                    {
                        state.SetIndicatorLevel(association.Name, value.Value);
                    }
                }
            }



            foreach (var rule in this._CustomRules)
            {
                var result = rule.Rule(jsonGetter);
                state.SetIndicatorLevel(rule.IndicatorName, result);
            }
        }
 public TrackerUpdate(TrackerControl c, TrackerState s)
 {
     this.control = c;
     this.State   = s;
 }
Beispiel #4
0
 /// <summary>
 /// Applies the specified JSON data to the specified tracker state
 /// </summary>
 public void Process(string json, TrackerState state)
 {
     Process(JObject.Parse(json), state);
 }