Ejemplo n.º 1
0
        private void modifyFilterByUserRights(FilterExpression fExp)
        {
            if (Provider.CurrentMember.SuperUser)
            {
                return;
            }

            if (T == typeof(Entity.ApiRelated.Api))
            {
                fExp = fExp.And("Id", CriteriaTypes.Eq, Provider.CurrentApi.Id);
            }
            else if (T == typeof(Product))
            {
                fExp = fExp.And("ApiId", CriteriaTypes.Eq, Provider.CurrentApi.Id);
            }
            else if (T == typeof(NewsletterDefinition))
            {
                fExp = fExp.And("ApiId", CriteriaTypes.Eq, Provider.CurrentApi.Id);
            }
            //else if (T == typeof(Right))
            //    fExp = fExp.And("ApiId", CriteriaTypes.Eq, Provider.CurrentApi.Id);
            //else if (T == typeof(Role))
            //    fExp = fExp.And("ApiId", CriteriaTypes.Eq, Provider.CurrentApi.Id);
            else if (T == typeof(ApiClient))
            {
                fExp = fExp.And("ApiId", CriteriaTypes.Eq, Provider.CurrentApi.Id);
            }
            else if (T == typeof(Member))
            {
                fExp = fExp.And("StaffMemberId", CriteriaTypes.Eq, Provider.CurrentMember.Id);
            }
        }
Ejemplo n.º 2
0
 public void AddAndFilter(Expression <Func <T, bool> > filter)
 {
     if (FilterExpression == null)
     {
         FilterExpression = filter;
     }
     else
     {
         FilterExpression = FilterExpression.And(filter);
     }
 }
Ejemplo n.º 3
0
        private void CreateLavaDocumentParsers()
        {
            // Define the top-level parsers.
            var anyTags   = CreateKnownTagsParser(throwOnUnknownTag: false);
            var knownTags = CreateKnownTagsParser(throwOnUnknownTag: true);

            var outputElement = OutputStart.SkipAnd(FilterExpression.And(OutputEnd.ElseError(ErrorMessages.ExpectedOutputEnd))
                                                    .Then <Statement>(x => new OutputStatement(x.Item1)));

            var textElement = AnyCharBefore(OutputStart.Or(LavaTagParsers.LavaTagStart().AsFluidTagResultParser()).Or(LavaTagParsers.LavaShortcodeStart().AsFluidTagResultParser()))
                              .Then <Statement>((ctx, x) =>
            {
                // Keep track of each text span such that whitespace trimming can be applied
                var p = ( FluidParseContext )ctx;

                var result = new TextSpanStatement(x);

                p.PreviousTextSpanStatement = result;

                if (p.StripNextTextSpanStatement)
                {
                    result.StripLeft             = true;
                    p.StripNextTextSpanStatement = false;
                }

                result.PreviousIsTag    = p.PreviousIsTag;
                result.PreviousIsOutput = p.PreviousIsOutput;

                return(result);
            });

            // Define parsers for Lava block/inline comments.
            var blockCommentElement = Terms.Text("/-").SkipAnd(AnyCharBefore(Terms.Text("-/")));
            var lineCommentElement  = Terms.Text("/-").SkipAnd(AnyCharBefore(Terms.Char('\r').SkipAnd(Terms.Char('\n'))));

            var commentElement = blockCommentElement.Or(lineCommentElement);

            // Set the parser to be used for a block element.
            // This parser returns an empty result when an unknown tag is found.
            _anyTagsListParser = ZeroOrMany(outputElement.Or(anyTags).Or(textElement));

            // Set the parser to be used for the entire template.
            // This parser raises an exception when an unknown tag is found.
            _knownTagsListParser = ZeroOrMany(outputElement.Or(knownTags).Or(textElement));
        }
Ejemplo n.º 4
0
        public void UsageRequestMatchesExample()
        {
            var example = @"{
  ""type"": ""Usage"",
  ""timeframe"": ""MonthToDate"",
  ""dataset"": {
    ""granularity"": ""Daily"",
    ""aggregation"": {},
    ""grouping"": [],
    ""filter"": {
      ""and"": [
        {
          ""or"": [
            {
              ""dimension"": {
                ""name"": ""ResourceLocation"",
                ""operator"": ""In"",
                ""values"": [
                  ""East US"",
                  ""West Europe""
                ]
              }
            },
            {
              ""tags"": {
                ""name"": ""Environment"",
                ""operator"": ""In"",
                ""values"": [
                  ""UAT"",
                  ""Prod""
                ]
              }
            }
          ]
        },
        {
          ""dimension"": {
            ""name"": ""ResourceGroup"",
            ""operator"": ""In"",
            ""values"": [
              ""API""
            ]
          }
        }
      ]
    }
  }
}";

            var request =
                new UsageRequest(
                    Timeframe.MonthToDate,
                    new Dataset(
                        Granularity.Daily,
                        new Dictionary <string, Aggregation>(),
                        new List <Grouping>(),
                        FilterExpression.And(
                            FilterExpression.Or(
                                FilterExpression.Dimension(
                                    "ResourceLocation",
                                    Operator.In,
                                    new[] { "East US", "West Europe" }),
                                FilterExpression.Tag(
                                    "Environment",
                                    Operator.In,
                                    new[] { "UAT", "Prod" })),
                            FilterExpression.Dimension(
                                "ResourceGroup",
                                Operator.In,
                                new[] { "API" }))));

            Assert.Equal(example, Serialize(request));
        }
Ejemplo n.º 5
0
 public void AndCondition(Expression <Func <T, bool> > expression)
 {
     FilterExpression = FilterExpression.And(expression);
 }