public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var diagnostic     = context.Diagnostics.First();
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var expression = root.FindNode(diagnosticSpan, false, true);

            if (!TryGetInvocationExpression(expression, out SyntaxNode invocationExpression))
            {
                return;
            }

            SemanticModel semanticModel = await context.Document.GetSemanticModelAsync();

            var durableVersion = SyntaxNodeUtils.GetDurableVersion(semanticModel);

            if (SyntaxNodeUtils.IsInsideOrchestrator(invocationExpression) && durableVersion.Equals(DurableVersion.V2))
            {
                if (CodeFixProviderUtils.TryGetDurableOrchestrationContextVariableName(invocationExpression, out string variableName))
                {
                    var newExpression = "";
                    if (TryGetMillisecondsParameter(invocationExpression, out string milliseconds))
                    {
                        if (TryGetCancellationTokenParameter(invocationExpression, semanticModel, out string cancellationToken))
                        {
                            newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.AddMilliseconds(" + milliseconds + "), " + cancellationToken + ")";
                        }
                        else
                        {
                            newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.AddMilliseconds(" + milliseconds + "), CancellationToken.None)";
                        }
                    }
                    else if (TryGetTimespanParameter(invocationExpression, semanticModel, out string timeSpan))
                    {
                        if (TryGetCancellationTokenParameter(invocationExpression, semanticModel, out string cancellationToken))
                        {
                            newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.Add(" + timeSpan + "), " + cancellationToken + ")";
                        }
                        else
                        {
                            newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.Add(" + timeSpan + "), CancellationToken.None)";
                        }
                    }

                    context.RegisterCodeFix(
                        CodeAction.Create(FixTimerInOrchestrator.ToString(), c => ReplaceWithAwaitExpressionAsync(context.Document, expression, c, newExpression), nameof(TimerCodeFixProvider)),
                        diagnostic);
                }
            }
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var diagnostic     = context.Diagnostics.First();
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var expression = root.FindNode(diagnosticSpan);

            if (SyntaxNodeUtils.IsInsideOrchestrationTrigger(expression))
            {
                if (CodeFixProviderUtils.TryGetDurableOrchestrationContextVariableName(expression, out string variableName))
                {
                    context.RegisterCodeFix(
                        CodeAction.Create(FixDateTimeInOrchestrator.ToString(), c => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, expression, c, variableName + ".CurrentUtcDateTime"), nameof(DateTimeCodeFixProvider)), diagnostic);
                }
            }
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var diagnostic     = context.Diagnostics.First();
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var expression = root.FindNode(diagnosticSpan) as InvocationExpressionSyntax;

            if (expression == null)
            {
                return;
            }

            if (SyntaxNodeUtils.IsInsideOrchestrator(expression))
            {
                if (CodeFixProviderUtils.TryGetDurableOrchestrationContextVariableName(expression, out string variableName))
                {
                    context.RegisterCodeFix(
                        CodeAction.Create(FixGuidInOrchestrator.ToString(), c => ReplaceWithInvocationExpressionAsync(context.Document, expression, c, variableName + ".NewGuid()"), nameof(GuidCodeFixProvider)),
                        diagnostic);
                }
            }
        }
예제 #4
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var diagnostic     = context.Diagnostics.First();
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var identifierNode = root.FindNode(diagnosticSpan);

            context.RegisterCodeFix(
                CodeAction.Create(FixIDurableEntityContext.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, "IDurableEntityContext"), nameof(EntityContextCodeFixProvider)),
                diagnostic);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var diagnostic     = context.Diagnostics.First();
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var identifierNode = root.FindNode(diagnosticSpan);

            SemanticModel semanticModel = await context.Document.GetSemanticModelAsync();

            var durableVersion = SyntaxNodeUtils.GetDurableVersion(semanticModel);

            if (durableVersion.Equals(DurableVersion.V1))
            {
                context.RegisterCodeFix(
                    CodeAction.Create(FixDurableOrchestrationClient.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, "DurableOrchestrationClient"), nameof(ClientCodeFixProvider) + nameof(FixDurableOrchestrationClient)),
                    diagnostic);
            }
            else if (durableVersion.Equals(DurableVersion.V2))
            {
                context.RegisterCodeFix(
                    CodeAction.Create(FixIDurableClient.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, "IDurableClient"), nameof(ClientCodeFixProvider) + nameof(FixIDurableClient)),
                    diagnostic);

                context.RegisterCodeFix(
                    CodeAction.Create(FixIDurableEntityClient.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, "IDurableEntityClient"), nameof(ClientCodeFixProvider) + nameof(FixIDurableEntityClient)),
                    diagnostic);

                context.RegisterCodeFix(
                    CodeAction.Create(FixIDurableOrchestrationClient.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, "IDurableOrchestrationClient"), nameof(ClientCodeFixProvider) + nameof(FixIDurableOrchestrationClient)),
                    diagnostic);
            }
        }
예제 #6
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var diagnostic     = context.Diagnostics.First();
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var           identifierNode = root.FindNode(diagnosticSpan);
            SemanticModel semanticModel  = await context.Document.GetSemanticModelAsync();

            if (SyntaxNodeUtils.TryGetFunctionName(semanticModel, identifierNode, out string functionName))
            {
                context.RegisterCodeFix(
                    CodeAction.Create(FixDispatchEntityCall.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, functionName), nameof(DispatchEntityNameCodeFixProvider)),
                    diagnostic);
            }
        }