Example #1
0
        internal void RefreshLocalEntities(Action <int> setProgress)
        {
            var cloudTables = getAllKindNames();

            //we get the keys and editdates
            foreach (var table in cloudTables)
            {
                var localCloudData = new CloudLocalStore <CloudEntity>(table.toKind());
                var entities       = localCloudData.GetUnsyncedLocalEntities(
                    cloudTable: table.toKind(),
                    localTable: getLocalTableName(table).toKind()
                    );
                if (entities.Count == 0)
                {
                    continue;
                }

                var entityConverter = new EntityConverter();
                var localStore      = new CloudLocalStore <LocalEntity>(getLocalTableName(table).toKind());
                var flatStore       = new FieldValueStore(getTableFieldValueName(table))
                {
                    batchSize = 50
                };

                foreach (var entity in entities)
                {
                    //we decrypt
                    var localEntity = entityConverter.toLocalEntity(entity);
                    var saved       = localStore.Update(localEntity);
                    if (saved == null)
                    {
                        //means we couldn't save, so we do what?
                        //throw exception??
                        log(string.Format("Couldn't save record for ", table, entity.Id));
                        continue;
                    }

                    //and deidentify
                    var deid = entityConverter.toDeidEntity(localEntity);

                    var ged = DbSaveableEntity.fromJson <GeneralEntityDataset>(
                        new KindItem(deid.DataBlob)
                        );

                    //todo: modify so we sync from CloudLocalStore separately than when downloading
                    //and save to localTables
                    flatStore.Save(ged, localEntity, saved.recordId);
                }

                //call finalise
                flatStore.finalise();
            }

            //check if we have these in the local tables

            //fetch and process records missing

            //or do a sql comparison
        }