Exemplo n.º 1
0
 private static And UserIsGroupCreator(Guid userId, ReqlExpr eventExpr)
 {
     return(R.And(
                eventExpr["Type"].Eq(EventType.GroupCreated),
                UserIsAuthor(userId, eventExpr)
                ));
 }
Exemplo n.º 2
0
        public override ReqlExpr Parse(ReqlExpr expression, QueryModel queryModel, Expression predicate)
        {
            var binaryExpression = (BinaryExpression)predicate;
            var value            = GetValue(binaryExpression);

            return(((Table)expression).Get(value));
        }
Exemplo n.º 3
0
 private static And UserMembersInChannelNotChanged(ReqlExpr eventExpr)
 {
     return(R.And(
                eventExpr["Type"].Ne(EventType.UserAddedToChannel),
                eventExpr["Type"].Ne(EventType.UserRemovedFromChannel)
                ));
 }
Exemplo n.º 4
0
 private static And UserNotRemovedFromGroup(Guid userId, ReqlExpr eventExpr)
 {
     return(R.And(
                UserAttached(userId, eventExpr),
                eventExpr["Type"].Ne(EventType.UserRemovedFromGroup)
                ));
 }
Exemplo n.º 5
0
        private static ReqlExpr GetWhereReqlAst(ReqlExpr reqlExpr, Expression predicate, QueryModel queryModel)
        {
            var visitor = new ExpressionVisitor(reqlExpr, GetResultType(queryModel));

            visitor.Visit(predicate);
            return(visitor.Current);
        }
Exemplo n.º 6
0
        public void Configuration(IAppBuilder app)
        {
            var mongo   = new MongoConnection();
            var rethink = new RethinkConnection();

            // Configure Web API for self-host.
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );


            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR();

            app.UseWebApi(config);

            ReqlExpr dbTable = RethinkDB.R.Db("baseball").Table("batterStat");

            var feed = dbTable.Changes()
                       .RunChanges <Batter>(RethinkConnection.Connection);

            var observe = feed.ToObservable();

            observe.SubscribeOn(NewThreadScheduler.Default)
            .Subscribe((Change <Batter> b) =>
            {
                BatterInstance.Instance.UpdateBatterStat(b.NewValue);
            });
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var mongo      = new MongoConnection();
            var rethink    = new RethinkConnection();
            var eventStore = new EventConnection();

            var system   = ActorSystem.Create("baseballStats");
            var topLevel = system.ActorOf(GameEventCoordinator.Create(), "gameCoordinator");

            var handler = new PlayHandler(topLevel);


            ReqlExpr dbTable = RethinkDB.R.Db("baseball").Table("plays");

            var feed = dbTable.Changes()
                       .RunChanges <Play>(RethinkConnection.Connection /*, new { include_initial = true }*/);

            var observe = feed.ToObservable();

            observe.SubscribeOn(CurrentThreadScheduler.Instance)
            .Subscribe((Change <Play> p) =>
            {
                handler.Handle(p.NewValue);
            });



            Console.WriteLine("Hit enter to exit...");
            Console.ReadLine();
        }
Exemplo n.º 8
0
        public override ReqlExpr Parse(ReqlExpr expression, QueryModel queryModel, Expression predicate)
        {
            var binaryExpression = (BinaryExpression)predicate;
            var value            = GetValue(binaryExpression);

            return(((Table)expression).GetAll(value).OptArg("index", GetIndexName(binaryExpression)));
        }
        public override NexusExtDBBaseService Where(JArray conditions)
        {
            Where();
            query = query.Filter(doc => BuildFilter(doc, conditions));

            return(this);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var handler = new PlayHandler();

            var conn = RethinkDB.R
                       .Connection()
                       .Hostname("localhost")
                       .Port(RethinkDBConstants.DefaultPort)
                       .Timeout(30)
                       .Connect();
            ReqlExpr dbTable = RethinkDB.R.Db("baseball").Table("plays");

            var feed = dbTable.Changes()
                       .RunChanges <Play>(conn, new { include_initial = true });

            var observe = feed.ToObservable();

            observe.SubscribeOn(CurrentThreadScheduler.Instance)
            .Subscribe((Change <Play> p) =>
            {
                handler.Handle(p.NewValue);
            });



            Console.WriteLine("Hit enter to exit...");
            Console.ReadLine();
        }
Exemplo n.º 11
0
        public static ReqlExpr filter <T>(this ReqlExpr _this, Expression <Func <T, object> > expr)
        {
            var arguments = new Arguments(_this);

            arguments.CoerceAndAdd(expr);
            return(new Filter(arguments));
        }
        private static ReqlExpr GetWhereReqlAst(ReqlExpr reqlExpr, Expression predicate)
        {
            var visitor = new ExpressionVisitor(reqlExpr, typeof(bool));

            visitor.Visit(predicate);
            return(visitor.Current);
        }
Exemplo n.º 13
0
 private And UserIdRelatedCriteria(Guid userId, ReqlExpr eventExpr)
 {
     return(R.And(
                R.Or(
                    R.And(
                        R.Or(
                            GroupNotCreated(eventExpr),
                            UserNotRemovedFromGroup(userId, eventExpr)
                            ),
                        UserIsInsideGroup(userId, eventExpr)
                        ),
                    UserIsGroupCreator(userId, eventExpr),
                    UserRemovedFromGroup(userId, eventExpr)
                    ),
                R.Or(
                    ChatNotAffected(eventExpr),
                    UserRemovedFromChat(userId, eventExpr),
                    UserIsInsideAffectedChat(userId, eventExpr)
                    ),
                R.Or(
                    ChannelNotAffected(eventExpr),
                    UserRemovedFromChannel(userId, eventExpr),
                    UserMembersInChannelNotChanged(eventExpr),
                    UserIsInsideAffectedChannel(userId, eventExpr)
                    )
                ));
 }
Exemplo n.º 14
0
 private static And UserRemovedFromChannel(Guid userId, ReqlExpr eventExpr)
 {
     return(R.And(
                UserAttached(userId, eventExpr),
                eventExpr["Type"].Eq(EventType.UserRemovedFromChannel)
                ));
 }
Exemplo n.º 15
0
        public static async Task <T[]> RunArrayAsync <T>(this ReqlExpr expr, IConnection conn)
        {
            var huh = await expr.RunResultAsync(conn);

            var cursor = await expr.RunCursorAsync <T>(conn);

            return(cursor.ToArray());
        }
        public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel)
        {
            var fromExpression     = queryModel.MainFromClause.FromExpression as MemberExpression;
            var memberNameResolver = new MemberNameResolver(fromExpression);

            reqlExpr = memberNameResolver.Resolve(reqlExpr);
            reqlExpr = reqlExpr.Filter(expr => GetWhereReqlAst(expr, ((AllResultOperator)queryModel.ResultOperators[0]).Predicate, queryModel).Not());
            return(reqlExpr.Count().Eq(0));
        }
Exemplo n.º 17
0
        private ReqlExpr BuildDynamicFilter(ReqlExpr expr, string[] colorSearch)
        {
            var statement = R.Or();

            foreach (var color in colorSearch)
            {
                statement = statement.Or(expr[nameof(Product.ColorCode)].Eq(color));
            }
            return(statement);
        }
        public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel)
        {
            var fromExpression = queryModel.MainFromClause.FromExpression as ConstantExpression;
            var array          = RethinkDB.R.Expr(fromExpression.Value as IEnumerable <object>);

            var resultOperator = queryModel.ResultOperators[0] as ContainsResultOperator;

            var memberNameResolver = new MemberNameResolver((MemberExpression)resultOperator.Item);

            return(array.Contains(memberNameResolver.Resolve(reqlExpr)));
        }
Exemplo n.º 19
0
        public static ReqlExpr TranslateUnary(ExpressionType type, ReqlExpr term)
        {
            switch (type)
            {
            case ExpressionType.Not:
                return(term.Not());

            default:
                throw new NotSupportedException("Unary term not supported.");
            }
        }
        private static ReqlExpr GetWhereReqlAst(ReqlExpr reqlExpr, Expression predicate)
        {
            var subQueryExpression = predicate as SubQueryExpression;

            var where = subQueryExpression.QueryModel.BodyClauses[0] as WhereClause;

            var visitor = new ExpressionVisitor(reqlExpr, subQueryExpression.QueryModel.MainFromClause.ItemType);

            visitor.Visit(where.Predicate);
            return(visitor.Current);
        }
Exemplo n.º 21
0
        protected override ReqlExpr BuildReql(ReqlExpr reqlExpr, QueryModel queryModel)
        {
            reqlExpr = reqlExpr.Nth(queryModel.ResultOperators[0] is FirstResultOperator ? 0 : -1);
            var resultOperator = (ChoiceResultOperatorBase)queryModel.ResultOperators[0];

            if (resultOperator.ReturnDefaultWhenEmpty)
            {
                reqlExpr = reqlExpr.Default_((object)null);
            }
            return(reqlExpr);
        }
Exemplo n.º 22
0
        private JObject GetFromDbFull <T>(Id id)
        {
            var      importTree = GetFullImportTree(typeof(T), null);
            var      table      = GetTable(typeof(T));
            ReqlExpr get        = table
                                  .Get(id.ToString());

            get = Merge(get, importTree);
            var result = get.Run(_connection) as JObject;

            return(result);
        }
Exemplo n.º 23
0
 private static ReqlExpr ResolveMemberExpression(ReqlExpr reqlExpr, MemberExpression expression)
 {
     if (expression.Expression.NodeType == ExpressionType.MemberAccess)
     {
         reqlExpr = ResolveMemberExpression(reqlExpr, (MemberExpression)expression.Expression);
     }
     if (expression.Expression.NodeType == ExpressionType.Extension && expression.Expression is SubQueryExpression)
     {
         reqlExpr = ResolveExtensionExpression(reqlExpr, (SubQueryExpression)expression.Expression);
     }
     return(reqlExpr[QueryHelper.GetJsonMemberName(expression.Member)]);
 }
Exemplo n.º 24
0
 private Gt UserIsInsideGroup(Guid userId, ReqlExpr eventExpr)
 {
     return(_groupUserTable
            .Filter(
                groupUser => R.And(
                    groupUser["GroupId"].Eq(eventExpr["GroupId"]),
                    groupUser["UserId"].Eq(userId)
                    )
                )
            .Count()
            .Gt(0));
 }
        public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel)
        {
            var fromExpression     = queryModel.MainFromClause.FromExpression as MemberExpression;
            var memberNameResolver = new MemberNameResolver(fromExpression);

            reqlExpr = memberNameResolver.Resolve(reqlExpr);
            if (queryModel.BodyClauses.Any())
            {
                reqlExpr = reqlExpr.Filter(expr => GetWhereReqlAst(expr, ((WhereClause)queryModel.BodyClauses[0]).Predicate, queryModel));
            }
            return(BuildReql(reqlExpr, queryModel));
        }
Exemplo n.º 26
0
 private Gt UserIsInsideAffectedChannel(Guid userId, ReqlExpr eventExpr)
 {
     return(_channelUserTable
            .Filter(
                channelUser => R.And(
                    channelUser["ChannelId"].Eq(eventExpr["ChannelId"]),
                    channelUser["UserId"].Eq(userId)
                    )
                )
            .Count()
            .Gt(0));
 }
Exemplo n.º 27
0
        public static ReqlExpr TranslateBinary(ExpressionType type, ReqlExpr left, ReqlExpr right)
        {
            switch (type)
            {
            case ExpressionType.Equal:
                return(left.Eq(right));

            case ExpressionType.NotEqual:
                return(left.Eq(right).Not());

            case ExpressionType.LessThan:
                return(left.Lt(right));

            case ExpressionType.LessThanOrEqual:
                return(left.Le(right));

            case ExpressionType.GreaterThan:
                return(left.Gt(right));

            case ExpressionType.GreaterThanOrEqual:
                return(left.Ge(right));

            case ExpressionType.And:
            case ExpressionType.AndAlso:
                return(left.And(right));

            case ExpressionType.Or:
            case ExpressionType.OrElse:
                return(left.Or(right));

            case ExpressionType.Not:
                throw new InvalidOperationException("ExpresionType:Not cannot be called on a binary translation.");

            case ExpressionType.Add:
                return(left.Add(right));

            case ExpressionType.Subtract:
                return(left.Sub(right));

            case ExpressionType.Multiply:
                return(left.Mul(right));

            case ExpressionType.Divide:
                return(left.Div(right));

            case ExpressionType.Modulo:
                return(left.Mod(right));

            default:
                throw new NotSupportedException("Binary expression not supported.");
            }
        }
        private ReqlExpr BuildFilter(ReqlExpr doc, JArray conditions)
        {
            var statement = r.And();

            foreach (JToken cond in conditions)
            {
                string column = (string)cond["column"];
                string op     = (string)cond["operator"];
                object value  = (object)cond["value"];

                switch (op)
                {
                case "eq": statement = statement.And(doc[column].Eq(value)); break;

                case "lt": statement = statement.And(doc[column].Lt(value)); break;

                case "gt": statement = statement.And(doc[column].Gt(value)); break;

                case "lte": statement = statement.And(doc[column].Le(value)); break;

                case "gte": statement = statement.And(doc[column].Ge(value)); break;

                case "like": statement = statement.And(doc[column].Match(value)); break;

                case "not-like": statement = statement.And(doc[column].Match(value).Not()); break;

                case "in": {
                    var      st     = r.Or();
                    string[] values = ((string)value).Split(new char[] { ',', ';' });
                    foreach (string val in values)
                    {
                        st = st.Or(doc[column].Eq(val));
                    }
                    statement = statement.And(st);
                    break;
                }

                case "not-in": {
                    var      st     = r.And();
                    string[] values = ((string)value).Split(new char[] { ',', ';' });
                    foreach (string val in values)
                    {
                        st = st.And(doc[column].Eq(val).Not());
                    }
                    statement = statement.And(st);
                    break;
                }
                }
            }

            return(statement);
        }
Exemplo n.º 29
0
        private ReqlExpr BuildDynamicFilter(ReqlExpr expr, Dictionary <string, object> parameters)
        {
            var statement = rethinkDB.And();

            if (parameters != null && parameters.Keys.Count > 0)
            {
                foreach (var key in parameters.Keys)
                {
                    statement = statement.And(expr[key].Eq(parameters[key]));
                }
            }
            return(statement);
        }
Exemplo n.º 30
0
        //private JArray GetFromDb<T>(Id[] ids, MapObject hashMap)
        //{
        //    var importTree = GetImportTree(typeof(T), hashMap, null);
        //    var idStrings = ids.Select(d => d.ToString()).ToArray();
        //    var table = GetTable(typeof(T));
        //    ReqlExpr get = table.GetAll(R.Args(idStrings));
        //    get = get.Map(item => Merge(item, importTree));
        //    get = get.Map(item => item.Pluck(hashMap));
        //    var result = get.CoerceTo("ARRAY").Run(_connection) as JArray;
        //    return result;
        //}

        private JObject GetFromDb <T>(Id id, MapObject hashMap)
        {
            var      importTree = GetImportTree(typeof(T), hashMap, null);
            var      table      = GetTable(typeof(T));
            ReqlExpr get        = table
                                  .Get(id.ToString());

            get = Merge(get, importTree);
            get = get.Pluck(hashMap);
            var result = get.Run(_connection) as JObject;

            return(result);
        }