Ejemplo n.º 1
0
 public async Task <JavaObject> InvokeGetField(JavaObject javaObject, string fieldName, string className, CancellationToken ct)
 {
     return(await SendJavaRequest(RequestType.GetField, ct, fieldName : fieldName, className : className, javaObject : javaObject));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a request to the java process with one of the invoke options.
        /// Receives the response from the java process and it encapsulates it in JavaObject.
        /// Throws an exception if the result state is not Successful.
        /// </summary>
        /// <param name="requestType"></param>
        /// <param name="ct"></param>
        /// <param name="className"></param>
        /// <param name="methodName"></param>
        /// <param name="fieldName"></param>
        /// <param name="javaObject"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private async Task <JavaObject> SendJavaRequest(RequestType requestType, CancellationToken ct,
                                                        string className         = null, string methodName     = null,
                                                        string fieldName         = null, JavaObject javaObject = null,
                                                        List <object> parameters = null, List <Type> parametersTypes = null)
        {
            var request = new JavaRequest()
            {
                RequestType = requestType,
                MethodName  = methodName,
                ClassName   = className,
                FieldName   = fieldName,
                Instance    = javaObject?.Instance,
            };

            request.AddParametersToRequest(parameters);

            JavaResponse response = await _javaService.RequestAsync(request, ct);

            ct.ThrowIfCancellationRequested();
            response.ThrowExceptionIfNeeded();

            return(new JavaObject()
            {
                Instance = response.Result
            });
        }
Ejemplo n.º 3
0
 public async Task <JavaObject> InvokeMethod(string methodName, string className, JavaObject javaObject, List <object> parameters, List <Type> parametersTypes,
                                             CancellationToken ct)
 {
     return(await SendJavaRequest(className != null?RequestType.InvokeStaticMethod : RequestType.InvokeMethod, ct, methodName : methodName,
                                  className : className, javaObject : javaObject, parameters : parameters, parametersTypes : parametersTypes));
 }