Esempio n. 1
0
        public void ExpressionSearchIsTransmittedCorrectly()
        {
            //send the expression, then test it against the one received to make sure they're identical
            Expression <Func <Instrument, bool> > exp = x => x.Symbol == "SPY" && x.Type == InstrumentType.CFD && !x.IsContinuousFuture;

            var ms = new MemoryStream();
            EditableExpression editableExpr = EditableExpression.CreateEditableExpression(exp);
            XmlSerializer      xs           = new XmlSerializer(editableExpr.GetType());

            xs.Serialize(ms, editableExpr);

            Expression <Func <Instrument, bool> > receivedExpr = null;

            _instrumentSourceMock.Setup(x =>
                                        x.FindInstruments(It.IsAny <Expression <Func <Instrument, bool> > >(), It.IsAny <MyDBContext>()))
            .Callback <Expression <Func <Instrument, bool> >, MyDBContext>((x, y) => receivedExpr = x);

            _client.FindInstruments(exp);
            Thread.Sleep(100);

            Assert.IsNotNull(receivedExpr);

            var ms2 = new MemoryStream();
            EditableExpression receivedEditableExpr = EditableExpression.CreateEditableExpression(exp);

            xs.Serialize(ms2, receivedEditableExpr);

            Assert.AreEqual(Encoding.UTF8.GetString(ms.ToArray()), Encoding.UTF8.GetString(ms2.ToArray()));
        }
 public EditableConditionalExpression(ConditionalExpression condEx)
 {
     NodeType = condEx.NodeType;
     Test     = EditableExpression.CreateEditableExpression(condEx.Test);
     IfTrue   = EditableExpression.CreateEditableExpression(condEx.IfTrue);
     IfFalse  = EditableExpression.CreateEditableExpression(condEx.IfFalse);
 }
Esempio n. 3
0
        /// <summary>
        ///     Query the server for contracts using a predicate
        /// </summary>
        /// <param name="pred">Predicate to match instruments against</param>
        /// <returns>A list of instruments matching these features.</returns>
        public List <Instrument> FindInstruments(Expression <Func <Instrument, bool> > pred)
        {
            if (!Connected)
            {
                RaiseEvent(Error, this, new ErrorArgs(-1, "Could not request instruments - not connected."));
                return(new List <Instrument>());
            }

            using (var s = new RequestSocket(_instrumentServerConnectionString))
            {
                using (var ms = new MemoryStream())
                {
                    EditableExpression mutable = EditableExpression.CreateEditableExpression(pred);
                    XmlSerializer      xs      = new XmlSerializer(typeof(EditableExpression),
                                                                   new[] { typeof(MetaLinq.Expressions.EditableLambdaExpression) });
                    xs.Serialize(ms, mutable);

                    //Send the request
                    s.SendMoreFrame(MessageType.PredicateSearch);
                    s.SendFrame(ms.ToArray());
                }

                //And return the result
                return(ReceiveInstrumentSearchResults(s));
            }
        }
Esempio n. 4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EditableElementInit" /> class.
 /// </summary>
 /// <param name="elmInit">
 ///     The <see cref="ElementInit" /> .
 /// </param>
 public EditableElementInit(ElementInit elmInit) : this()
 {
     AddMethod = elmInit.AddMethod;
     foreach (Expression ex in elmInit.Arguments)
     {
         Arguments.Add(EditableExpression.CreateEditableExpression(ex));
     }
 }
 public EditableInvocationExpression(InvocationExpression invocEx)
     : this()
 {
     Expression = EditableExpression.CreateEditableExpression(invocEx.Expression);
     foreach (Expression ex in invocEx.Arguments)
     {
         Arguments.Add(EditableExpression.CreateEditableExpression(ex));
     }
 }
 public EditableListInitExpression(ListInitExpression listInit)
     : this()
 {
     NewExpression = EditableExpression.CreateEditableExpression(listInit.NewExpression);
     foreach (ElementInit e in listInit.Initializers)
     {
         Initializers.Add(new EditableElementInit(e));
     }
 }
 public EditableLambdaExpression(LambdaExpression lambEx)
     : base(lambEx.Type)
 {
     Parameters = new EditableExpressionCollection();
     Body       = EditableExpression.CreateEditableExpression(lambEx.Body);
     foreach (ParameterExpression param in lambEx.Parameters)
     {
         Parameters.Add(EditableExpression.CreateEditableExpression(param));
     }
 }
 public static string Serialize <T>(this Expression <T> expression)
 {
     using (var stream = new StringWriter())
     {
         EditableExpression mutable = EditableExpression.CreateEditableExpression(expression);
         XmlSerializer      xs      = new XmlSerializer(typeof(EditableExpression),
                                                        new[] { typeof(MetaLinq.Expressions.EditableLambdaExpression) });
         xs.Serialize(stream, mutable);
         return(stream.ToString());
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Create a new SerializableExpression.
        /// </summary>
        /// <param name="expression">Expression to serialize.</param>
        public SerializableFunc(Expression <Func <TOut> > expression)
        {
            var editableExpression = EditableExpression.CreateEditableExpression(expression);

            var ms         = new MemoryStream();
            var serializer = new XmlSerializer(editableExpression.GetType());

            serializer.Serialize(ms, editableExpression);
            ms.Flush();
            _xmlString = Encoding.UTF8.GetString(ms.ToArray());
            _type      = editableExpression.GetType();
        }
Esempio n. 10
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ConditionalTransition" /> class.
        /// </summary>
        /// <param name="fromState"> From state. </param>
        /// <param name="trueState"> From state. </param>
        /// <param name="falseState"> State of the true. </param>
        /// <param name="transitionExpression"> expression used to determine which branch to traverse. </param>
        public ConditionalTransition(IState fromState, IState trueState, IState falseState, Action <IExpressionEvaluator> transitionExpression)
        {
            To = new List <IState> ( );

            Expression = new StateTransitionExpression {
                Expression = EditableExpression.CreateEditableExpression(() => transitionExpression)
            };

            True  = trueState;
            False = falseState;
            From  = fromState;

            To.Add(trueState);
            To.Add(falseState);
        }
Esempio n. 11
0
 public EditableMemberInitExpression(NewExpression newRawEx, IEnumerable <MemberBinding> bindings)
     : this(EditableExpression.CreateEditableExpression(newRawEx) as EditableNewExpression, bindings)
 {
 }
Esempio n. 12
0
        private static void CheckSerialization <T1, T2, T3>(Expression <Func <T1, T2, T3> > lambda, T1 value1, T2 value2)
        {
            EditableExpression e = CheckSerializationInternal(EditableExpression.CreateEditableExpression(lambda));

            InvokeExpression <T1, T2>(e, value1, value2);
        }
Esempio n. 13
0
        private static void CheckSerialization <T>(Expression <Func <T> > lambda)
        {
            EditableExpression e = CheckSerializationInternal(EditableExpression.CreateEditableExpression(lambda));

            InvokeExpression(e);
        }
 public EditableTypeBinaryExpression(TypeBinaryExpression typeBinEx)
     : this(EditableExpression.CreateEditableExpression(typeBinEx.Expression), typeBinEx.TypeOperand)
 {
 }
Esempio n. 15
0
 public EditableBinaryExpression(BinaryExpression binex) : base(binex.Type)
 {
     Left     = EditableExpression.CreateEditableExpression(binex.Left);
     Right    = EditableExpression.CreateEditableExpression(binex.Right);
     NodeType = binex.NodeType;
 }
 public EditableMemberExpression(MemberExpression membEx)
     : this(EditableExpression.CreateEditableExpression(membEx.Expression), membEx.Member)
 {
 }
 public EditableUnaryExpression(UnaryExpression unEx)
     : this(unEx.NodeType, EditableExpression.CreateEditableExpression(unEx.Operand), unEx.Type)
 {
 }
Esempio n. 18
0
 public EditableMemberInitExpression(MemberInitExpression membInit)
     : this(EditableExpression.CreateEditableExpression(membInit.NewExpression) as EditableNewExpression, membInit.Bindings)
 {
 }
Esempio n. 19
0
 public EditableMethodCallExpression(IEnumerable <EditableExpression> arguments, MethodInfo method, Expression theObject, ExpressionType nodeType) :
     this(new EditableExpressionCollection(arguments), method, EditableExpression.CreateEditableExpression(theObject), nodeType)
 {
 }
Esempio n. 20
0
 public EditableMethodCallExpression(MethodCallExpression callEx) :
     this(new EditableExpressionCollection(callEx.Arguments), callEx.Method, EditableExpression.CreateEditableExpression(callEx.Object), callEx.NodeType)
 {
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="EditableMemberAssignment" /> class.
 /// </summary>
 /// <param name="member"> The member. </param>
 public EditableMemberAssignment(MemberAssignment member) : base(member.BindingType, member.Member)
 {
     Expression = EditableExpression.CreateEditableExpression(member.Expression);
 }
 public EditableMemberExpression(Expression rawEx, MemberInfo member)
     : this(EditableExpression.CreateEditableExpression(rawEx), member)
 {
 }