예제 #1
0
        /// <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);
        }
 public String GetHashValue()
 {
     if (null == hashValue)
     {
         //keep it consistant with ios/android/js
         JObject json = AsJObject();
         hashValue = FHSyncUtils.GenerateSHA1Hash(json);
     }
     return(hashValue);
 }
예제 #3
0
        /// <summary>
        /// Save permentently the storage.
        /// </summary>
        public void Save()
        {
            IIOService  ioService = ServiceFinder.Resolve <IIOService> ();
            ILogService logger    = ServiceFinder.Resolve <ILogService> ();

            Monitor.Enter(this);
            try {
                ioService.WriteFile(this.PersistPath, FHSyncUtils.SerializeObject(memoryStore));
            } catch (Exception ex) {
                logger.e("FHSyncClient.InMemoryDataStore", "Failed to save file " + this.PersistPath, ex);
                throw;
            } finally {
                Monitor.Exit(this);
            }
        }
예제 #4
0
        /// <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();
            }
        }
예제 #5
0
        /// <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 override string ToString()
 {
     return(FHSyncUtils.SerializeObject(this));
 }
 public static FHSyncPendingRecord <T> FromJSON(string val)
 {
     return((FHSyncPendingRecord <T>)FHSyncUtils.DeserializeObject(val, typeof(FHSyncPendingRecord <T>)));
 }
예제 #8
0
 /// <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>)));
 }
예제 #9
0
 /// <summary>
 /// Clone a data record.
 /// </summary>
 /// <returns></returns>
 public FHSyncDataRecord <T> Clone()
 {
     return((FHSyncDataRecord <T>)FHSyncUtils.Clone(this));
 }
예제 #10
0
 /// <summary>
 /// Contructor with a Data type.
 /// </summary>
 /// <param name="pData"></param>
 public FHSyncDataRecord(T pData)
 {
     Data = (T)FHSyncUtils.Clone(pData);
 }