Example #1
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();
            }
        }
        public async Task<IEditorScript> StartScript(IExportProvider exportProvider, string text, string filename, string contentType, IRSessionProvider sessionProvider) {
            var shell = exportProvider.GetExportedValue<ICoreShell>();
            var coreEditor = await InUI(() => new CoreEditor(shell, text, filename, contentType));
            var containerDisposable = await AddToHost(coreEditor.Control);

            if (sessionProvider != null) {
                IntelliSenseRSession.HostStartTimeout = 10000;
                HostScript = new RHostScript(sessionProvider);

                PackageIndex = exportProvider.GetExportedValue<IPackageIndex>();
                await PackageIndex.BuildIndexAsync();

                FunctionIndex = exportProvider.GetExportedValue<IFunctionIndex>();
                await FunctionIndex.BuildIndexAsync();
            }

            return new EditorScript(exportProvider, coreEditor, containerDisposable);
        }
Example #3
0
        public async Task BuildIndexAsync()
        {
            var ready = await _buildIndexLock.WaitAsync();

            try {
                if (!ready)
                {
                    var startTotalTime = DateTime.Now;

                    await TaskUtilities.SwitchToBackgroundThread();

                    await _host.CreateSessionAsync();

                    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 BuildPackageListAsync();

                    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);
            } finally {
                _buildIndexLock.Release();
            }
        }
Example #4
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();
            }
        }
        public async Task <IEditorScript> StartScript(ICoreShell coreShell, string text, string filename, string contentType, IRSessionProvider sessionProvider)
        {
            var coreEditor = await InUI(() => new CoreEditor(coreShell, text, filename, contentType));

            var containerDisposable = await AddToHost(coreEditor.Control);

            if (sessionProvider != null)
            {
                IntelliSenseRSession.HostStartTimeout = 10000;
                HostScript = new RHostScript(sessionProvider);

                PackageIndex = coreShell.GetService <IPackageIndex>();
                await PackageIndex.BuildIndexAsync();

                FunctionIndex = coreShell.GetService <IFunctionIndex>();
                await FunctionIndex.BuildIndexAsync();
            }

            return(new EditorScript(coreShell, coreEditor, containerDisposable));
        }
Example #6
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();
            }
        }