/// <summary> /// Converts a normalized binary expression into the appropriate ParseQuery clause. /// </summary> private static ParseQuery <T> WhereBinaryExpression <T>( this ParseQuery <T> source, Expression <Func <T, bool> > expression, BinaryExpression node) where T : ParseObject { var leftTransformed = new ObjectNormalizer().Visit(node.Left) as MethodCallExpression; if (!(IsParseObjectGet(leftTransformed) && leftTransformed.Object == expression.Parameters[0])) { throw new InvalidOperationException( "Where expressions must have one side be a field operation on a ParseObject."); } var fieldPath = GetValue(leftTransformed.Arguments[0]) as string; var filterValue = GetValue(node.Right); if (filterValue != null && !ParseEncoder.IsValidType(filterValue)) { throw new InvalidOperationException( "Where clauses must use types compatible with ParseObjects."); } switch (node.NodeType) { case ExpressionType.GreaterThan: return(source.WhereGreaterThan(fieldPath, filterValue)); case ExpressionType.GreaterThanOrEqual: return(source.WhereGreaterThanOrEqualTo(fieldPath, filterValue)); case ExpressionType.LessThan: return(source.WhereLessThan(fieldPath, filterValue)); case ExpressionType.LessThanOrEqual: return(source.WhereLessThanOrEqualTo(fieldPath, filterValue)); case ExpressionType.Equal: return(source.WhereEqualTo(fieldPath, filterValue)); case ExpressionType.NotEqual: return(source.WhereNotEqualTo(fieldPath, filterValue)); default: throw new InvalidOperationException( "Where expressions do not support this operator."); } }
/// <summary> /// Converts a normalized method call expression into the appropriate ParseQuery clause. /// </summary> private static ParseQuery <T> WhereMethodCall <T>( this ParseQuery <T> source, Expression <Func <T, bool> > expression, MethodCallExpression node) where T : ParseObject { if (IsParseObjectGet(node) && (node.Type == typeof(bool) || node.Type == typeof(bool?))) { // This is a raw boolean field access like 'where obj.Get<bool>("foo")' return(source.WhereEqualTo(GetValue(node.Arguments[0]) as string, true)); } MethodInfo translatedMethod; if (functionMappings.TryGetValue(node.Method, out translatedMethod)) { var objTransformed = new ObjectNormalizer().Visit(node.Object) as MethodCallExpression; if (!(IsParseObjectGet(objTransformed) && objTransformed.Object == expression.Parameters[0])) { throw new InvalidOperationException( "The left-hand side of a supported function call must be a ParseObject field access."); } var fieldPath = GetValue(objTransformed.Arguments[0]); var containedIn = GetValue(node.Arguments[0]); var queryType = translatedMethod.DeclaringType.GetGenericTypeDefinition() .MakeGenericType(typeof(T)); translatedMethod = ReflectionHelpers.GetMethod(queryType, translatedMethod.Name, translatedMethod.GetParameters().Select(p => p.ParameterType).ToArray()); return(translatedMethod.Invoke(source, new[] { fieldPath, containedIn }) as ParseQuery <T>); } if (node.Arguments[0] == expression.Parameters[0]) { // obj.ContainsKey("foo") --> query.WhereExists("foo") if (node.Method == containsKeyMethod) { return(source.WhereExists(GetValue(node.Arguments[1]) as string)); } // !obj.ContainsKey("foo") --> query.WhereDoesNotExist("foo") if (node.Method == notContainsKeyMethod) { return(source.WhereDoesNotExist(GetValue(node.Arguments[1]) as string)); } } if (node.Method.IsGenericMethod) { if (node.Method.GetGenericMethodDefinition() == containsMethod) { // obj.Get<IList<T>>("path").Contains(someValue) if (IsParseObjectGet(node.Arguments[0] as MethodCallExpression)) { return(source.WhereEqualTo( GetValue(((MethodCallExpression)node.Arguments[0]).Arguments[0]) as string, GetValue(node.Arguments[1]))); } // someList.Contains(obj.Get<T>("path")) if (IsParseObjectGet(node.Arguments[1] as MethodCallExpression)) { var collection = GetValue(node.Arguments[0]) as System.Collections.IEnumerable; return(source.WhereContainedIn( GetValue(((MethodCallExpression)node.Arguments[1]).Arguments[0]) as string, collection.Cast <object>())); } } if (node.Method.GetGenericMethodDefinition() == notContainsMethod) { // !obj.Get<IList<T>>("path").Contains(someValue) if (IsParseObjectGet(node.Arguments[0] as MethodCallExpression)) { return(source.WhereNotEqualTo( GetValue(((MethodCallExpression)node.Arguments[0]).Arguments[0]) as string, GetValue(node.Arguments[1]))); } // !someList.Contains(obj.Get<T>("path")) if (IsParseObjectGet(node.Arguments[1] as MethodCallExpression)) { var collection = GetValue(node.Arguments[0]) as System.Collections.IEnumerable; return(source.WhereNotContainedIn( GetValue(((MethodCallExpression)node.Arguments[1]).Arguments[0]) as string, collection.Cast <object>())); } } } throw new InvalidOperationException(node.Method + " is not a supported method call in a where expression."); }
void signUp() { user = new ParseUser(){ Username = username, Password = password, Email = email }; int results = 0; ParseQuery<ParseUser> query = new ParseQuery<ParseUser>(); query.WhereEqualTo ("username", username).CountAsync ().ContinueWith (t => { results += t.Result; query.WhereEqualTo ("email", email).CountAsync ().ContinueWith (s => { results += s.Result; if(results > 0){ print ("User or email already exists"); return; } if(!Regex.IsMatch(email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z")){ print("Invalid email address"); return; } user["Geolocation"] = new ParseGeoPoint( lat, lon ); user["Messages"] = new List<string> (); Task signuptask = user.SignUpAsync (); print ("Success"); ParseUser.LogInAsync(username, password); if (ParseUser.CurrentUser.IsAuthenticated) { print ("Logged In"); loggedin = true; } }); }); GameObject temp = GameObject.Instantiate(Resources.Load("Entity"), new Vector3(0f, 0f, 0f), new Quaternion(0, 0, 0, 0)) as GameObject; temp.GetComponent<Entity> ().setUID (ParseUser.CurrentUser.ObjectId); GameObject chat = GameObject.Instantiate(Resources.Load("Chatroom"), new Vector3(0f, 0f, 0f), new Quaternion(0, 0, 0, 0)) as GameObject; chat.GetComponent<Chatroom>().entity = temp.GetComponent<Entity>(); chat.GetComponent<Chatroom>().userId = ParseUser.CurrentUser.ObjectId; }