/// <summary> /// Clone storage. /// </summary> /// <returns></returns> public IDataStore <T> Clone() { InMemoryDataStore <T> cloned = new InMemoryDataStore <T>(); cacheLock.EnterReadLock(); try { foreach (var entry in memoryStore) { cloned.Insert(entry.Key, (T)FHSyncUtils.Clone(entry.Value)); } return(cloned); } finally { cacheLock.ExitReadLock(); } }
/// <summary> /// Load in-memory storage from file. /// </summary> /// <typeparam name="X"></typeparam> /// <param name="fullFilePath"></param> /// <returns></returns> public static InMemoryDataStore <X> Load <X>(string fullFilePath) { InMemoryDataStore <X> dataStore = new InMemoryDataStore <X>(); dataStore.PersistPath = fullFilePath; IIOService ioService = ServiceFinder.Resolve <IIOService> (); ILogService logger = ServiceFinder.Resolve <ILogService> (); if (ioService.Exists(fullFilePath)) { try { string fileContent = ioService.ReadFile(fullFilePath); dataStore.memoryStore = (Dictionary <string, X>)FHSyncUtils.DeserializeObject(fileContent, typeof(Dictionary <string, X>)); } catch (Exception ex) { logger.e("FHSyncClient.InMemoryDataStore", "Failed to load file " + fullFilePath, ex); dataStore.memoryStore = new Dictionary <string, X> (); } } return(dataStore); }