示例#1
0
        static async Task <IEnumerable <ParseObject> > HandleFileAsync()
        {
            ParseClient.Initialize(new ParseClient.Configuration
            {
                ApplicationId = "XW0rXBZxcGJcl3zkoWrh3w6bryBpkXnG36CvzOPV",
                WindowsKey    = "C3O1Mn02ELUtYpKSBUbfUXf2dOh0snBHR8yoIbx6",
                Server        = "https://parseapi.back4app.com/"
            }
                                   );

            IEnumerable <ParseObject> cities       = null;
            List <ParseObject>        listOfCities = new List <ParseObject>();

            ParseQuery <ParseObject> query =
                ParseObject.GetQuery("City")
                .Include("country");

            int count = await query.CountAsync();

            int limit = 1000;

            for (int i = 0; i < count;)
            {
                query =
                    ParseObject.GetQuery("City")
                    .Include("country").Skip(i).Limit(limit);
                cities = await query.FindAsync();

                listOfCities.AddRange(cities.ToList <ParseObject>());
                i += limit;
            }

            return(listOfCities);
        }
        public int Count()
        {
            int result = 0;

            ParseObject obj = MapToParseObject((T)typeof(T).Instantiate());
            ParseQuery <ParseObject> query = ParseObject.GetQuery(GetTableName());

            result = query.CountAsync().Result;

            return(result);
        }
示例#3
0
    //Find a new match to join. If no waiting match is found, a new one will be created
    IEnumerator FindRandomMatch()
    {
        //get count of matches waiting
        ParseQuery <ParseObject> mainQuery = new ParseQuery <ParseObject> ("Match").WhereNotEqualTo("playerOne", ParseUser.CurrentUser).WhereEqualTo("status", "waiting");
        var find = mainQuery.CountAsync();

        while (!find.IsCompleted)
        {
            yield return(null);
        }
        int resultCount = find.Result;

        if (resultCount > 0)
        {
            Debug.Log("found " + resultCount + " matches, picking random one");
            var skipNumber = Random.Range(0, resultCount);
            mainQuery = new ParseQuery <ParseObject> ("Match").WhereNotEqualTo("playerOne", ParseUser.CurrentUser).WhereEqualTo("status", "waiting").Limit(1).Skip(skipNumber);
            var retrieve = mainQuery.FindAsync();
            while (!retrieve.IsCompleted)
            {
                yield return(null);
            }
            IEnumerable <ParseObject> foundMatches = retrieve.Result;
            if (foundMatches.Count() > 0)
            {
                var match = foundMatches.ElementAt(0);
                Debug.Log("trying to join random match " + match.ObjectId + " where " + match["playerOne"] + " is waiting");
                match.Increment("matchLock");
                var save = match.SaveAsync();

                while (!save.IsCompleted)
                {
                    yield return(null);
                }
                mainQuery = ParseObject.GetQuery("Match");
                var getMatch = mainQuery.GetAsync(match.ObjectId);

                while (!getMatch.IsCompleted)
                {
                    yield return(null);
                }
                ParseObject lockedMatch = getMatch.Result;
                if (int.Parse(lockedMatch["matchLock"].ToString()) <= 1)
                {
                    Debug.Log("successfully locked match " + match.ObjectId);
                    match["playerTwo"] = ParseUser.CurrentUser;
                    //match["player2DisplayName"] = AppModel.currentDisplayName;
                    match["status"]     = "active";
                    match["playerTurn"] = ParseUser.CurrentUser;
                    var updateMatch = match.SaveAsync();
                    while (!updateMatch.IsCompleted)
                    {
                        yield return(null);
                    }
                    if (!updateMatch.IsCanceled && !updateMatch.IsFaulted)
                    {
                        Debug.Log("successfully activated match, player2:s turn");
                        //StartCoroutine("GetMatches");
                        Application.LoadLevel("MyMatches");
                    }
                    else
                    {
                        Debug.Log("error adding current user as player 2 for match..");
                    }
                }
                else
                {
                    Debug.Log("match lock failed, create a new game...");
                    StartCoroutine("CreateMatch");
                }
            }
            else
            {
                Debug.Log("selected game not found, create a new game...");
                StartCoroutine("CreateMatch");
            }
        }
        else
        {
            Debug.Log("no waiting matches found, create a new game...");
            StartCoroutine("CreateMatch");
        }
    }