/// <summary> /// Clone an object. /// </summary> /// <param name="pData"></param> /// <returns></returns> public static object Clone(object pData) { string strVal = SerializeObject(pData); object cloned = FHSyncUtils.DeserializeObject(strVal, pData.GetType()); return(cloned); }
/// <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); }
public static FHSyncPendingRecord <T> FromJSON(string val) { return((FHSyncPendingRecord <T>)FHSyncUtils.DeserializeObject(val, typeof(FHSyncPendingRecord <T>))); }
/// <summary> /// Build a data record from a JSON object. /// </summary> /// <param name="str"></param> /// <returns></returns> public static FHSyncDataRecord <T> FromJson(string str) { return((FHSyncDataRecord <T>)FHSyncUtils.DeserializeObject(str, typeof(FHSyncDataRecord <T>))); }