コード例 #1
0
ファイル: LogicalExpression.cs プロジェクト: BlackGad/PS
        public virtual void ReadXml(XmlReader reader)
        {
            var @operator = ExpressionSerialization.ReadExpressionOperator(reader);

            if (@operator != null)
            {
                Operator = (LogicalOperator)Enum.Parse(typeof(LogicalOperator), @operator, true);
            }

            var result = new List <IExpression>();

            using (var subTree = reader.ReadSubtree())
            {
                //Skip root node
                subTree.MoveToContent();
                subTree.Read();

                while (subTree.IsStartElement())
                {
                    result.Add(ExpressionSerialization.ReadNode(subTree));
                    subTree.Read();
                }
            }

            reader.Skip();
            Expressions = result.ToArray();
        }
コード例 #2
0
ファイル: RouteExpression.cs プロジェクト: BlackGad/PS
 public virtual void WriteXml(XmlWriter writer)
 {
     ExpressionSerialization.WriteExpressionRoute(writer, Route);
     if (Operator != null)
     {
         ExpressionSerialization.WriteOperatorExpression(writer, Operator);
     }
 }
コード例 #3
0
ファイル: LogicalExpression.cs プロジェクト: BlackGad/PS
 public virtual void WriteXml(XmlWriter writer)
 {
     ExpressionSerialization.WriteExpressionOperator(writer, Operator.ToString());
     foreach (var expression in Expressions)
     {
         ExpressionSerialization.WriteNode(writer, expression);
     }
 }
コード例 #4
0
 public override void WriteXml(XmlWriter writer)
 {
     base.WriteXml(writer);
     ExpressionSerialization.WriteSubsetExpressionQuery(writer, Query);
     if (Subset != null)
     {
         ExpressionSerialization.WriteNode(writer, Subset);
     }
 }
コード例 #5
0
        public void TestThatParameterlessExpressionInvokes()
        {
            Expression <Action <IParameterlessInterface> > expression = a => a.DoSomething();
            var serialized = ExpressionSerialization.Serialize(expression);

            var actor             = new ActorTest();
            var serializationInfo = ExpressionSerialization.Deserialize <IParameterlessInterface>(serialized);
            var consumer          = ExpressionExtensions.CreateDelegate <IParameterlessInterface>(actor, serializationInfo);

            consumer(actor);
            Assert.True(actor.WasRun);
        }
コード例 #6
0
        async Task <T> ExecuteImplAsync <T>(LambdaExpression expr)
        {
            var requestJson = ExpressionSerialization.Serialize(expr);

            var webClient = new WebClient();

            webClient.Headers.Add("Content-Type", "application/json");
            var resultJson = await webClient.UploadStringTaskAsync(url, requestJson);

            var result = JsonConvert.DeserializeObject <T>(resultJson);

            return(result);
        }
コード例 #7
0
        public void TestThatSimpleParameterExpressionInvokes()
        {
            var message = "hello";
            var i       = 10;
            Expression <Action <ISimpleParametersInterface> > expression = a => a.DoSomething(message, i);
            var serialized = ExpressionSerialization.Serialize(expression);

            var actor             = new ActorTest();
            var serializationInfo = ExpressionSerialization.Deserialize <ISimpleParametersInterface>(serialized);
            var consumer          = ExpressionExtensions.CreateDelegate <ISimpleParametersInterface>(actor, serializationInfo);

            consumer(actor);
            Assert.Equal(i, actor.Count);
            Assert.Equal(message, actor.Message);
        }
コード例 #8
0
        public void TestThatSimpleExpressionInvokes()
        {
            var actor = new ActorTest();
            var m     = "Test";
            Expression <Action <int> > expression = i => actor.DoSomething(m, i);
            var serialized = ExpressionSerialization.Serialize(expression);

            var serializationInfo = ExpressionSerialization.Deserialize(serialized);
            var consumer          = ExpressionExtensions.CreateDelegate <IParameterlessInterface, int>(actor, serializationInfo);

            consumer(actor, 100);

            Assert.Equal(100, actor.Count);
            Assert.Equal(m, actor.Message);
        }
コード例 #9
0
        public override void ReadXml(XmlReader reader)
        {
            base.ReadXml(reader);
            Query = ExpressionSerialization.ReadSubsetExpressionQuery(reader);

            using (var subTree = reader.ReadSubtree())
            {
                //Skip root node
                subTree.MoveToContent();
                subTree.Read();

                if (subTree.IsStartElement())
                {
                    Subset = ExpressionSerialization.ReadNode(subTree);
                }
            }
        }
コード例 #10
0
        public void TestThatComplexParameterExpressionInvokes()
        {
            var i = 10;
            var complexParameters = new ComplexParameters
            {
                Int             = 1,
                Message         = "Hello",
                InnerParameters = new ComplexParameters
                {
                    Int     = 2,
                    Message = "World"
                }
            };
            Expression <Action <IComplexParameterInterface> > expression = a => a.DoSomething(i, complexParameters);
            var serialized = ExpressionSerialization.Serialize(expression);

            var actor             = new ActorTest();
            var serializationInfo = ExpressionSerialization.Deserialize <IComplexParameterInterface>(serialized);
            var consumer          = ExpressionExtensions.CreateDelegate <IComplexParameterInterface>(actor, serializationInfo);

            consumer(actor);
            Assert.Equal(i, actor.Count);
            Assert.Equal(complexParameters, actor.Parameters);
        }
コード例 #11
0
        public async Task <String> Execute()
        {
            using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                var requestJson = await reader.ReadToEndAsync();

                System.Diagnostics.Debug.WriteLine($"Executing request sized {requestJson.Length}.");

                var expr = ExpressionSerialization.Deserialize(requestJson);

                var del = expr.Compile();

                var result = del.DynamicInvoke();

                if (result is Task taskResult)
                {
                    await taskResult;

                    result = result.GetType().GetProperty("Result").GetValue(result);
                }

                return(JsonConvert.SerializeObject(result));
            }
        }
コード例 #12
0
ファイル: RouteExpression.cs プロジェクト: BlackGad/PS
 public virtual void ReadXml(XmlReader reader)
 {
     Operator = ExpressionSerialization.ReadOperatorExpression(reader);
     Route    = ExpressionSerialization.ReadExpressionRoute(reader);
 }