public void Handle()

in src/Core/Compiling/Policy/QuotaByKeyCompiler.cs [18:70]


    public void Handle(ICompilationContext context, InvocationExpressionSyntax node)
    {
        if (!node.TryExtractingConfigParameter<QuotaByKeyConfig>(context, "quota-by-key",
                out IReadOnlyDictionary<string, InitializerValue>? values))
        {
            return;
        }

        XElement element = new("quota-by-key");

        if (!element.AddAttribute(values, nameof(QuotaByKeyConfig.CounterKey), "counter-key"))
        {
            context.Report(Diagnostic.Create(
                CompilationErrors.RequiredParameterNotDefined,
                node.GetLocation(),
                "quota-by-key",
                nameof(QuotaByKeyConfig.CounterKey)
            ));
            return;
        }

        bool isCallsAdded = element.AddAttribute(values, nameof(QuotaByKeyConfig.Calls), "calls");
        bool isBandwidthAdded = element.AddAttribute(values, nameof(QuotaByKeyConfig.Bandwidth), "bandwidth");

        if (!isCallsAdded && !isBandwidthAdded)
        {
            context.Report(Diagnostic.Create(
                CompilationErrors.AtLeastOneOfTwoShouldBeDefined,
                node.GetLocation(),
                "quota-by-key",
                nameof(QuotaByKeyConfig.Calls),
                nameof(QuotaByKeyConfig.Bandwidth)
            ));
            return;
        }

        if (!element.AddAttribute(values, nameof(QuotaByKeyConfig.RenewalPeriod), "renewal-period"))
        {
            context.Report(Diagnostic.Create(
                CompilationErrors.RequiredParameterNotDefined,
                node.GetLocation(),
                "quota-by-key",
                nameof(QuotaByKeyConfig.RenewalPeriod)
            ));
            return;
        }

        element.AddAttribute(values, nameof(QuotaByKeyConfig.IncrementCondition), "increment-condition");
        element.AddAttribute(values, nameof(QuotaByKeyConfig.IncrementCount), "increment-count");
        element.AddAttribute(values, nameof(QuotaByKeyConfig.FirstPeriodStart), "first-period-start");

        context.AddPolicy(element);
    }