protected override void Execute(CodeActivityContext context) { IInvoker invoker = JavaScope.GetJavaInvoker(context); var javaObject = JavaObject.Get(context) ?? throw new ArgumentNullException(Resources.JavaObject); Result.Set(context, javaObject.Convert <T>()); }
protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { IInvoker invoker = JavaScope.GetJavaInvoker(context); var fieldName = FieldName.Get(context) ?? throw new ArgumentNullException(Resources.FieldName); var javaObject = TargetObject.Get(context); var className = TargetType.Get(context); if (javaObject == null && className == null) { throw new InvalidOperationException(Resources.InvokationObjectException); } JavaObject instance; try { instance = await invoker.InvokeGetField(javaObject, fieldName, className, cancellationToken); } catch (Exception e) { Trace.TraceError($"Could not get java field: {e}"); throw new InvalidOperationException(Resources.GetFieldException, e); } return(asyncCodeActivityContext => { Result.Set(asyncCodeActivityContext, instance); }); }
protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { IInvoker invoker = JavaScope.GetJavaInvoker(context); var className = TargetType.Get(context); if (string.IsNullOrWhiteSpace(className)) { throw new ArgumentNullException(nameof(TargetType)); } List <object> parameters = GetParameters(context); JavaObject instance = null; try { instance = await invoker.InvokeConstructor(className, parameters, parameters.Select(param => param?.GetType()).ToList(), cancellationToken); } catch (Exception e) { Trace.TraceError($"Constrcutor could not be invoker: {e.ToString()}"); throw new InvalidOperationException(Resources.ConstructorException, e); } return(asyncCodeActivityContext => { Result.Set(asyncCodeActivityContext, instance); }); }
protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { IInvoker invoker = JavaScope.GetJavaInvoker(context); var methodName = MethodName.Get(context) ?? throw new ArgumentNullException(Resources.MethodName); JavaObject javaObject = TargetObject.Get(context); string className = TargetType.Get(context); if (javaObject == null && string.IsNullOrWhiteSpace(className)) { throw new InvalidOperationException(Resources.InvokationObjectException); } List <object> parameters = GetParameters(context); var types = GetParameterTypes(context, parameters); JavaObject instance = null; try { instance = await invoker.InvokeMethod(methodName, className, javaObject, parameters, types, cancellationToken); } catch (Exception e) { Trace.TraceError($"The method could not be invoked: {e}"); throw new InvalidOperationException(Resources.InvokeMethodException, e); } return(asyncCodeActivityContext => { Result.Set(asyncCodeActivityContext, instance); }); }
protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { IInvoker invoker = JavaScope.GetJavaInvoker(context); var jarPath = JarPath.Get(context) ?? throw new ArgumentNullException(Resources.JarPathDisplayName); try { await invoker.LoadJar(jarPath, cancellationToken); } catch (Exception e) { Trace.TraceError($"Jar could not be loaded{e.ToString()}"); throw new InvalidOperationException(Resources.LoadJarException, e); } return(asyncCodeActivityContext => { }); }