Esempio n. 1
0
 private async Task AddRecord(IFileRecord record)
 {
     await _indexedDbMgr.AddRecord(new StoreRecord <IFileRecord> {
         Storename = StoreName,
         Data      = record
     });
 }
 private static async Task AddRecord(IndexedDBManager DbManager, Word word)
 {
     await DbManager.AddRecord(new StoreRecord <Word>
     {
         Storename = DbConstants.StoreName,
         Data      = word
     });
 }
Esempio n. 3
0
 public async Task Save(string storeName, IEnumerable <TData> entities)
 {
     foreach (var entity in entities)
     {
         await indexedDb.AddRecord(new StoreRecord <TData> {
             Storename = storeName, Data = entity
         });
     }
 }
Esempio n. 4
0
        public async Task AddAsync <T>(string storeName, T valueItem)
        {
            var newRecord = new StoreRecord <T>
            {
                Storename = storeName,
                Data      = valueItem
            };

            await _dbManager.AddRecord(newRecord);
        }
 private async Task AddRecord(Word word)
 {
     await DbManager.AddRecord(new StoreRecord <FlashcardWord>
     {
         Storename = DbConstants.FlashcardsStoreName,
         Data      = new FlashcardWord {
             Chinese = word.Chinese, Day = 1, LastTrainDate = 0
         }
     });
 }
        public async void AddPlayer(Player player)
        {
            var record = new StoreRecord <Player>
            {
                Storename = "Players",
                Data      = player
            };

            await _dbManager.AddRecord(record);

            _allPlayers.Add(player);
        }
Esempio n. 7
0
    public async Task SaveGameAsync(string gameId, int slot, GameState state)
    {
        var saveGameRecord = new StoreRecord <SavedGame>
        {
            Storename = StoreName,
            Data      = SavedGame.Create(gameId, slot, state)
        };

        if (await SavedGameExists(gameId, slot))
        {
            await _dbManager.UpdateRecord(saveGameRecord);
        }
        else
        {
            await _dbManager.AddRecord(saveGameRecord);
        }
    }
Esempio n. 8
0
        public async Task SaveCollection(IEnumerable <ContactEntity> contacts)
        {
            int newCount    = 0;
            int updateCount = 0;
            int skipCount   = 0;

            foreach (ContactEntity c in contacts)
            {
                var getContact = await dbManager.GetRecordById <string, ContactEntity>("Contacts", c.Id);

                var writeContact = new StoreRecord <ContactEntity>
                {
                    Storename = "Contacts",
                    Data      = c
                };
                if (getContact == null || string.IsNullOrEmpty(getContact.Id))
                {
                    await dbManager.AddRecord(writeContact);

                    newCount++;
                }
                else
                {
                    if (getContact.ETag != c.ETag)
                    {
                        await dbManager.UpdateRecord <ContactEntity>(writeContact);

                        updateCount++;
                    }
                    else
                    {
                        skipCount++;
                    }
                }
            }
            NotifyPropertyChanged("Contacts");
        }
Esempio n. 9
0
        /// <summary>
        /// TryGet, Includes (Cause, Effect), OrderBy (Id, EventId, Order, Value, UpdatedDate)
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="orderby"></param>
        /// <param name="ascending"></param>
        /// <param name="includeProperties"></param>
        /// <param name="onSuccess"></param>
        /// <param name="onFail"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task TryGet(Expression <Func <Class, bool> > filter, string orderby, bool ascending, string includeProperties, Action <IEnumerable <Class>, string> onSuccess, Action <Exception, string> onFail, CascadingAppStateProvider state)
        {
            try
            {
                var          serializer            = new ExpressionSerializer(new BinarySerializer());
                var          bytes                 = serializer.SerializeBinary(filter);
                var          predicateDeserialized = serializer.DeserializeBinary(bytes);
                string       filterString          = predicateDeserialized.ToString();
                string       key           = ("causality_Class_tryget_" + filterString + "_" + orderby + "_" + ascending.ToString()).Replace(" ", "").ToLower();
                List <Class> data          = new();
                bool         getFromServer = false;
                string       source        = "";

                if (state.AppState.UseIndexedDB)
                {
                    var result = await _indexedDBManager.GetRecordByIndex <string, Blob>(new StoreIndexQuery <string> {
                        Storename = _indexedDBManager.Stores[0].Name, IndexName = "key", QueryValue = key
                    });

                    if (result is not null)
                    {
                        data   = JsonConvert.DeserializeObject <List <Class> >(result.Value);
                        source = "indexedDB";
                    }
                    else if (await _onlineState.IsOnline())
                    {
                        getFromServer = true;
                    }
                    else
                    {
                        throw new Exception("No connection");
                    }
                }
                else
                {
                    getFromServer = true;
                }

                if (getFromServer)
                {
                    ClassRequestGet  req = new() { Filter = filterString, OrderBy = orderby, Ascending = ascending };
                    ClassResponseGet ret = await _classService.GetAsync(req);

                    if (ret.Success)
                    {
                        foreach (var includeProperty in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            foreach (var item in ret.Classes)
                            {
                                if (includeProperty.ToLower().Equals("cause"))
                                {
                                    CauseRequestGet  _req = new() { Filter = "c => c.ClassId = " + item.Id, OrderBy = "Id", Ascending = true };
                                    CauseResponseGet _ret = await _causeService.GetAsync(_req);

                                    item.Causes.Add(_ret.Causes);
                                }
                                if (includeProperty.ToLower().Equals("effect"))
                                {
                                    EffectRequestGet  _req = new() { Filter = "e => e.ClassId = " + item.Id, OrderBy = "Id", Ascending = true };
                                    EffectResponseGet _ret = await _effectService.GetAsync(_req);

                                    item.Effects.Add(_ret.Effects);
                                }
                            }
                        }
                        data   = ret.Classes.ToList();
                        source = ret.Status;
                        if (state.AppState.UseIndexedDB)
                        {
                            await _indexedDBManager.AddRecord(new StoreRecord <Blob> {
                                Storename = "Blobs", Data = new Blob()
                                {
                                    Key = key, Value = JsonConvert.SerializeObject(data)
                                }
                            });
                        }
                    }
                    else
                    {
                        throw new Exception("No connection");
                    }
                }

                onSuccess(data, RequestCodes.TWO_ZERO_ZERO + ", recived " + data.Count.ToString() + " record from " + source);
            }
            catch (Exception e)
            {
                onFail(e, RequestCodes.FIVE_ZERO_ZERO);
            }
        }
 public Task AddAsync(T model)
 => _db.AddRecord(CreateStoreRecord(model));
Esempio n. 11
0
 public Task Add(TEntity entity)
 => _indexedDB.AddRecord(new StoreRecord <TEntity> {
     Data = entity, Storename = StoreName
 });
Esempio n. 12
0
        /// <summary>
        /// TryGet, Includes (none), OrderBy (Id, EventId, ClassId, CauseId, UserId, Value, UpdatedDate)
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="orderby"></param>
        /// <param name="ascending"></param>
        /// <param name="includeProperties"></param>
        /// <param name="onSuccess"></param>
        /// <param name="onFail"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task TryGet(Expression <Func <Effect, bool> > filter, string orderby, bool ascending, Action <IEnumerable <Effect>, string> onSuccess, Action <Exception, string> onFail, CascadingAppStateProvider state)
        {
            try
            {
                var           serializer            = new ExpressionSerializer(new BinarySerializer());
                var           bytes                 = serializer.SerializeBinary(filter);
                var           predicateDeserialized = serializer.DeserializeBinary(bytes);
                string        filterString          = predicateDeserialized.ToString();
                string        key           = ("causality_effect_tryget_" + filterString + "_" + orderby + "_" + ascending.ToString()).Replace(" ", "").ToLower();
                List <Effect> data          = new();
                bool          getFromServer = false;
                string        source        = "";

                if (state.AppState.UseIndexedDB)
                {
                    var result = await _indexedDBManager.GetRecordByIndex <string, Blob>(new StoreIndexQuery <string> {
                        Storename = _indexedDBManager.Stores[0].Name, IndexName = "key", QueryValue = key
                    });

                    if (result is not null)
                    {
                        data   = JsonConvert.DeserializeObject <List <Effect> >(result.Value);
                        source = "indexedDB";
                    }
                    else if (await _onlineState.IsOnline())
                    {
                        getFromServer = true;
                    }
                    else
                    {
                        throw new Exception("No connection");
                    }
                }
                else
                {
                    getFromServer = true;
                }

                if (getFromServer)
                {
                    EffectRequestGet  req = new() { Filter = filterString, OrderBy = orderby, Ascending = ascending };
                    EffectResponseGet ret = await _effectService.GetAsync(req);

                    if (ret.Success)
                    {
                        data   = ret.Effects.ToList();
                        source = ret.Status;
                        if (state.AppState.UseIndexedDB)
                        {
                            await _indexedDBManager.AddRecord(new StoreRecord <Blob> {
                                Storename = "Blobs", Data = new Blob()
                                {
                                    Key = key, Value = JsonConvert.SerializeObject(data)
                                }
                            });
                        }
                    }
                    else
                    {
                        throw new Exception("No connection");
                    }
                }

                onSuccess(data, RequestCodes.TWO_ZERO_ZERO + ", recived " + data.Count.ToString() + " record from " + source);
            }
            catch (Exception e)
            {
                onFail(e, RequestCodes.FIVE_ZERO_ZERO);
            }
        }
Esempio n. 13
0
 public async Task AddAsync(IUpdateEntry entry)
 {
     var storeRecord = ConvertToObjectRecord(entry);
     await _manager.AddRecord(storeRecord);
 }