Exemple #1
0
        public static ExpressionDefinition TakeWhile()
        {
            Expression <Func <IObservable <string>, IObservable <string> > > expression
                = (a) => a.TakeWhile(i => i.Length < 3);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #2
0
        public static ExpressionInstance Create(ExpressionDefinition definition)
        {
            // input
            var inputs = new ObservableCollection <ObservableInput>();

            foreach (var pair in definition.SourceTypes)
            {
                var inputType = typeof(ObservableInput <>).MakeGenericType(pair.Value.GetGenericArguments()[0]);
                var input     = (ObservableInput)Activator.CreateInstance(inputType);
                input.Name = pair.Key;
                inputs.Add(input);
            }

            // create output
            var outputObject = definition
                               .CompiledExpression
                               .DynamicInvoke(inputs
                                              .OfType <IObservableInput>()
                                              .Select(g => g.Observable)
                                              .ToArray());

            var outputType = typeof(ObservableOutput <>).MakeGenericType(
                definition.CompiledExpression.Method.ReturnType.GetGenericArguments()[0]);
            var output = (ObservableSource)Activator.CreateInstance(outputType, outputObject);

            return(new ExpressionInstance
            {
                Definition = definition,
                Inputs = new ReadOnlyObservableCollection <ObservableInput>(inputs),
                Output = output,
            }.SetUpDiagram());
        }
Exemple #3
0
        public static ExpressionDefinition GroupBy()
        {
            string code =
                @"
from s in a
group s by s.Length
  into gr
  from ss in gr
  select ""Key: "" + gr.Key + ""  Value: "" + ss;
";
            Expression <Func <IObservable <string>, IObservable <string> > > expression = a =>
                                                                                          from s in a
                                                                                          group s by s.Length
                                                                                          into gr
                                                                                          from ss in gr
                                                                                          select "Key: " + gr.Key + "  Value: " + ss;

            var @operator = ReflectionHelper.GetMethod(
                () => Observable.GroupBy <string, string>(null, _ => _));

            return(ExpressionDefinition.Create(expression,
                                               new ExpressionSettings {
                Operator = @operator, CodeSample = code
            }));
        }
Exemple #4
0
        public static ExpressionDefinition SelectMany()
        {
            Expression <Func <IObservable <long>, IObservable <long> > > expression
                = a => a.SelectMany(v => Observable.Interval(TimeSpan.FromMilliseconds(1000)).Select(_ => v).Take((int)v));

            return(ExpressionDefinition.Create(expression));
        }
Exemple #5
0
        public static ExpressionDefinition Skip()
        {
            Expression <Func <IObservable <string>, IObservable <string> > > expression
                = (a) => a.Skip(4);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #6
0
        public static ExpressionDefinition Scan()
        {
            Expression <Func <IObservable <string>,
                              IObservable <int> > > expression
                = (a) => a.Scan(0, (acc, v) => acc + v.Length);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #7
0
        public static ExpressionDefinition DistinctUntilChanged()
        {
            Expression <Func <IObservable <string>,
                              IObservable <string> > > expression
                = (a) => a.DistinctUntilChanged();

            return(ExpressionDefinition.Create(expression));
        }
Exemple #8
0
        public static ExpressionDefinition Where()
        {
            Expression <Func <IObservable <string>,
                              IObservable <string> > > expression
                = (a) => a.Where(i => i.Length % 2 == 0);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #9
0
        public static ExpressionDefinition OnErrorResumeNext()
        {
            Expression <Func <IObservable <string>, IObservable <string>,
                              IObservable <string> > > expression
                = (a, b) => a.OnErrorResumeNext(b);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #10
0
        public static ExpressionDefinition Any()
        {
            Expression <Func <IObservable <string>,
                              IObservable <bool> > > expression
                = a => a.Any(i => i.Length < 3);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #11
0
        public static ExpressionDefinition Average()
        {
            Expression <Func <IObservable <double>,
                              IObservable <double> > > expression
                = a => a.Average();

            return(ExpressionDefinition.Create(expression));
        }
Exemple #12
0
        public static ExpressionDefinition Min()
        {
            Expression <Func <IObservable <int>,
                              IObservable <int> > > expression
                = a => a.Min();

            return(ExpressionDefinition.Create(expression));
        }
Exemple #13
0
        public static ExpressionDefinition Count()
        {
            Expression <Func <IObservable <string>,
                              IObservable <int> > > expression
                = a => a.Count();

            return(ExpressionDefinition.Create(expression));
        }
Exemple #14
0
        public static ExpressionDefinition Merge()
        {
            Expression <Func <IObservable <string>, IObservable <string>, IObservable <string>,
                              IObservable <string> > > expression
                = (a, b, c) => Observable.Merge(a, b, c);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #15
0
        public static ExpressionDefinition Select()
        {
            Expression <Func <IObservable <string>,
                              IObservable <int> > > expression
                = (a) => a.Select(i => i.Length);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #16
0
        public static ExpressionDefinition CombineLatest()
        {
            Expression <Func <IObservable <string>, IObservable <string>,
                              IObservable <string> > > expression
                = (a, b) => a.CombineLatest(b, (x, y) => x + " - " + y);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #17
0
        public static ExpressionDefinition Sample()
        {
            Expression <Func <IObservable <string>,
                              IObservable <string> > > expression
                = (a) => a.Sample(TimeSpan.FromSeconds(2));

            return(ExpressionDefinition.Create(expression));
        }
Exemple #18
0
        public static ExpressionDefinition TakeUntil()
        {
            Expression <Func <IObservable <string>, IObservable <string>,
                              IObservable <string> > > expression
                = (a, b) => a.TakeUntil(b);

            return(ExpressionDefinition.Create(expression));
        }
Exemple #19
0
        public static ExpressionDefinition Repeat()
        {
            Expression <Func <IObservable <string>, IObservable <string> > > expression
                = a => a
                  .SelectMany(v => string.IsNullOrEmpty(v) ? Observable.Throw <string>(new Exception()) : Observable.Return(v))
                  .Retry();

            return(ExpressionDefinition.Create(expression));
        }
Exemple #20
0
        public static ExpressionDefinition Merge()
        {
            Expression <Action> temp = () => Observable.Merge(new IObservable <string> [0]);
            var @operator            = (temp.Body as MethodCallExpression).Method;

            Func <IObservable <string>, IObservable <string>, IObservable <string>,
                  IObservable <string> > expression
                = (a, b, c) => Observable.Merge(a, b, c);

            return(ExpressionDefinition.Create(expression, new ExpressionSettings
            {
                Operator = @operator
            }));
        }
Exemple #21
0
        public ExpressionInstanceVM()
        {
            Reset = new DelegateCommand <object>(ResetHandler);
            Close = new DelegateCommand <object>(CloseHandler);

            _inputs = new ObservableCollection <ObservableInputVM>();
            Inputs  = new ReadOnlyObservableCollection <ObservableInputVM>(_inputs);

            if (IsInDesignMode())
            {
                Definition = new ExpressionDefinition("Zip", "To jest opis Zip ... ", "(a,b) => z.Zip(b, (x,y) => x + y)");
                _inputs.Add(new ObservableInputVM());
                Output = new ObservableOutputVM();
            }
        }
Exemple #22
0
        public static ExpressionDefinition BufferWithCount()
        {
            Expression <Func <IObservable <string>,
                              IObservable <string> > > expression
                = a => a.Buffer(3).
                  Select(i => string.Join(",", i.ToArray()));

            var @operator = ReflectionHelper.GetMethod(
                () => Observable.Buffer <string>(null, 3));

            return(ExpressionDefinition.Create(expression,
                                               new ExpressionSettings {
                Operator = @operator, Name = "BufferWithCount"
            }));
        }
Exemple #23
0
        public static ExpressionDefinition WindowWithTime()
        {
            Expression <Func <IObservable <string>,
                              IObservable <string> > > expression
                = a => a.Window(TimeSpan.FromSeconds(3)).
                  Select(i => string.Join(",", i.ToArray()));

            var @operator = ReflectionHelper.GetMethod(
                () => Observable.Window <string>(null, TimeSpan.FromSeconds(3)));

            return(ExpressionDefinition.Create(expression,
                                               new ExpressionSettings {
                Operator = @operator
            }));
        }
Exemple #24
0
        public static ExpressionDefinition IncrementalSearch()
        {
            Func <IObservable <string>, IObservable <Person>, IObservable <Person> > expression
                = (codeChanged, webServiceCall) =>
                {
                var q =
                    from code in codeChanged
                    from x in Observable.Return(new Unit()).Delay(TimeSpan.FromSeconds(4)).TakeUntil(codeChanged)
                    from result in webServiceCall.TakeUntil(codeChanged)
                    select result;

                return(q);
                };

            return(ExpressionDefinition.Create(expression, new ExpressionSettings
            {
                Name = "Incremental find",
                Description = @"Send the code of the person you are looking for, "
                              + "after four seconds (if you don't send new code again) web service "
                              + "will be called. The result won't be returned if new code is provided "
                              + "in the meantime.",
            }));
        }
Exemple #25
0
 public ExpressionInstanceVM(ExpressionDefinition definition)
     : this()
 {
     Definition = definition;
     Reset.Execute(null);
 }