예제 #1
0
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken ct)
        {
            string javaPath = JavaPath.Get(context);

            if (javaPath != null)
            {
                javaPath = Path.Combine(javaPath, "bin", "java.exe");
                if (!File.Exists(javaPath))
                {
                    throw new ArgumentException(Resources.InvalidJavaPath, Resources.JavaPathDisplayName);
                }
            }
            _invoker = new JavaInvoker(javaPath);

            try
            {
                await _invoker.StartJavaService();
            }
            catch (Exception e)
            {
                Trace.TraceError($"Error initializing Java Invoker: {e.ToString()}");
                throw new InvalidOperationException(string.Format(Resources.JavaInitiazeException, e.ToString()));
            }
            ct.ThrowIfCancellationRequested();
            return(ctx =>
            {
                ctx.ScheduleAction(Body, _invoker, OnCompleted, OnFaulted);
            });
        }
예제 #2
0
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken ct)
        {
            string javaPath = JavaPath.Get(context);
            var    javaExec = _javaExeWindows;

#if NETCOREAPP
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                javaExec = _javaExeLinux;
            }
#endif
            if (javaPath != null)
            {
                javaPath = Path.Combine(javaPath, "bin", javaExec);
                if (!File.Exists(javaPath))
                {
                    throw new ArgumentException(Resources.InvalidJavaPath, Resources.JavaPathDisplayName);
                }
            }
            _invoker = new JavaInvoker(javaPath);

            int initTimeout = TimeoutMS.Get(context);
            if (initTimeout < 0)
            {
                throw new ArgumentException(UiPath.Java.Activities.Properties.Resources.TimeoutMSException, "TimeoutMS");
            }

            try
            {
                await _invoker.StartJavaService(initTimeout);
            }
            catch (Exception e)
            {
                Trace.TraceError($"Error initializing Java Invoker: {e}");
                throw new InvalidOperationException(string.Format(Resources.JavaInitiazeException, e.ToString()));
            }
            ct.ThrowIfCancellationRequested();
            return(ctx =>
            {
                ctx.ScheduleAction(Body, _invoker, OnCompleted, OnFaulted);
            });
        }