public async Task ReleaseProjectContextAsync(IWorkspaceProjectContextAccessor accessor)
        {
            Requires.NotNull(accessor, nameof(accessor));

            try
            {
                accessor.Context.Dispose();
            }
            catch (Exception ex)
            {
                await _faultHandlerService.ReportFaultAsync(ex, _project, ProjectFaultSeverity.Recoverable);
            }
        }
        public async Task ReleaseProjectContextAsync(IWorkspaceProjectContextAccessor accessor)
        {
            Requires.NotNull(accessor, nameof(accessor));

            // TODO: https://github.com/dotnet/project-system/issues/353.
            await _threadingService.SwitchToUIThread();

            try
            {
                accessor.Context.Dispose();
            }
            catch (Exception ex)
            {
                await _faultHandlerService.ReportFaultAsync(ex, _project, ProjectFaultSeverity.Recoverable);
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Attaches error handling to a block so that if it throws an unhandled exception,
        ///     the error will be reported to the user.
        /// </summary>
        /// <param name="faultHandlerService">
        ///     The <see cref="IProjectFaultHostHandler"/> that should handle the fault.
        /// </param>
        /// <param name="block">
        ///     The block to attach error handling to.
        /// </param>
        /// <param name="project">
        ///     The project related to the failure, if applicable. Can be <see langword="null"/>.
        /// </param>
        /// <param name="severity">
        ///     The severity of the failure.
        /// </param>
        public static Task RegisterFaultHandler(
            this IProjectFaultHandlerService faultHandlerService,
            IDataflowBlock block,
            UnconfiguredProject?project,
            ProjectFaultSeverity severity = ProjectFaultSeverity.Recoverable)
        {
            Requires.NotNull(faultHandlerService, nameof(faultHandlerService));
            Requires.NotNull(block, nameof(block));

            return(block.Completion.ContinueWith(_ =>
            {
                var dataSourceException = new AggregateException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.DataFlowFaults,
                        block.ToString(),
                        block.Completion.Exception),
                    block.Completion.Exception);

                try
                {
                    throw dataSourceException;
                }
                catch (AggregateException ex)
                {
                    dataSourceException = ex;
                }

                return faultHandlerService.ReportFaultAsync(dataSourceException, project, severity);
            },
                                                 CancellationToken.None,
                                                 TaskContinuationOptions.OnlyOnFaulted,
                                                 TaskScheduler.Default));
        }