Exemple #1
0
 /// <inheritdoc/>
 public IObservable <Unit> Upsert(T item)
 {
     return(_childQuery
            .Child(item.Id)
            .PutAsync(item)
            .ToObservable());
 }
Exemple #2
0
        //tap an action
        async void Action_Tapped(object sender, System.EventArgs e)
        {
            var button = (Frame)sender;
            int position;

            if (int.TryParse(button.ClassId, out position))
            {
                //send position to firebase
                if (button.ClassId.Equals(GameInfo.DestroyPos))
                {
                    SendToFirebase("");
                }
                else if (!string.IsNullOrEmpty(cardName))
                {
                    SendToFirebase(cardName);
                }

                await Task.Delay(500);

                await child.Child(GameInfo.Position).PutAsync(position);
            }

            device.NewTag -= HandleNewTag;

            await Application.Current.MainPage.Navigation.PopAsync();
        }
        public void SaveReplay(ReplayMeta meta, ReplayData data)
        {
            logger.Info($"Checking for saved maps");
            string encodedMap = Encode(data.Map);
            string mapHash    = encodedMap.CalculateMd5();

            if (maps.Child("keys").Child(mapHash).OnceSingleAsync <EncodedData>().ConfigureAwait(false).GetAwaiter().GetResult()?.D != "1")
            {
                maps.Child("data").Child(mapHash).PutAsync(new EncodedData(encodedMap)).ConfigureAwait(false).GetAwaiter().GetResult();
                maps.Child("keys").Child(mapHash).PutAsync(new EncodedData("1")).ConfigureAwait(false).GetAwaiter().GetResult();
            }

            logger.Info($"Saving data for AI {meta.AiName} to Firebase");
            var resultData = datas
                             .PostAsync(new EncodedData(data.Encode()))
                             .ConfigureAwait(false).GetAwaiter()
                             .GetResult();

            logger.Info($"Data for AI {meta.AiName} saved, result is {resultData.Key}");

            meta.DataId  = resultData.Key;
            meta.MapHash = mapHash;

            logger.Info($"Saving meta for AI {meta.AiName} to Firebase");
            var resultMeta = metas.PostAsync(meta)
                             .ConfigureAwait(false).GetAwaiter()
                             .GetResult();

            logger.Info($"Meta for AI {meta.AiName} saved, result is {resultMeta.Key}");
        }
        public ReplayRepo(bool test = false)
        {
            fb = Connect().ConfigureAwait(false).GetAwaiter().GetResult();
            var rootName = test ? "test" : "v2";

            rootQuery = fb.Child(rootName);
            metas     = rootQuery.Child("replays").Child("metas");
            datas     = rootQuery.Child("replays").Child("datas");
            maps      = rootQuery.Child("maps");
        }
Exemple #5
0
 public virtual Task SetAsync(ChildQuery query, string key, OfflineEntry entry)
 {
     if (entry.SyncOptions == SyncOptions.Put)
     {
         return(query.Child(key).PutAsync(entry.Data));
     }
     else
     {
         return(query.Child(key).PatchAsync(entry.Data));
     }
 }
Exemple #6
0
        public async Task <bool> DeleteUserAsync(string username)
        {
            try
            {
                await _query.Child(username).DeleteAsync();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        public bool CheckIfPortIsFree(int portNumber)
        {
            var portChild = rootQuery.Child(portNumber.ToString());
            var resp      = portChild.PostAsync(GetValidToTimestamp()).ConfigureAwait(false)
                            .GetAwaiter().GetResult();

            var dateTimes = portChild.OnceAsync <DateTime>().ConfigureAwait(false).GetAwaiter().GetResult();

            var now            = DateTime.UtcNow;
            var firebaseObject = dateTimes.First(x => x.Object >= now);

            portChild.Child(resp.Key).DeleteAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            return(firebaseObject.Key == resp.Key);
        }
        public async Task <bool> UpdateItemAsync(string id, T item)
        {
            try
            {
                await _query
                .Child(id)
                .PutAsync(item);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Exemple #9
0
 private IDictionary <string, int[]> GetMapsInner()
 {
     return(maps.Child("data")
            .OnceAsync <EncodedData>()
            .ConfigureAwait(false).GetAwaiter()
            .GetResult()
            .ToDictionary(e => e.Key, e => JsonConvert.DeserializeObject <Map>(e.Object.D).Mines.OrderBy(g => g).ToArray()));
 }
 public ReplayData GetData(ReplayMeta meta)
 {
     return(datas
            .Child(meta.DataId)
            .OnceSingleAsync <ReplayData>()
            .ConfigureAwait(false).GetAwaiter()
            .GetResult());
 }
Exemple #11
0
        public async Task <bool> AddItem(T item)
        {
            try
            {
                item.Id      = Guid.NewGuid().ToString();
                item.OwnerId = uid;

                await _query
                .Child(item.Id)
                .PutAsync(item);
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(false));
            }

            return(await Task.FromResult(true));
        }
        public async Task <bool> UpdateItemAsync(EntryData updatedata)
        {
            try
            {
                var toUpdatePerson = (await _query
                                      .OnceAsync <Item>()).Where(a => (a.Key == updatedata.EntryId)).FirstOrDefault();

                await _query
                .Child(updatedata.EntryId)
                .PutAsync(updatedata.EntryItem);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Exemple #13
0
 public virtual async Task SetAsync(ChildQuery query, string key, OfflineEntry entry)
 {
     using (var child = query.Child(key))
     {
         if (entry.SyncOptions == SyncOptions.Put)
         {
             await child.PutAsync(entry.Data);
         }
         else
         {
             await child.PatchAsync(entry.Data);
         }
     }
 }
        public ReplayData GetData(ReplayMeta meta)
        {
            string data = datas
                          .Child(meta.DataId)
                          .OnceSingleAsync <EncodedData>()
                          .ConfigureAwait(false).GetAwaiter()
                          .GetResult().D;
            string mapData = maps.Child("data")
                             .Child(meta.MapHash)
                             .OnceSingleAsync <EncodedData>()
                             .ConfigureAwait(false).GetAwaiter()
                             .GetResult().D;
            var replayData = ReplayData.Decode(data);

            replayData.Map = Decode <Map>(mapData);
            return(replayData);
        }
        public static async Task Read()
        {
            AppData.onlineLists = new List <GroceryListClass>();

            if (AppData.auth.CurrentUser == null)
            {
                return;
            }


            ChildQuery listsNode = AppData.dataNode.Child(AppData.currentUser.Uid);

            var allListsData = await listsNode.OnceAsync <TempGroceryListClass>();

            foreach (FirebaseObject <TempGroceryListClass> any in allListsData)
            {
                List <ItemClass> itemsOfList = new List <ItemClass>();

                ChildQuery thisListNode = listsNode.Child(any.Object.Name);

                var readItems = await thisListNode.Child("Items").OnceAsync <ItemClass>();

                foreach (FirebaseObject <ItemClass> anyItem in readItems)
                {
                    itemsOfList.Add(anyItem.Object);
                }

                GroceryListClass thisList = new GroceryListClass
                {
                    Name  = any.Object.Name,
                    Items = itemsOfList,
                    Owner = any.Object.Owner
                };

                AppData.onlineLists.Add(thisList);
            }
        }
 /// <summary>
 /// References a sub child of the existing node.
 /// </summary>
 /// <param name="node"> The child. </param>
 /// <param name="path"> The path of sub child. </param>
 /// <returns> The <see cref="ChildQuery"/>. </returns>
 public static ChildQuery Child(this ChildQuery node, string path)
 {
     return(node.Child(() => path));
 }
 public async Task Edit(T t)
 {
     await FirebaseClient.Child(t.Id).PutAsync(t);
 }
Exemple #18
0
 public virtual Task PutAsync(ChildQuery query, string key, OfflineEntry entry)
 {
     return(query.Child(key).PutAsync(entry.Deserialize <T>()));
 }
        public Task SetAsync(ChildQuery query, string key, OfflineEntry entry)
        {
            var user = entry.Deserialize <User>();

            return(query.Child(key).Child("currentTabId").PutAsync <string>(user.ActiveGroupId));
        }