Ejemplo n.º 1
0
            public void OnNext(T value)
            {
                var expression = Expression.Invoke(Expression.Parameter(typeof(Action <IQbserver <T>, T>), "rx://builtin/onNext"), Expression, Expression.Constant(value, typeof(T)));
                var normalized = ExpressionService.Normalize(expression);

                Provider.Service.Evaluate(normalized);
            }
Ejemplo n.º 2
0
            public void Dispose()
            {
                var expression = Expression.Invoke(Expression.Parameter(typeof(Action <IQubscription>), "rx://builtin/dispose"), Expression);
                var normalized = ExpressionService.Normalize(expression);

                Provider.Service.Evaluate(normalized);
            }
Ejemplo n.º 3
0
        public void SaveFormulasWithTreeGridFormat(string groupId, string json)
        {
            Guid      id = new Guid(groupId);
            DataTable dt = TreeGridJsonParser.JsonToDataTable(json.ToString());

            ExpressionService.SaveFormulas(id, dt);
        }
Ejemplo n.º 4
0
        public IBindToExpression <T> Property <T>(
            Expression <Func <TDescriptor, IVMPropertyDescriptor <T> > > sourcePropertySelector
            )
        {
            string path = ExpressionService.GetPropertyPathString(sourcePropertySelector);

            BinderContext context = QueueBuilderExecution();

            context.ExtendPropertyPath(path);
            context.SourcePropertyType = typeof(T);

            // HACK ATTACK: My collegas needed a quick fix!!!!
            if (typeof(T) == typeof(ICommand))
            {
                context.Binding.FallbackValue   = DelegateCommand.AlwaysDisabled;
                context.Binding.TargetNullValue = DelegateCommand.AlwaysDisabled;
            }

            // TODO: Always necessary? Is there a better place?
            Binding binding = context.Binding as Binding;

            if (binding != null)
            {
                binding.ValidatesOnDataErrors = true;
            }

            return(new PropertyBinderExpression <T>(context));
        }
Ejemplo n.º 5
0
        public void BindVM <TDescriptor>(Expression <Func <TScreen, IViewModelExpression <TDescriptor> > > viewModelSelector, Action <IVMBinder <TDescriptor> > bindingConfigurator) where TDescriptor : VMDescriptor
        {
            string pathPrefix = ExpressionService.GetPropertyPathString(viewModelSelector);
            VMPropertyBinder <TDescriptor> binder = new VMPropertyBinder <TDescriptor>(pathPrefix);

            bindingConfigurator(binder);
            binder.Execute();
        }
Ejemplo n.º 6
0
            public IQubject <T> Create(string id)
            {
                var expression = Expression.Invoke(Expression.Parameter(typeof(Func <IQubjectFactory <T>, string, IQubject <T> >), "rx://builtin/createSubject"), Expression, Expression.Constant(id, typeof(string)));
                var normalized = ExpressionService.Normalize(expression);

                Provider.Service.Evaluate(normalized);
                return(new SubjectProxy <T>(Expression.Parameter(typeof(IQubject <T>), id), Provider));
            }
Ejemplo n.º 7
0
            public IQubscription Subscribe(string id, IQbserver <T> observer)
            {
                var expression = Expression.Invoke(Expression.Parameter(typeof(Func <IQbservable <T>, string, IQbserver <T>, IQubscription>), "rx://builtin/subscribe"), Expression, Expression.Constant(id, typeof(string)), observer.Expression);
                var normalized = ExpressionService.Normalize(expression);

                Provider.Service.Evaluate(normalized);
                return(Provider.CreateSubscription(Expression.Parameter(typeof(IQubscription), id)));
            }
Ejemplo n.º 8
0
        public void These_are_valid_expressions(string expression, string[] parameterNames, object[] values, object expected)
        {
            ExpressionService service = new ExpressionService();

            Type[] types  = values?.Select(v => v.GetType()).ToArray() ?? new Type[0];
            object actual = service.Evaluate(expression, parameterNames, values, types);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 9
0
        public void Compare_constants_versus_native(ExpressionFeatures features, int trials)
        {
            ExpressionService service = new ExpressionService(features);

            // Constants:
            CompareTests("Constants",
                         features.ToString(), () => service.Evaluate("100", null, null, null),
                         "Native", () => ConstantNative(),
                         trials, service, 100);
        }
Ejemplo n.º 10
0
 public ActionResult <ExpressionStructureDto> EvaluateExpression(string expression)
 {
     try
     {
         return(Ok(ExpressionService.EvaluateExpression(expression)));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 11
0
        public IBindToExpression <IViewModel> BindVM(Expression <Func <TScreen, IViewModel> > viewModelSelector)
        {
            BinderContext context = QueueBuilderExecution();

            context.SourcePropertyType = typeof(IViewModel); // TODO: Clean up how types are assigned, also check if IBindToExpression has to be generic...
            context.ExtendPropertyPath(
                ExpressionService.GetPropertyPathString(viewModelSelector)
                );

            return(new PropertyBinderExpression <IViewModel>(context));
        }
Ejemplo n.º 12
0
        public IBindCollectionExpression <TItemDescriptor> CollectionManual <TItemDescriptor>(
            Expression <Func <TDescriptor, IVMPropertyDescriptor <object> > > collectionPropertySelector
            ) where TItemDescriptor : VMDescriptor
        {
            string path = ExpressionService.GetPropertyPathString(collectionPropertySelector);

            BinderContext context = QueueBuilderExecution();

            context.ExtendPropertyPath(path);

            return(new VMCollectionBinder <TItemDescriptor>(context));
        }
Ejemplo n.º 13
0
 public string ValidateExpression(string expression)
 {
     string[] result = ExpressionService.ValidateExpression(expression);
     if (result.Length == 0)
     {
         return("success");
     }
     else
     {
         return(result[0]);
     }
 }
        public void GetPropertyName_WorksWithPropertiesWithDerivedTypes()
        {
            Expression <Func <Person, object> > exp = x => x.BirthDate;

            var path = ExpressionService.GetProperties(exp);

            Assert.AreEqual("BirthDate", ToString(path));

            exp = x => x.Department.Name;

            path = ExpressionService.GetProperties(exp);
            Assert.AreEqual("Department.Name", ToString(path));
        }
Ejemplo n.º 15
0
        [InlineData("100 + a + b + c", new[] { "a", "b", "c" }, new object[] { 50, 5.5, 0.1 }, 155.6)]  // 100 + a + b + c => 155.6
        public void These_are_valid_expressions(string expression, string[] parameterNames, object[] values, object expected)
        {
            var trace = new TraceSource(nameof(ExpressionService));

            trace.Switch.Level = SourceLevels.All;
            trace.Listeners.Add(new XunitTraceListener(_output));

            using (ExpressionService service = new ExpressionService(ExpressionFeatures.None, trace))
            {
                Type[] types  = values?.Select(v => v.GetType()).ToArray() ?? Type.EmptyTypes;
                object actual = service.Evaluate(expression, parameterNames, types, values);
                Assert.Equal(expected, actual);
            }
        }
Ejemplo n.º 16
0
        public string GetFormulaName(string groupId)
        {
            Guid id = new Guid(groupId);

            DataTable dt = ExpressionService.GetFormulaGroupInfoByGroupId(id);

            if (dt.Rows.Count > 0)
            {
                return("{\"name\":\"" + dt.Rows[0]["Name"].ToString() + "\"}");
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            Console.WriteLine("This program counts the number of found words or expressions in comments from a file C# (*.cs).");

            ILoadService loadService = new LoadService();

            while (true)
            {
                Console.WriteLine("Press any key to select file and count.");
                Console.ReadKey();

                var resultLoad = loadService.LoadFile();
                if (resultLoad.Result)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter a word or expression");
                    string searchWord = Console.ReadLine();

                    var expressionService = new ExpressionService();

                    Console.WriteLine(new string ('-', 50));
                    var resultCount = expressionService.CountNumberExpressionsAsync(searchWord, resultLoad.Data).Result;
                    if (resultCount.Result)
                    {
                        Console.WriteLine($"{resultCount.Message} {resultCount.Data}.");
                    }
                    else
                    {
                        Console.WriteLine(resultCount.Message);
                    }
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(resultLoad.Message);
                }

                Console.WriteLine(new string('-', 50));
                Console.WriteLine("Press key 'E' to exit or any key to continue.");
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.E)
                {
                    break;
                }
                Console.Clear();
            }
        }
        public void GetPropertyName()
        {
            string name = ExpressionService.GetPropertyName <Person, DateTime>(p => p.BirthDate);

            Assert.AreEqual("BirthDate", name);

            name = ExpressionService.GetPropertyName <Person, Department>(p => p.Department);
            Assert.AreEqual("Department", name);

            AssertHelper.Throws <ArgumentException>(() =>
                                                    ExpressionService.GetPropertyName <Person, string>(p => p.Department.Name)
                                                    ).Containing("more");

            AssertHelper.Throws <ArgumentException>(() =>
                                                    ExpressionService.GetPropertyName <Person, Person>(p => p)
                                                    ).Containing("single");
        }
        public void GetProperties()
        {
            PropertyInfo[] path = ExpressionService.GetProperties <Person, DateTime>(p => p.BirthDate);
            Assert.AreEqual(1, path.Length);
            Assert.AreEqual("BirthDate", path[0].Name);

            path = ExpressionService.GetProperties <Person, string>(p => p.Department.Name);
            Assert.AreEqual(2, path.Length);
            Assert.AreEqual("Department", path[0].Name);
            Assert.AreEqual("Name", path[1].Name);

            path = ExpressionService.GetProperties <Person, Person>(p => p);
            Assert.AreEqual(0, path.Length);

            AssertHelper.Throws <ArgumentException>(() => {
                ExpressionService.GetProperties <Person, DateTime>(p => p.GetBirthDate().Date);
            });
        }
Ejemplo n.º 20
0
        public string GetFormulasWithTreeGridFormat(string groupId)
        {
            Guid       id             = new Guid(groupId);
            DataTable  formulas       = ExpressionService.GetFormulasByGroupId(id);
            DataColumn parentIdColumn = new DataColumn("ParentID");

            formulas.Columns.Add(parentIdColumn);

            foreach (DataRow row in formulas.Rows)
            {
                string levelcode = row["LevelCode"].ToString().Trim();
                if (levelcode.Length > 3)
                {
                    row["ParentID"] = levelcode.Substring(0, levelcode.Length - 2);
                }
            }

            return(TreeGridJsonParser.DataTableToJson(formulas, "LevelCode", "ParentID", "Name", "Formula"));
        }
Ejemplo n.º 21
0
        public void VM <TChildDescriptor>(
            Expression <Func <TDescriptor, IVMPropertyDescriptor <IViewModelExpression <TChildDescriptor> > > > viewModelPropertySelector,
            Action <IVMBinder <TChildDescriptor> > viewModelBinder
            ) where TChildDescriptor : VMDescriptor
        {
            string path;

            // HACK: just a quick fix
            if (String.IsNullOrEmpty(_pathPrefix))
            {
                path = ExpressionService.GetPropertyPathString(viewModelPropertySelector);
            }
            else
            {
                path = String.Join(".", _pathPrefix, ExpressionService.GetPropertyPathString(viewModelPropertySelector));
            }
            var binder = new VMPropertyBinder <TChildDescriptor>(pathPrefix: path);

            viewModelBinder(binder);
            binder.Execute();
        }
Ejemplo n.º 22
0
 public Expression Add(int x, int y)
 {
     return(ExpressionService.Add(x, y));
 }
Ejemplo n.º 23
0
        private void CompareTests(string task, string usLabel, Func <object> us, string themLabel, Func <object> them, int trials, ExpressionService service, object result)
        {
            GC.Collect();
            them();
            us();

            Stopwatch sw = Stopwatch.StartNew();

            bool doWork = false;

            GC.Collect();
            sw.Restart();
            for (var i = 0; i < trials; i++)
            {
                doWork = us() == result;
            }
            if (doWork)
            {
                throw new Exception("test is not valid");
            }
            double usTime = sw.Elapsed.TotalMilliseconds;

            GC.Collect();
            sw.Restart();
            for (var i = 0; i < trials; i++)
            {
                doWork = them() == result;
            }
            if (doWork)
            {
                throw new Exception("test is not valid");
            }
            double themTime = sw.Elapsed.TotalMilliseconds;

            _output.WriteLine($"{task}: ({usLabel}) @ {trials}x: {usTime}ms, {usTime/themTime:P2}");
            _output.WriteLine($"{task}: ({themLabel}) @ {trials}x: {themTime}ms");
        }
Ejemplo n.º 24
0
 public Expression Sub(int x, int y)
 {
     return(ExpressionService.Subtract(x, y));
 }
Ejemplo n.º 25
0
 public Expression Divide(int x, int y)
 {
     return(ExpressionService.Divide(x: x, y: y));
 }
        public void GetPropertyNameParameterless_StaticFieldInExternalClass_Succeeds()
        {
            var name = ExpressionService.GetPropertyName(() => Person.DefaultDepartment);

            Assert.AreEqual("DefaultDepartment", name);
        }
Ejemplo n.º 27
0
 public Expression Multiply(int x, int y)
 {
     return(ExpressionService.Multiply(x, y));
 }
        public void GetPropertyNameParameterless()
        {
            string name = ExpressionService.GetPropertyName(() => BirthDate);

            Assert.AreEqual("BirthDate", name);
        }
Ejemplo n.º 29
0
 public Expression Get(long id)
 {
     return(ExpressionService.GetById(id));
 }
        public void GetPropertyNameParameterless_StaticFieldInCallingClass_Succeeds()
        {
            var name = ExpressionService.GetPropertyName(() => StaticField);

            Assert.AreEqual("StaticField", name);
        }