/// <summary> /// Private constructor /// </summary> /// <param name="smartStore"></param> /// <param name="client"></param> private SyncManager(SmartStore.Store.SmartStore smartStore, IRestClient client) { ApiVersion = ApiVersionStrings.VersionNumber; _smartStore = smartStore; RestClient = client; SyncState.SetupSyncsSoupIfNeeded(smartStore); }
/// <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)); }
/// <summary> /// Create syncs soup if needed. /// </summary> /// <param name="store"></param> public static void SetupSyncsSoupIfNeeded(SmartStore.Store.SmartStore store) { if (store.HasSoup(Constants.SyncsSoup)) { return; } IndexSpec[] indexSpecs = { new IndexSpec(Constants.SyncType, SmartStoreType.SmartString) }; store.RegisterSoup(Constants.SyncsSoup, indexSpecs); }
/// <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); }
/// <summary> /// Save SyncState to db /// </summary> /// <param name="store"></param> public void Save(SmartStore.Store.SmartStore store) { try { store.Update(Constants.SyncsSoup, AsJson(), Id, false); } catch (SQLiteException sqe) { var se = new SmartStoreException("SqliteError occurred ", sqe); throw se; } }
public static SyncManager GetInstance(Account account, string communityId, SmartStore.Store.SmartStore smartStore) { if (account == null) { account = AccountManager.GetAccount(); } if (smartStore == null) { smartStore = SmartStore.Store.SmartStore.GetSmartStore(account); } string uniqueId = Constants.GenerateUniqueId(account, smartStore); lock (Synclock) { var client = new ClientManager().PeekRestClient(account); SyncManager instance = null; if (_instances != null) { if (_instances.TryGetValue(uniqueId, out instance)) { SyncState.SetupSyncsSoupIfNeeded(instance._smartStore); instance = new SyncManager(instance._smartStore, client); return(instance); } instance = new SyncManager(smartStore, client); _instances.Add(uniqueId, instance); } else { _instances = new Dictionary <string, SyncManager>(); instance = new SyncManager(smartStore, client); _instances.Add(uniqueId, instance); } SyncState.SetupSyncsSoupIfNeeded(instance._smartStore); return(instance); } }
public static string GenerateUniqueId(Account account, SmartStore.Store.SmartStore smartStore) { return(account != null ? account.UserId : "" + ":" + smartStore.DatabasePath); }
private CacheManager(Account account, string communityId) { _smartStore = SmartStore.Store.SmartStore.GetSmartStore(account); ResetInMemoryCache(); }