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"); }
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); } }
/// <summary> /// Create sync state in database for a sync down and return corresponding SyncState /// </summary> /// <param name="store"></param> /// <param name="target"></param> /// <param name="options"></param> /// <param name="soupName"></param> /// <returns></returns> public static SyncState CreateSyncDown(SmartStore.Store.SmartStore store, SyncDownTarget target, string soupName, SyncOptions options = null) { var sync = new JObject { {Constants.SyncType, SyncTypes.SyncDown.ToString()}, {Constants.SyncTarget, target.AsJson()}, {Constants.SyncSoupName, soupName}, {Constants.SyncStatus, SyncStatusTypes.New.ToString()}, {Constants.SyncProgress, 0}, {Constants.SyncTotalSize, -1}, {Constants.SyncMaxTimeStamp, -1}, }; if (options != null) { sync[Constants.SyncOptions] = options.AsJson(); } JObject upserted = store.Upsert(Constants.SyncsSoup, sync); if (upserted != null) { return FromJson(upserted); } sync[Constants.SyncStatus] = SyncStatusTypes.Failed.ToString(); return FromJson(sync); }