public static Object GetFragmentPono(Object result, BeanEventType eventType, EventAdapterService eventAdapterService) { if (result == null) { return(null); } if (result is EventBean[]) { return(result); } if (result is EventBean) { return(result); } if (result is Array) { var arrayX = (Array)result; var len = arrayX.Length; var events = new EventBean[len]; for (var i = 0; i < events.Length; i++) { events[i] = eventAdapterService.AdapterForTypedObject(arrayX.GetValue(i), eventType); } return(events); } return(eventAdapterService.AdapterForTypedObject(result, eventType)); }
public Object GetFragment(EventBean eventBean) { DetermineFragmentable(); if (!_isFragmentable) { return null; } var @object = Get(eventBean); if (@object == null) { return null; } if (_isArray) { return ToFragmentArray((Object[])@object, _fragmentEventType, _eventAdapterService); } else if (_isIterable) { return ToFragmentIterable(@object, _fragmentEventType, _eventAdapterService); } else { return _eventAdapterService.AdapterForTypedObject(@object, _fragmentEventType); } }
private EventBean GetEventBean(Object theEvent) { // type check if (theEvent.GetType() != _beanEventType.UnderlyingType) { using (_iLock.Acquire()) { if (!_compatibleClasses.Contains(theEvent.GetType())) { if (TypeHelper.IsSubclassOrImplementsInterface( theEvent.GetType(), _beanEventType.UnderlyingType)) { _compatibleClasses.Add(theEvent.GetType()); } else { throw new EPException( "Event object of type " + theEvent.GetType().FullName + " does not equal, extend or implement the type " + _beanEventType.UnderlyingType.FullName + " of event type '" + _beanEventType.Name + "'"); } } } } return(_eventAdapterService.AdapterForTypedObject(theEvent, _beanEventType)); }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="array">array</param> /// <param name="fragmentEventType">fragment type</param> /// <param name="eventAdapterService">event adapters</param> /// <returns>array</returns> public static Object ToFragmentArray(Array array, BeanEventType fragmentEventType, EventAdapterService eventAdapterService) { var events = new EventBean[array.Length]; int countFilled = 0; for (int i = 0; i < array.Length; i++) { var element = array.GetValue(i); if (element == null) { continue; } events[countFilled] = eventAdapterService.AdapterForTypedObject(element, fragmentEventType); countFilled++; } if (countFilled == array.Length) { return events; } if (countFilled == 0) { return new EventBean[0]; } var returnVal = new EventBean[countFilled]; Array.Copy(events, 0, returnVal, 0, countFilled); return returnVal; }
/// <summary>Return an adapter for the given type of event using the pre-validated object. </summary> /// <param name="theEvent">value object</param> /// <param name="eventType">type of event</param> /// <param name="eventAdapterService">service for instances</param> /// <returns>event adapter</returns> public static EventBean AdapterForType(Object theEvent, EventType eventType, EventAdapterService eventAdapterService) { if (theEvent == null) { return(null); } if (eventType is BeanEventType) { return(eventAdapterService.AdapterForTypedObject(theEvent, eventType)); } else if (eventType is MapEventType) { return(eventAdapterService.AdapterForTypedMap((IDictionary <string, object>)theEvent, eventType)); } else if (eventType is ObjectArrayEventType) { return(eventAdapterService.AdapterForTypedObjectArray((Object[])theEvent, eventType)); } else if (eventType is BaseConfigurableEventType) { return(eventAdapterService.AdapterForTypedDOM((XmlNode)theEvent, eventType)); } else { return(null); } }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// Returns the fragment for dynamic properties. /// </summary> /// <param name="object">to inspect</param> /// <param name="fragmentEventType">type</param> /// <param name="eventAdapterService">factory for event beans and event types</param> /// <returns>fragment</returns> public static Object ToFragmentIterable(Object @object, BeanEventType fragmentEventType, EventAdapterService eventAdapterService) { if (!(@object is IEnumerable)) { return null; } var enumerator = ((IEnumerable) @object).GetEnumerator(); if (!enumerator.MoveNext()) { return new EventBean[0]; } var events = new ArrayDeque<EventBean>(); do { var next = enumerator.Current; if (next == null) { continue; } events.Add(eventAdapterService.AdapterForTypedObject(next, fragmentEventType)); } while (enumerator.MoveNext()); return events.ToArray(); }
public EventBean Process(EventBean[] eventsPerStream, bool isNewData, bool isSynthesize, ExprEvaluatorContext exprEvaluatorContext) { EventBean theEvent = eventsPerStream[_streamNumber]; EventBean recast = _eventAdapterService.AdapterForTypedObject(theEvent.Underlying, _eventType.UnderlyingEventType); return(_eventAdapterService.AdapterForTypedWrapper(recast, new Dictionary <string, object>(), _eventType)); }
public override EventBean Process(EventBean[] eventsPerStream, bool isNewData, bool isSynthesize, ExprEvaluatorContext exprEvaluatorContext) { var evaluateParams = new EvaluateParams(eventsPerStream, isNewData, exprEvaluatorContext); var result = ExprEvaluator.Evaluate(evaluateParams); if (result == null) { return(null); } return(EventAdapterService.AdapterForTypedObject(result, EventType)); }
public static EventBean[] TypeCast(IList <EventBean> events, EventType targetType, EventAdapterService eventAdapterService) { var convertedArray = new EventBean[events.Count]; var count = 0; foreach (EventBean theEvent in events) { EventBean converted; if (theEvent is DecoratingEventBean) { var wrapper = (DecoratingEventBean)theEvent; if (targetType is MapEventType) { IDictionary <String, Object> props = new Dictionary <String, Object>(); props.PutAll(wrapper.DecoratingProperties); foreach (EventPropertyDescriptor propDesc in wrapper.UnderlyingEvent.EventType.PropertyDescriptors) { props.Put(propDesc.PropertyName, wrapper.UnderlyingEvent.Get(propDesc.PropertyName)); } converted = eventAdapterService.AdapterForTypedMap(props, targetType); } else { converted = eventAdapterService.AdapterForTypedWrapper(wrapper.UnderlyingEvent, wrapper.DecoratingProperties, targetType); } } else if ((theEvent.EventType is MapEventType) && (targetType is MapEventType)) { var mapEvent = (MappedEventBean)theEvent; converted = eventAdapterService.AdapterForTypedMap(mapEvent.Properties, targetType); } else if ((theEvent.EventType is MapEventType) && (targetType is WrapperEventType)) { converted = eventAdapterService.AdapterForTypedWrapper(theEvent, Collections.EmptyDataMap, targetType); } else if ((theEvent.EventType is BeanEventType) && (targetType is BeanEventType)) { converted = eventAdapterService.AdapterForTypedObject(theEvent.Underlying, targetType); } else if (theEvent.EventType is ObjectArrayEventType && targetType is ObjectArrayEventType) { Object[] convertedObjectArray = ObjectArrayEventType.ConvertEvent(theEvent, (ObjectArrayEventType)targetType); converted = eventAdapterService.AdapterForTypedObjectArray(convertedObjectArray, targetType); } else { throw new EPException("Unknown event type " + theEvent.EventType); } convertedArray[count] = converted; count++; } return(convertedArray); }
public void TestMapNestedEventType() { _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean)); EventType supportBeanType = _epService.EPAdministrator.Configuration.GetEventType("SupportBean"); IDictionary <String, Object> lev2def = new Dictionary <String, Object>(); lev2def["sb"] = "SupportBean"; IDictionary <String, Object> lev1def = new Dictionary <String, Object>(); lev1def["lev1name"] = lev2def; IDictionary <String, Object> lev0def = new Dictionary <String, Object>(); lev0def["lev0name"] = lev1def; _epService.EPAdministrator.Configuration.AddEventType("MyMap", lev0def); Assert.NotNull(_epService.EPAdministrator.Configuration.GetEventType("MyMap")); var listener = new SupportUpdateListener(); _epService.EPAdministrator.CreateEPL("select lev0name.lev1name.sb.TheString as val from MyMap").Events += listener.Update; EventAdapterService eventAdapterService = ((EPServiceProviderSPI)_epService).EventAdapterService; IDictionary <String, Object> lev2data = new Dictionary <String, Object>(); lev2data["sb"] = eventAdapterService.AdapterForTypedObject(new SupportBean("E1", 0), supportBeanType); IDictionary <String, Object> lev1data = new Dictionary <String, Object>(); lev1data["lev1name"] = lev2data; IDictionary <String, Object> lev0data = new Dictionary <String, Object>(); lev0data["lev0name"] = lev1data; _epService.EPRuntime.SendEvent(lev0data, "MyMap"); Assert.AreEqual("E1", listener.AssertOneGetNewAndReset().Get("val")); try { _epService.EPRuntime.SendEvent(new Object[0], "MyMap"); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual( "Event type named 'MyMap' has not been defined or is not a Object-array event type, the name 'MyMap' refers to a " + typeof(IDictionary <string, object>).FullName + " event type", ex.Message); } }
private void RunAssertionMapNestedEventType(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EventType supportBeanType = epService.EPAdministrator.Configuration.GetEventType("SupportBean"); var lev2def = new Dictionary <string, object>(); lev2def.Put("sb", "SupportBean"); var lev1def = new Dictionary <string, object>(); lev1def.Put("lev1name", lev2def); var lev0def = new Dictionary <string, object>(); lev0def.Put("lev0name", lev1def); epService.EPAdministrator.Configuration.AddEventType("MyMap", lev0def); Assert.IsNotNull(epService.EPAdministrator.Configuration.GetEventType("MyMap")); var listener = new SupportUpdateListener(); epService.EPAdministrator.CreateEPL("select lev0name.lev1name.sb.TheString as val from MyMap").Events += listener.Update; EventAdapterService eventAdapterService = ((EPServiceProviderSPI)epService).EventAdapterService; var lev2data = new Dictionary <string, object>(); lev2data.Put("sb", eventAdapterService.AdapterForTypedObject(new SupportBean("E1", 0), supportBeanType)); var lev1data = new Dictionary <string, object>(); lev1data.Put("lev1name", lev2data); var lev0data = new Dictionary <string, object>(); lev0data.Put("lev0name", lev1data); epService.EPRuntime.SendEvent(lev0data, "MyMap"); Assert.AreEqual("E1", listener.AssertOneGetNewAndReset().Get("val")); try { epService.EPRuntime.SendEvent(new object[0], "MyMap"); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual("Event type named 'MyMap' has not been defined or is not a Object-array event type, the name 'MyMap' refers to a " + typeof(IDictionary <string, object>).GetCleanName() + " event type", ex.Message); } epService.EPAdministrator.DestroyAllStatements(); }
public ICollection <object> Convert(Object result) { if (result == null) { return(null); } var asEnum = result.Unwrap <object>(); if (asEnum == null) { return(null); } return(asEnum .Select(item => _eventAdapterService.AdapterForTypedObject(item, _type)) .ToArray()); }
public ICollection <object> Convert(Object result) { if (result == null) { return(null); } var asArray = result as Array; if (asArray == null) { return(null); } return(asArray.Cast <object>() .Select(item => _eventAdapterService.AdapterForTypedObject(item, _type)) .Cast <object>() .ToList()); }
public EventBean Copy(EventBean theEvent) { Object underlying = theEvent.Underlying; Object copied; try { copied = _copyMethod.Invoke(underlying, null); } catch (TargetInvocationException e) { Log.Error("TargetInvocationException copying event object for Update: " + e.Message, e); return(null); } catch (Exception e) { Log.Error("RuntimeException copying event object for Update: " + e.Message, e); return(null); } return(_eventAdapterService.AdapterForTypedObject(copied, _beanEventType)); }
public EventBean Copy(EventBean theEvent) { Object underlying = theEvent.Underlying; Object copied; try { copied = SerializableObjectCopier.Copy(underlying); } catch (IOException e) { Log.Error("IOException copying event object for Update: " + e.Message, e); return(null); } catch (TypeLoadException e) { Log.Error("Exception copying event object for Update: " + e.Message, e); return(null); } return(_eventAdapterService.AdapterForTypedObject(copied, _beanEventType)); }
public override void Run(EPServiceProvider epService) { EventAdapterService eventAdapterService = ((EPServiceProviderSPI)epService).EventAdapterService; epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EventType supportBeanType = epService.EPAdministrator.Configuration.GetEventType("SupportBean"); var lev2def = new Dictionary <string, Object>(); lev2def.Put("sb", "SupportBean"); var lev1def = new Dictionary <string, Object>(); lev1def.Put("lev1name", lev2def); epService.EPAdministrator.Configuration.AddEventType("MyMapNestedObjectArray", new string[] { "lev0name" }, new object[] { lev1def }); Assert.AreEqual(typeof(object[]), epService.EPAdministrator.Configuration.GetEventType("MyMapNestedObjectArray").UnderlyingType); var listener = new SupportUpdateListener(); epService.EPAdministrator.CreateEPL("select lev0name.lev1name.sb.TheString as val from MyMapNestedObjectArray").Events += listener.Update; var lev2data = new Dictionary <string, Object>(); lev2data.Put("sb", eventAdapterService.AdapterForTypedObject(new SupportBean("E1", 0), supportBeanType)); var lev1data = new Dictionary <string, Object>(); lev1data.Put("lev1name", lev2data); epService.EPRuntime.SendEvent(new object[] { lev1data }, "MyMapNestedObjectArray"); Assert.AreEqual("E1", listener.AssertOneGetNewAndReset().Get("val")); try { epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MyMapNestedObjectArray"); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual("Event type named 'MyMapNestedObjectArray' has not been defined or is not a Map event type, the name 'MyMapNestedObjectArray' refers to a System.Object[] event type", ex.Message); } }
public EventBean Wrap(Object underlying) { EventBean bean = _eventAdapterService.AdapterForTypedObject(underlying, _beanEventType); return(_eventAdapterService.AdapterForTypedWrapper(bean, new EmptyDictionary <string, object>(), _wrapperEventType)); }
public EventBean Wrap(Object underlying) { return(_eventAdapterService.AdapterForTypedObject(underlying, _type)); }
public EventBean Make(Object[] propertyValues) { Object outObject = MakeUnderlying(propertyValues); return(_service.AdapterForTypedObject(outObject, _beanEventType)); }
/// <summary>Returns the fragment for dynamic properties. </summary> /// <param name="object">to inspect</param> /// <param name="eventAdapterService">factory for event beans and event types</param> /// <returns>fragment</returns> public static Object GetFragmentDynamic(Object @object, EventAdapterService eventAdapterService) { if (@object == null) { return(null); } BeanEventType fragmentEventType = null; bool isArray = false; if (@object.GetType().IsArray) { if (@object.GetType().GetElementType().IsFragmentableType()) { isArray = true; fragmentEventType = eventAdapterService.BeanEventTypeFactory.CreateBeanTypeDefaultName(@object.GetType().GetElementType()); } } else { if (@object.GetType().IsFragmentableType()) { fragmentEventType = eventAdapterService.BeanEventTypeFactory.CreateBeanTypeDefaultName(@object.GetType()); } } if (fragmentEventType == null) { return(null); } if (isArray) { var asArray = (Array)@object; var len = asArray.Length; var events = new EventBean[len]; int countFilled = 0; for (int i = 0; i < len; i++) { Object element = asArray.GetValue(i); if (element == null) { continue; } events[countFilled] = eventAdapterService.AdapterForTypedObject(element, fragmentEventType); countFilled++; } if (countFilled == len) { return(events); } if (countFilled == 0) { return(new EventBean[0]); } var returnVal = new EventBean[countFilled]; Array.Copy(events, 0, returnVal, 0, countFilled); return(returnVal); } else { return(eventAdapterService.AdapterForTypedObject(@object, fragmentEventType)); } }
public Object GetFragment(EventBean eventBean) { Object @object = Get(eventBean); if (@object == null) { return(null); } if (!_isFragmentable) { return(null); } if (_fragmentEventType == null) { if (_fragmentClassType.IsFragmentableType()) { _fragmentEventType = _eventAdapterService.BeanEventTypeFactory.CreateBeanTypeDefaultName(_fragmentClassType); } else { _isFragmentable = false; return(null); } } if (_isArray) { var asArray = (Array)@object; var len = asArray.Length; var events = new EventBean[len]; int countFilled = 0; for (int i = 0; i < len; i++) { Object element = asArray.GetValue(i); if (element == null) { continue; } events[countFilled] = _eventAdapterService.AdapterForTypedObject(element, _fragmentEventType); countFilled++; } if (countFilled == len) { return(events); } if (countFilled == 0) { return(new EventBean[0]); } var returnVal = new EventBean[countFilled]; Array.Copy(events, 0, returnVal, 0, countFilled); return(returnVal); } else if (_isIterable) { if (!(@object is IEnumerable)) { return(null); } IEnumerator enumerator = ((IEnumerable)@object).GetEnumerator(); if (!enumerator.MoveNext()) { return(new EventBean[0]); } var events = new List <EventBean>(); do { Object next = enumerator.Current; if (next == null) { continue; } events.Add(_eventAdapterService.AdapterForTypedObject(next, _fragmentEventType)); } while (enumerator.MoveNext()); return(events.ToArray()); } else { return(_eventAdapterService.AdapterForTypedObject(@object, _fragmentEventType)); } }
public EventBean Make(object[] properties) { object instance = MakeUnderlying(properties); return _eventAdapterService.AdapterForTypedObject(instance, _beanEventType); }
public EventBean Process(EventBean[] eventsPerStream, bool isNewData, bool isSynthesize, ExprEvaluatorContext exprEvaluatorContext) { EventBean theEvent = eventsPerStream[_streamNumber]; return(_eventAdapterService.AdapterForTypedObject(theEvent.Underlying, _eventType)); }