예제 #1
0
 public Aggregator()
 {
     Node       = new AggregateNode();
     Routers    = new List <IRouter>();
     Collectors = new List <ICollector>();
     Finalizers = new List <IFinalizer>();
 }
예제 #2
0
        private void ProcessRetriever(object obj, IScope scope, IRouter retriever, AggregateNode current)
        {
            if (!retriever.Filter(obj, current, scope))
            {
                return;
            }
            var subnode = string.IsNullOrWhiteSpace(retriever.Key) ? current : current.GetNode(retriever.Key);

            subnode.IsBucket = true;
            subnode.RouteKey = new RouteKey(retriever.Key);
            AggregateNode keynode = subnode;

            SetValues(obj, scope, subnode);
            var key = retriever.GetKey(obj, scope);

            if (null != key)
            {
                keynode          = subnode.GetNode(key.Key);
                keynode.RouteKey = key;
                SetValues(obj, scope, keynode);
            }
            if (retriever.HasChildren)
            {
                foreach (var r in retriever.Children)
                {
                    ProcessRetriever(obj, scope, r, keynode);
                }
            }
        }
예제 #3
0
 public virtual void Execute(AggregateNode node)
 {
     if (null != ExecuteFunction)
     {
         ExecuteFunction(node);
     }
 }
예제 #4
0
 public virtual bool Filter(object o, AggregateNode current, IScope scope)
 {
     if (null != FilterFunc)
     {
         return(FilterFunc(o, current, scope));
     }
     return(true);
 }
예제 #5
0
 protected virtual object InternalGetValue(object src, object currentValue, AggregateNode trg, IScope scope)
 {
     if (null != ValueFunction)
     {
         {
             return(ValueFunction(src, currentValue, trg, scope));
         }
     }
     return(null);
 }
예제 #6
0
        public override object GetValue(object src, object currentValue, AggregateNode trg, IScope scope)
        {
            var result = InternalGetValue(src, currentValue, trg, scope);

            if (null != result)
            {
                var dec     = result.ToDecimal();
                var current = currentValue.ToDecimal();
                return(current + dec);
            }
            return(currentValue);
        }
예제 #7
0
 public override object GetValue(object src, object currentValue, AggregateNode trg, IScope scope)
 {
     var result = InternalGetValue(src, currentValue, trg, scope);
     if (!Equals(0,result)) {
         var i = result.ToInt();
         if (0 == i) {
             i = 1;
         }
         
         return currentValue.ToInt() + i;
     }
     return currentValue.ToInt();
 }
예제 #8
0
        public override object GetValue(object src, object currentValue, AggregateNode trg, IScope scope)
        {
            var result = InternalGetValue(src, currentValue, trg, scope);

            if (!Equals(0, result))
            {
                var i = result.ToInt();
                if (0 == i)
                {
                    i = 1;
                }

                return(currentValue.ToInt() + i);
            }
            return(currentValue.ToInt());
        }
예제 #9
0
        private void SetValues(object obj, IScope scope, AggregateNode current)
        {
            foreach (var collector in Collectors)
            {
                if (!collector.Filter(obj, current, scope))
                {
                    continue;
                }

                var currentValue = current.GetValue(collector.Key);
                var newValue     = collector.GetValue(obj, currentValue, current, scope);
                if (currentValue != newValue && null != newValue)
                {
                    current.SetValue(collector.Key, newValue);
                }
            }
        }
예제 #10
0
        public override object GetValue(object src, object currentValue, AggregateNode trg, IScope scope)
        {
            var result = InternalGetValue(src, currentValue, trg, scope);

            if (null == result)
            {
                return(currentValue);
            }
            var key  = trg.Id + "_" + this.Id;
            var val  = result.ToStr();
            var vals = scope.Ensure(key, new List <string>());

            if (vals.Contains(val))
            {
                return(currentValue);
            }
            vals.Add(val);
            return(currentValue.ToInt() + 1);
        }
예제 #11
0
 public AggregateNode GetNode(string name, params string[] path)
 {
     if (name.Contains("/") || name.Contains("."))
     {
         var p = name.SmartSplit(false, true, '/', '.');
         return(GetNode(p[0], p.Skip(1).ToArray()));
     }
     if (path != null && 0 != path.Length)
     {
         var current = GetNode(name);
         foreach (var s in path)
         {
             current = current.GetNode(s);
         }
         return(current);
     }
     if (!Children.ContainsKey(name))
     {
         return(Children[name] = new AggregateNode {
             Parent = this
         });
     }
     return(Children[name]);
 }
예제 #12
0
 public virtual bool Filter(object src, AggregateNode trg, IScope scope)
 {
     return(true);
 }
예제 #13
0
        public virtual object GetValue(object src, object currentValue, AggregateNode trg, IScope scope)
        {
            var result = InternalGetValue(src, currentValue, trg, scope);

            return(result ?? currentValue);
        }
예제 #14
0
 public AggregateNode GetNode(string name, params string[] path) {
     if (name.Contains("/") || name.Contains(".")) {
         var p = name.SmartSplit(false, true, '/','.');
         return GetNode(p[0], p.Skip(1).ToArray());
     }
     if (path != null && 0 != path.Length) {
         var current = GetNode(name);
         foreach (var s in path) {
             current = current.GetNode(s);
         }
         return current;
     }
     if (!Children.ContainsKey(name)) {
         return Children[name] = new AggregateNode {Parent = this};
     }
     return Children[name];
 }
예제 #15
0
 public virtual bool Filter(object o, AggregateNode current, IScope scope) {
     if (null != FilterFunc) {
         return FilterFunc(o, current, scope);
     }
     return true;
 }