コード例 #1
0
        // IManagedHotReloadAgent

        public async ValueTask ApplyUpdatesAsync(ImmutableArray <ManagedHotReloadUpdate> updates, CancellationToken cancellationToken)
        {
            if (!_sessionActive)
            {
                WriteToOutputWindow($"ApplyUpdatesAsync called but the session is not active.");
                return;
            }

            if (_deltaApplier is null)
            {
                WriteToOutputWindow($"ApplyUpdatesAsync called but we have no delta applier.");
            }

            if (!_sessionActive || _deltaApplier is null)
            {
                return;
            }

            try
            {
                WriteToOutputWindow(VSResources.HotReloadSendingUpdates);

                ApplyResult result = await _deltaApplier.ApplyUpdatesAsync(updates, cancellationToken);

                if (result == ApplyResult.Success || result == ApplyResult.SuccessRefreshUI)
                {
                    WriteToOutputWindow(VSResources.HotReloadApplyUpdatesSuccessful);
                    if (_callback is not null)
                    {
                        await _callback.OnAfterChangesAppliedAsync(cancellationToken);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = $"{ex.GetType()}: {ex.Message}";

                WriteToOutputWindow(string.Format(VSResources.HotReloadApplyUpdatesFailure, message));
                throw;
            }
        }
コード例 #2
0
        // IManagedHotReloadAgent

        public async ValueTask ApplyUpdatesAsync(ImmutableArray <ManagedHotReloadUpdate> updates, CancellationToken cancellationToken)
        {
            if (!_sessionActive)
            {
                WriteToOutputWindow(
                    new HotReloadLogMessage(
                        HotReloadVerbosity.Detailed,
                        $"{nameof(ApplyUpdatesAsync)} called but the session is not active.",
                        Name,
                        _variant
                        ),
                    default);
                return;
            }

            if (_deltaApplier is null)
            {
                WriteToOutputWindow(
                    new HotReloadLogMessage(
                        HotReloadVerbosity.Detailed,
                        $"{nameof(ApplyUpdatesAsync)} called but we have no delta applier.",
                        Name,
                        _variant
                        ),
                    default);
            }

            if (!_sessionActive || _deltaApplier is null)
            {
                return;
            }

            try
            {
                WriteToOutputWindow(
                    new HotReloadLogMessage(
                        HotReloadVerbosity.Detailed,
                        VSResources.HotReloadSendingUpdates,
                        Name,
                        _variant
                        ),
                    cancellationToken);

                ApplyResult result = await _deltaApplier.ApplyUpdatesAsync(updates, cancellationToken);

                if (result == ApplyResult.Success || result == ApplyResult.SuccessRefreshUI)
                {
                    WriteToOutputWindow(
                        new HotReloadLogMessage(
                            HotReloadVerbosity.Detailed,
                            VSResources.HotReloadApplyUpdatesSuccessful,
                            Name,
                            _variant
                            ),
                        cancellationToken);
                    if (_callback is not null)
                    {
                        await _callback.OnAfterChangesAppliedAsync(cancellationToken);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = $"{ex.GetType()}: {ex.Message}";

                WriteToOutputWindow(
                    new HotReloadLogMessage(
                        HotReloadVerbosity.Minimal,
                        string.Format(VSResources.HotReloadApplyUpdatesFailure, message),
                        Name,
                        _variant,
                        errorLevel: HotReloadDiagnosticErrorLevel.Error
                        ),
                    cancellationToken);
                throw;
            }
        }