Ejemplo n.º 1
0
        private MethodInvocationResult ExecuteMethodInvocation(MethodInvocation methodInvocation)
        {
            object result = null;
            string exception;
            var    success       = false;
            var    nameConverter = repository.NameConverter;

            //make sure we don't throw exceptions in the executor task
            try
            {
                success = repository.TryCallMethod(methodInvocation.ObjectId, methodInvocation.MethodName, methodInvocation.Parameters.ToArray(), out result, out exception);
            }
            catch (Exception e)
            {
                exception = e.Message;
            }

            return(new MethodInvocationResult
            {
                BrowserId = methodInvocation.BrowserId,
                CallbackId = methodInvocation.CallbackId,
                FrameId = methodInvocation.FrameId,
                Message = exception,
                Result = result,
                Success = success,
                NameConverter = nameConverter
            });
        }
Ejemplo n.º 2
0
        public BrowserProcessResponse CallMethod(long objectId, string name, object[] parameters)
        {
            var result = javascriptObjectRepository.TryCallMethod(objectId, name, parameters);

            return(new BrowserProcessResponse {
                Success = result.Success, Result = result.ReturnValue, Message = result.Exception
            });
        }
Ejemplo n.º 3
0
        public BrowserProcessResponse CallMethod(long objectId, string name, object[] parameters)
        {
            object result;
            string exception;

            var success = javascriptObjectRepository.TryCallMethod(objectId, name, parameters, out result, out exception);

            return(new BrowserProcessResponse {
                Success = success, Result = result, Message = exception
            });
        }
Ejemplo n.º 4
0
        private MethodInvocationResult ExecuteMethodInvocation(MethodInvocation methodInvocation)
        {
            object returnValue = null;
            string exception;
            var    success       = false;
            var    nameConverter = repository.NameConverter;

            //make sure we don't throw exceptions in the executor task
            try
            {
                var result = repository.TryCallMethod(methodInvocation.ObjectId, methodInvocation.MethodName, methodInvocation.Parameters.ToArray());
                success     = result.Success;
                returnValue = result.ReturnValue;
                exception   = result.Exception;

                //We don't support Tasks by default
                if (success && returnValue != null && (typeof(Task).IsAssignableFrom(returnValue.GetType())))
                {
                    //Use StringBuilder to improve the formatting/readability of the error message
                    //I'm sure there's a better way I just cannot remember of the top of my head so going
                    //with this for now, as it's only for error scenaiors I'm not concerned about performance.
                    var builder = new System.Text.StringBuilder();
                    builder.AppendLine("Your method returned a Task which is not supported by default you must set CefSharpSettings.ConcurrentTaskExecution = true; before creating your first ChromiumWebBrowser instance.");
                    builder.AppendLine("This will likely change to the default at some point in the near future, subscribe to the issue link below to be notified of any changes.");
                    builder.AppendLine("See https://github.com/cefsharp/CefSharp/issues/2758 for more details, please report any issues you have there, make sure you have an example ready that reproduces your problem.");

                    success   = false;
                    result    = null;
                    exception = builder.ToString();
                }
            }
            catch (Exception e)
            {
                exception = e.Message;
            }

            return(new MethodInvocationResult
            {
                BrowserId = methodInvocation.BrowserId,
                CallbackId = methodInvocation.CallbackId,
                FrameId = methodInvocation.FrameId,
                Message = exception,
                Result = returnValue,
                Success = success,
                NameConverter = nameConverter
            });
        }