コード例 #1
0
    public async Task <List <DefaultCollectionDataDB> > CreateNewUserCollection(UserDB user)
    {
        List <DefaultCollectionDataDB> allCardList = await GetDefaultCardCollection();

        if (allCardList != null && allCardList.Count > 0)
        {
            // SET ISFIRSTTIME TO FALSE

            await DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.usersTable)
            .Child(user.Name.ToLower())
            .Child(isFirstTime).SetValueAsync(false);

            // SET DEFAULT COLLECTION IN THE USERS COLLECTION IN DB
            foreach (DefaultCollectionDataDB dcData in allCardList)
            {
                string json = JsonUtility.ToJson(dcData);
                await DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.UsersCardCollectionTable)
                .Child(user.Name.ToLower())
                .Child(dcData.ID).SetRawJsonValueAsync(json);
            }

            FbUserCardCollectionUpdater userCollUpd = new FbUserCardCollectionUpdater();
            userCollUpd.UpdateLastUserCardCollectionDownloadTimestamp(user);
        }

        return(allCardList);
    }
コード例 #2
0
    public async void RestCardAmountFromCardCollection(DefaultCollectionDataDB pCardData, UserDB pUserDB)
    {
        if (DatosFirebaseRTHelper.Instance.isInit == false)
        {
            return;
        }

        int cardAmount = await GetUserCardCollectionCardAmount(pCardData, pUserDB);

        if (cardAmount <= 1)
        {
            await DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.UsersCardCollectionTable)
            .Child(pUserDB.Name.ToLower())
            .Child(pCardData.ID).SetValueAsync(null);
        }
        else
        {
            cardAmount--;
            await DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.UsersCardCollectionTable)
            .Child(pUserDB.Name.ToLower())
            .Child(pCardData.ID)
            .UpdateChildrenAsync(new Dictionary <string, object> {
                { cardAmountstr, cardAmount }
            });
        }

        FbUserCardCollectionUpdater userCollUpd = new FbUserCardCollectionUpdater();

        userCollUpd.UpdateLastUserCardCollectionModifyUpdateTimestamp(pUserDB);
    }
コード例 #3
0
 public HelperCardCollectionFirebaseKimboko()
 {
     fbGameCardCollection         = new FbGameCardCollection();
     fbUserCardCollection         = new FbUserCardCollection();
     fbUserCardCollectionCreation = new FbUserCardCollectionCreation();
     fbGameCardCollectionUpdater  = new FbGameCardCollectionUpdater();
     fbUserCardCollectionUpdater  = new FbUserCardCollectionUpdater();
 }
コード例 #4
0
    public async Task <bool> SetNewCardToUserCardCollection(DefaultCollectionDataDB pCardData, UserDB pUserDB)
    {
        if (DatosFirebaseRTHelper.Instance.isInit == false)
        {
            return(false);
        }

        int cardAmount = await GetUserCardCollectionCardAmount(pCardData, pUserDB);

        if (cardAmount == 0)
        {
            pCardData.Amount = 1;
            string json = JsonUtility.ToJson(pCardData);
            await DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.UsersCardCollectionTable)
            .Child(pUserDB.Name.ToLower())
            .Child(pCardData.ID)
            .SetRawJsonValueAsync(json);
        }
        else
        {
            cardAmount++;
            await DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.UsersCardCollectionTable)
            .Child(pUserDB.Name.ToLower())
            .Child(pCardData.ID)
            .UpdateChildrenAsync(new Dictionary <string, object> {
                { cardAmountstr, cardAmount }
            });
        }

        int newCardAmount = await GetUserCardCollectionCardAmount(pCardData, pUserDB);

        //Debug.Log("NEW CARD AMOUNT SETED ON DB CARD ID " + pCardData.ID + " Amount: " + cardAmount);
        if (cardAmount == newCardAmount)
        {
            //Debug.Log("IS THE SAME AMOUNT TRUE");
            FbUserCardCollectionUpdater userCollUpd = new FbUserCardCollectionUpdater();
            userCollUpd.UpdateLastUserCardCollectionModifyUpdateTimestamp(pUserDB);
            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #5
0
    public async Task <List <DefaultCollectionDataDB> > GetUserCardCollection(UserDB pUser)
    {
        if (DatosFirebaseRTHelper.Instance.isInit == false)
        {
            return(null);
        }

        List <DefaultCollectionDataDB> allCardList = new List <DefaultCollectionDataDB>();

        //FirebaseDatabase.DefaultInstance.GetReference(UsersCardCollectionTable).Child(pUser.Name.ToLower())
        DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.UsersCardCollectionTable)
        .Child(pUser.Name.ToLower()).KeepSynced(true);
        await DatosFirebaseRTHelper.Instance.reference.Child(DatosFirebaseRTHelper.Instance.UsersCardCollectionTable)
        .Child(pUser.Name.ToLower()).GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                //Debug.Log("NoChild");
                // Handle the error...
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;
                foreach (var child in snapshot.Children)
                {
                    DefaultCollectionDataDB card = JsonUtility.FromJson <DefaultCollectionDataDB>(child.GetRawJsonValue());
                    allCardList.Add(card);
                }
            }
        });

        if (allCardList.Count > 0)
        {
            FbUserCardCollectionUpdater userCollUpd = new FbUserCardCollectionUpdater();
            userCollUpd.UpdateLastUserCardCollectionDownloadTimestamp(pUser);
        }

        return(allCardList);
    }