private void UpdateAccountsLocally(Dictionary <String, String> idToNamesLocallyUpdated)
 {
     foreach (string id in idToNamesLocallyUpdated.Keys)
     {
         string updatedName = idToNamesLocallyUpdated[id];
         var    account     =
             _smartStore.Retrieve(AccountsSoup, _smartStore.LookupSoupEntryId(AccountsSoup, Constants.Id, id))[0]
             .ToObject <JObject>();
         account[Constants.Name]             = updatedName;
         account[SyncManager.Local]          = true;
         account[SyncManager.LocallyCreated] = false;
         account[SyncManager.LocallyDeleted] = false;
         account[SyncManager.LocallyUpdated] = true;
         _smartStore.Upsert(AccountsSoup, account);
     }
 }
Exemple #2
0
        public void TestAddAndRetrieveManyEntries()
        {
            Debug.WriteLine("SmartStoreLoadTest: In testAddAndRetrieveManyEntries");
            long    start = SmartStore.CurrentTimeMillis;
            long    end;
            var     soupEntryIds  = new List <long>();
            var     times         = new List <long>();
            JObject firstEntry    = null;
            JObject lastEntry     = null;
            JObject upsertedEntry = null;

            for (int i = 0; i < MAX_NUMBER_ENTRIES; i++)
            {
                String paddedIndex = i.ToString("D4");
                var    entry       = new JObject();
                entry.Add("Name", "Todd Stellanova" + paddedIndex);
                entry.Add("Id", "003" + paddedIndex);
                var attributes = new JObject();
                attributes.Add("type", "Contact");
                attributes.Add("url", "/foo/Contact" + paddedIndex);
                entry.Add("attributes", attributes);

                start         = SmartStore.CurrentTimeMillis;
                upsertedEntry = Store.Upsert(TEST_SOUP, entry);
                if (firstEntry == null)
                {
                    firstEntry = upsertedEntry;
                }
                var soupEntryId = upsertedEntry.GetValue(SmartStore.SoupEntryId).Value <long>();
                soupEntryIds.Add(soupEntryId);
                end = SmartStore.CurrentTimeMillis;
                times.Add(end - start);
            }
            lastEntry = upsertedEntry;
            // Compute average time taken
            long avg = 0;

            for (int i = 0; i < times.Count; i++)
            {
                avg += times[i];
            }
            avg /= times.Count;

            // Log avg time taken
            Debug.WriteLine("SmartStoreLoadTest",
                            "upserting " + MAX_NUMBER_ENTRIES + " entries avg time taken: " + avg + " ms");

            // Retrieve
            start = SmartStore.CurrentTimeMillis;
            JArray retrieved = Store.Retrieve(TEST_SOUP, soupEntryIds.ToArray());

            end = SmartStore.CurrentTimeMillis;

            Assert.AreEqual(retrieved.Count, MAX_NUMBER_ENTRIES);
            Assert.AreEqual(firstEntry.ToString(), retrieved[0].ToString());
            Assert.AreEqual(lastEntry.ToString(), retrieved[MAX_NUMBER_ENTRIES - 1].ToString());
            // Log retrieve time taken
            Debug.WriteLine("SmartStoreLoadTest",
                            "retrieve " + MAX_NUMBER_ENTRIES + " entries time taken: " + (end - start) + " ms");
        }
 /// <summary>
 ///     Build SyncState from store sync given by id
 /// </summary>
 /// <param name="store"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public static SyncState ById(SmartStore.Store.SmartStore store, long id)
 {
     JArray syncs = store.Retrieve(Constants.SyncsSoup, id);
     if (syncs == null || syncs.Count == 0)
     {
         return null;
     }
     return FromJson(syncs[0] as JObject);
 }