예제 #1
0
 public PollExecStrategyMethod(
     MethodTargetStrategy methodTargetStrategy,
     MethodConversionStrategy methodConversionStrategy)
 {
     this.methodTargetStrategy = methodTargetStrategy;
     this.methodConversionStrategy = methodConversionStrategy;
 }
        public override IList<EventBean> Convert(
            object invocationResult,
            MethodTargetStrategy origin,
            AgentInstanceContext agentInstanceContext)
        {
            var array = (Array) invocationResult;
            var length = array.Length;
            if (length == 0) {
                return Collections.GetEmptyList<EventBean>();
            }

            if (length == 1) {
                var value = array.GetValue(0);
                if (CheckNonNullArrayValue(value, origin)) {
                    var @event = GetEventBean(value, agentInstanceContext);
                    return Collections.SingletonList(@event);
                }

                return Collections.GetEmptyList<EventBean>();
            }

            var rowResult = new List<EventBean>(length);
            for (var i = 0; i < length; i++) {
                var value = array.GetValue(i);
                if (CheckNonNullArrayValue(value, origin)) {
                    var @event = GetEventBean(value, agentInstanceContext);
                    rowResult.Add(@event);
                }
            }

            return rowResult;
        }
        public override IList<EventBean> Convert(
            object invocationResult,
            MethodTargetStrategy origin,
            AgentInstanceContext agentInstanceContext)
        {
            ICollection<object> collection = invocationResult.Unwrap<object>();
            var length = collection.Count;
            if (length == 0) {
                return Collections.GetEmptyList<EventBean>();
            }

            if (length == 1) {
                object value = collection.First();
                if (CheckNonNullArrayValue(value, origin)) {
                    var @event = GetEventBean(value, agentInstanceContext);
                    return Collections.SingletonList(@event);
                }

                return Collections.GetEmptyList<EventBean>();
            }

            var rowResult = new List<EventBean>(length);
            foreach (var value in collection) {
                if (CheckNonNullArrayValue(value, origin)) {
                    var @event = GetEventBean(value, agentInstanceContext);
                    rowResult.Add(@event);
                }
            }

            return rowResult;
        }
예제 #4
0
 public override IList<EventBean> Convert(
     object invocationResult,
     MethodTargetStrategy origin,
     AgentInstanceContext agentInstanceContext)
 {
     return Collections.SingletonList(
         agentInstanceContext.EventBeanTypedEventFactory.AdapterForTypedObject(invocationResult, eventType));
 }
예제 #5
0
        public override IList<EventBean> Convert(
            object invocationResult,
            MethodTargetStrategy origin,
            AgentInstanceContext agentInstanceContext)
        {
            if (!(invocationResult is EventBean[])) {
                string result = invocationResult == null
                    ? "null"
                    : invocationResult.GetType().Name;
                Log.Warn("Script expected return type EventBean[] does not match result " + result);
                return Collections.GetEmptyList<EventBean>();
            }

            return invocationResult.UnwrapIntoList<EventBean>();
        }
        public override IList<EventBean> Convert(
            object invocationResult,
            MethodTargetStrategy origin,
            AgentInstanceContext agentInstanceContext)
        {
            if (invocationResult == null) {
                return Collections.GetEmptyList<EventBean>();
            }

            if (invocationResult.GetType().IsArray) {
                return invocationResult.UnwrapIntoList<EventBean>();
            }

            if (invocationResult.GetType().IsGenericCollection()) {
                var collection = invocationResult.Unwrap<EventBean>();
                var length = collection.Count;
                if (length == 0) {
                    return Collections.GetEmptyList<EventBean>();
                }

                var genRowResult = new List<EventBean>(length);
                foreach (var value in collection) {
                    if (value != null) {
                        genRowResult.Add(value);
                    }
                }

                return genRowResult;
            }

            using (var enumerator = (IEnumerator<EventBean>) invocationResult) {
                if (!enumerator.MoveNext()) {
                    return Collections.GetEmptyList<EventBean>();
                }

                var rowResult = new List<EventBean>();
                do {
                    var value = enumerator.Current;
                    if (value != null) {
                        rowResult.Add(value);
                    }
                } while (enumerator.MoveNext());

                return rowResult;
            }
        }
예제 #7
0
        public override IList<EventBean> Convert(
            object invocationResult,
            MethodTargetStrategy origin,
            AgentInstanceContext agentInstanceContext)
        {
            var enumerator = (IEnumerator) invocationResult;
            if (enumerator == null || !enumerator.MoveNext()) {
                return Collections.GetEmptyList<EventBean>();
            }

            var rowResult = new List<EventBean>();
            do {
                object value = enumerator.Current;
                if (CheckNonNullArrayValue(value, origin)) {
                    var @event = GetEventBean(value, agentInstanceContext);
                    rowResult.Add(@event);
                }
            } while (enumerator.MoveNext());

            return rowResult;
        }