Search in sources :

Example 1 with EventHandlerInterface

use of com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface in project ma-core-public by MangoAutomation.

the class ScriptEventHandlerDefinition method createRuntimeInternal.

private ScriptEventHandlerRT createRuntimeInternal(ScriptEventHandlerVO vo) {
    Map<String, Object> bindings = Collections.singletonMap(ScriptEventHandlerRT.EVENT_HANDLER_KEY, vo);
    EvalContext context = new EvalContext(bindings);
    PermissionHolder user = Common.getUser();
    if (permissionService.hasPermission(user, standardStreamsPermission.getPermission())) {
        context.setWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        context.setErrorWriter(new BufferedWriter(new OutputStreamWriter(System.err)));
        context.setReader(new BufferedReader(new InputStreamReader(System.in)));
    }
    EventHandlerInterface scriptHandlerDelegate = scriptService.getInterface(vo.toMangoScript(), EventHandlerInterface.class, context);
    return new ScriptEventHandlerRT(vo, scriptHandlerDelegate);
}
Also used : ScriptEventHandlerRT(com.serotonin.m2m2.rt.event.handlers.ScriptEventHandlerRT) InputStreamReader(java.io.InputStreamReader) EvalContext(com.infiniteautomation.mango.spring.script.EvalContext) BufferedReader(java.io.BufferedReader) EventHandlerInterface(com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface) OutputStreamWriter(java.io.OutputStreamWriter) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) BufferedWriter(java.io.BufferedWriter)

Example 2 with EventHandlerInterface

use of com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface in project ma-core-public by infiniteautomation.

the class ScriptEventHandlerDefinition method createRuntimeInternal.

private ScriptEventHandlerRT createRuntimeInternal(ScriptEventHandlerVO vo) {
    Map<String, Object> bindings = Collections.singletonMap(ScriptEventHandlerRT.EVENT_HANDLER_KEY, vo);
    EvalContext context = new EvalContext(bindings);
    PermissionHolder user = Common.getUser();
    if (permissionService.hasPermission(user, standardStreamsPermission.getPermission())) {
        context.setWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        context.setErrorWriter(new BufferedWriter(new OutputStreamWriter(System.err)));
        context.setReader(new BufferedReader(new InputStreamReader(System.in)));
    }
    EventHandlerInterface scriptHandlerDelegate = scriptService.getInterface(vo.toMangoScript(), EventHandlerInterface.class, context);
    return new ScriptEventHandlerRT(vo, scriptHandlerDelegate);
}
Also used : ScriptEventHandlerRT(com.serotonin.m2m2.rt.event.handlers.ScriptEventHandlerRT) InputStreamReader(java.io.InputStreamReader) EvalContext(com.infiniteautomation.mango.spring.script.EvalContext) BufferedReader(java.io.BufferedReader) EventHandlerInterface(com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface) OutputStreamWriter(java.io.OutputStreamWriter) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) BufferedWriter(java.io.BufferedWriter)

Aggregations

EvalContext (com.infiniteautomation.mango.spring.script.EvalContext)2 EventHandlerInterface (com.serotonin.m2m2.rt.event.handlers.EventHandlerInterface)2 ScriptEventHandlerRT (com.serotonin.m2m2.rt.event.handlers.ScriptEventHandlerRT)2 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 InputStreamReader (java.io.InputStreamReader)2 OutputStreamWriter (java.io.OutputStreamWriter)2