Ejemplo n.º 1
0
        public void RegisterJsonEntity(string name, OnJsonDataCacheUpdated onupdated)
        {
            if (EntityRegistered(name))
            {
                return;
            }

            RegisterEntity <JsonDataCache>(name, delegate(string dname, IVersionedDataCache dcache)
            {
                JsonDataCache json = dcache as JsonDataCache;
                if (onupdated != null)
                {
                    onupdated(dname, json.Payload);
                }
            });
        }
Ejemplo n.º 2
0
        public void Serialize(Stream stream, IVersionedDataCache data_cache_obj)
        {
            UnityEngine.Debug.Assert(data_cache_obj != null && data_cache_obj is JsonDataCache,
                                     "data_cache_obj is null or data_cache_obj is not JsonDataCache");
            UnityEngine.Debug.Assert(stream != null && stream.CanWrite,
                                     "stream is null or can not write");

            JsonDataCache data = data_cache_obj as JsonDataCache;
            Hashtable     ht   = Johny.HashtablePool.Claim();

            ht["version"] = data.Version;
            ht["payload"] = data.Payload;

            string content = EB.JSON.Stringify(ht);

            using (TextWriter writer = new StreamWriter(stream))
            {
                writer.Write(content);
            }
        }
Ejemplo n.º 3
0
        public IVersionedDataCache Deserialize(Stream stream)
        {
            UnityEngine.Debug.Assert(stream != null && stream.CanRead,
                                     "stream is null or can not read");

            JsonDataCache data = new JsonDataCache();

            using (TextReader reader = new StreamReader(stream))
            {
                string    content = reader.ReadToEnd();
                Hashtable ht      = EB.JSON.Parse(content) as Hashtable;
                if (ht != null)
                {
                    data.Version = ht["version"].ToString();
                    data.Payload = ht["payload"];
                }
            }

            return(data.Payload != null ? data : null);
        }
Ejemplo n.º 4
0
        public object LoadJsonData(string name)
        {
            JsonDataCache json = Load <JsonDataCache>(name);

            return(json == null ? null : json.Payload);
        }
Ejemplo n.º 5
0
        public void CacheJsonData(string name, string version, object json)
        {
            JsonDataCache cache = new JsonDataCache(version, json);

            Cache(name, cache);
        }