22using System . Collections . Generic ;
33using System . Linq ;
44using System . Text ;
5- using JsonLogic . Net ;
5+ using System . Text . Json ;
6+ using System . Text . Json . Nodes ;
7+ using Json . Logic ;
68using Murmur ;
7- using Newtonsoft . Json . Linq ;
8- using Semver ;
99
1010namespace OpenFeature . Contrib . Providers . Flagd . Resolver . InProcess . CustomEvaluators
1111{
1212 /// <inheritdoc/>
13- public class FractionalEvaluator
13+ public class FractionalEvaluator : IRule
1414 {
1515 internal FractionalEvaluator ( )
1616 {
@@ -22,27 +22,27 @@ class FractionalEvaluationDistribution
2222 public int weight ;
2323 }
2424
25- internal object Evaluate ( IProcessJsonLogic p , JToken [ ] args , object data )
25+ public JsonNode Apply ( JsonNode args , EvaluationContext context )
2626 {
2727 // check if we have at least two arguments:
2828 // 1. the property value
2929 // 2. the array containing the buckets
3030
31- if ( args . Length == 0 )
31+ if ( args . AsArray ( ) . Count == 0 )
3232 {
3333 return null ;
3434 }
3535
36- var flagdProperties = new FlagdProperties ( data ) ;
36+ var flagdProperties = new FlagdProperties ( context ) ;
3737
3838 var bucketStartIndex = 0 ;
3939
40- var arg0 = p . Apply ( args [ 0 ] , data ) ;
40+ var arg0 = JsonLogic . Apply ( args [ 0 ] , context ) ;
4141
4242 string propertyValue ;
43- if ( arg0 is string stringValue )
43+ if ( arg0 . GetValueKind ( ) == JsonValueKind . String )
4444 {
45- propertyValue = stringValue ;
45+ propertyValue = arg0 . ToString ( ) ;
4646 bucketStartIndex = 1 ;
4747 }
4848 else
@@ -53,16 +53,16 @@ internal object Evaluate(IProcessJsonLogic p, JToken[] args, object data)
5353 var distributions = new List < FractionalEvaluationDistribution > ( ) ;
5454 var distributionSum = 0 ;
5555
56- for ( var i = bucketStartIndex ; i < args . Length ; i ++ )
56+ for ( var i = bucketStartIndex ; i < args . AsArray ( ) . Count ; i ++ )
5757 {
58- var bucket = p . Apply ( args [ i ] , data ) ;
58+ var bucket = JsonLogic . Apply ( args [ i ] , context ) ;
5959
60- if ( ! bucket . IsEnumerable ( ) )
60+ if ( ! ( bucket . GetValueKind ( ) == JsonValueKind . Array ) )
6161 {
6262 continue ;
6363 }
6464
65- var bucketArr = bucket . MakeEnumerable ( ) . ToArray ( ) ;
65+ var bucketArr = bucket . AsArray ( ) ;
6666
6767 if ( ! bucketArr . Any ( ) )
6868 {
@@ -71,9 +71,9 @@ internal object Evaluate(IProcessJsonLogic p, JToken[] args, object data)
7171
7272 var weight = 1 ;
7373
74- if ( bucketArr . Length >= 2 && bucketArr . ElementAt ( 1 ) . IsNumeric ( ) )
74+ if ( bucketArr . Count >= 2 && bucketArr . ElementAt ( 1 ) . GetValueKind ( ) == JsonValueKind . Number )
7575 {
76- weight = Convert . ToInt32 ( bucketArr . ElementAt ( 1 ) ) ;
76+ weight = bucketArr . ElementAt ( 1 ) . GetValue < int > ( ) ;
7777 }
7878
7979 distributions . Add ( new FractionalEvaluationDistribution
0 commit comments