Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously fetches RD data on the function from R.
        /// </summary>
        public async Task <string> GetFunctionRdDataAsync(string functionName, string packageName)
        {
            if (packageName.EqualsOrdinal("rtvs"))
            {
                return(GetRtvsFunctionRdData(functionName));
            }

            await TaskUtilities.SwitchToBackgroundThread();

            await _host.StartSessionAsync();

            string command = GetCommandText(functionName, packageName);

            try {
                return(await _host.Session.EvaluateAsync <string>(command, REvaluationKind.Normal));
            } catch (RException) { }

            // Sometimes there is no information in a specific package.
            // For example, Matrix exports 'as.matrix' and base does it as well.
            // However, help('as.matrix', 'Matrix') will fail while help('as.matrix' will succeed.
            command = GetCommandText(functionName, null);
            try {
                return(await _host.Session.EvaluateAsync <string>(command, REvaluationKind.Normal));
            } catch (RException) { }

            return(string.Empty);
        }
Ejemplo n.º 2
0
        private async Task BuildIndexAsync(IBinaryAsyncLockToken lockToken, CancellationToken ct)
        {
            try {
                if (!lockToken.IsSet)
                {
                    await TaskUtilities.SwitchToBackgroundThread();

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    // Ensure session is started
                    await _host.StartSessionAsync(ct);

                    Debug.WriteLine("R function host start: {0} ms", stopwatch.ElapsedMilliseconds);

                    // Fetch list of package functions from R session
                    _disposableBag.ThrowIfDisposed();
                    stopwatch.Reset();
                    await LoadInstalledPackagesIndexAsync(ct);

                    Debug.WriteLine("Fetch list of package functions from R session: {0} ms", stopwatch.ElapsedMilliseconds);

                    // Try load missing functions from cache or explicitly
                    _disposableBag.ThrowIfDisposed();
                    stopwatch.Reset();
                    await LoadRemainingPackagesFunctions(ct);

                    Debug.WriteLine("Try load missing functions from cache or explicitly: {0} ms", stopwatch.ElapsedMilliseconds);

                    // Build index
                    _disposableBag.ThrowIfDisposed();
                    stopwatch.Reset();
                    await _functionIndex.BuildIndexAsync(this, ct);

                    Debug.WriteLine("R function index build: {0} ms", stopwatch.ElapsedMilliseconds);

                    stopwatch.Stop();
                }
            } catch (RHostDisconnectedException ex) {
                Debug.WriteLine(ex.Message);
                ScheduleIdleTimeRebuild();
            } catch (ObjectDisposedException) { }
            finally {
                lockToken.Set();
            }
        }
Ejemplo n.º 3
0
        private async Task BuildIndexAsync(IBinaryAsyncLockToken lockToken)
        {
            try {
                if (!lockToken.IsSet)
                {
                    var startTotalTime = DateTime.Now;

                    await TaskUtilities.SwitchToBackgroundThread();

                    await _host.StartSessionAsync();

                    Debug.WriteLine("R function host start: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds);

                    var startTime = DateTime.Now;
                    // Fetch list of available packages from R session
                    await BuildInstalledPackagesIndexAsync();

                    Debug.WriteLine("R package names/description: {0} ms", (DateTime.Now - startTime).TotalMilliseconds);

                    // Populate function index for preloaded packages first
                    startTime = DateTime.Now;
                    await BuildPreloadedPackagesFunctionListAsync();

                    Debug.WriteLine("R function index (preloaded): {0} ms", (DateTime.Now - startTime).TotalMilliseconds);

                    // Populate function index for all remaining packages
                    startTime = DateTime.Now;
                    await BuildRemainingPackagesFunctionListAsync();

                    Debug.WriteLine("R function index (remaining): {0} ms", (DateTime.Now - startTime).TotalMilliseconds);

                    await _functionIndex.BuildIndexAsync(this);

                    Debug.WriteLine("R function index total: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds);
                }
            } catch (RHostDisconnectedException ex) {
                Debug.WriteLine(ex.Message);
                ScheduleIdleTimeRebuild();
            } finally {
                lockToken.Set();
            }
        }
Ejemplo n.º 4
0
        private async Task BuildIndexAsync(IBinaryAsyncLockToken lockToken)
        {
            try {
                if (!lockToken.IsSet)
                {
                    await TaskUtilities.SwitchToBackgroundThread();

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    // Ensure session is started
                    await _host.StartSessionAsync();

                    Debug.WriteLine("R function host start: {0} ms", stopwatch.ElapsedMilliseconds);

                    // Fetch list of package functions from R session
                    await LoadInstalledPackagesIndexAsync();

                    Debug.WriteLine("Fetch list of package functions from R session: {0} ms", stopwatch.ElapsedMilliseconds);

                    // Try load missing functions from cache or explicitly
                    await LoadRemainingPackagesFunctions();

                    Debug.WriteLine("Try load missing functions from cache or explicitly: {0} ms", stopwatch.ElapsedMilliseconds);

                    // Build index
                    await _functionIndex.BuildIndexAsync(this);

                    Debug.WriteLine("R function index total: {0} ms", stopwatch.ElapsedMilliseconds);

                    stopwatch.Stop();
                }
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                Debug.WriteLine(ex.Message);
                ScheduleIdleTimeRebuild();
            } finally {
                lockToken.Set();
            }
        }
Ejemplo n.º 5
0
        private async Task <IEnumerable <string> > GetFunctionNamesAsync()
        {
            var functions = TryRestoreFromCache();

            if (functions == null || !functions.Any())
            {
                try {
                    await _host.StartSessionAsync();

                    var result = await _host.Session.PackagesFunctionsNamesAsync(Name, REvaluationKind.BaseEnv);

                    functions = result.Children <JValue>().Select(v => (string)v.Value);
                } catch (RException) { }
            }
            else
            {
                _saved = true;
            }
            return(functions ?? Enumerable.Empty <string>());
        }