Beispiel #1
0
        protected static async Task <List <string> > GenerateRealmDB(Realms.Realm targetCache, int size)
        {
            var ret = new List <string>();

            // Write out in groups of 4096
            while (size > 0)
            {
                var toWriteSize = Math.Min(4096, size);
                var toWrite     = PerfHelper.GenerateRandomDatabaseContents(toWriteSize);

                await targetCache.WriteAsync((Realms.Realm realm) =>
                {
                    foreach (var item in toWrite)
                    {
                        var c   = new KeyValueRecord();
                        c.Key   = item.Key;
                        c.Value = item.Value;
                        realm.Manage <KeyValueRecord>(c);                        // update: false
                    }
                });

                foreach (var k in toWrite.Keys)
                {
                    ret.Add(k);
                }
                size -= toWrite.Count;
            }
            return(ret);
        }
 public void AddOrUpdate <T>(T item) where T : RealmObject
 {
     ConfigureInstance();
     _realm.WriteAsync(tempRealm =>
     {
         tempRealm.Add <T>(item, true);
     });
 }
Beispiel #3
0
        /// <summary>
        /// Writes the specified action async in a worker thread.
        /// Will create a temporary realm transaction on the worker thread.
        /// If an exception occurs during the write then the transaction is disposed of and will never be commited.
        /// You can provide a callback action to <paramref name="callbackAction"/> for an action to be invoked after the write occurs.
        /// </summary>
        /// <param name="writeAction">The write action.</param>
        /// <param name="callbackAction">The callback action.</param>
        /// <returns>An async task that you can operate off of.</returns>
        /// <exception cref="System.ArgumentNullException">writeAction</exception>
        public async Task WriteAsync([NotNull] Action <Realms.Realm> writeAction, Action callbackAction)
        {
            if (writeAction == null)
            {
                throw new ArgumentNullException(nameof(writeAction));
            }

            await _currentRealm.WriteAsync(writeAction);

            callbackAction?.Invoke();
        }