public void Deserialize(CompactReader reader)
 {
     this._name      = (string)reader.ReadObject();
     this._data      = reader.ReadBytes(10 * 1024);
     this._sampleObj = (SampleObject)reader.ReadObject();
     this.time       = reader.ReadDateTime();
 }
示例#2
0
        /// <summary>
        /// Adds an object to the cache if it is not already present.
        /// </summary>
        private static long Add(string key)
        {
            long objSize = 0;

            if (!_cache.Contains(key))
            {
                try
                {
                    int operation = TestID;
                    if (CompactSerializationUsage.TestID == 6)
                    {
                        Random rand = new Random();
                        operation = (int)rand.Next(1, 5);
                    }

                    object Obj;
                    switch (operation)
                    {
                    case 1:
                        Obj     = new SmallObject();
                        objSize = 512;
                        break;

                    case 2:
                        Obj     = new NormalObject();
                        objSize = 4000;
                        break;

                    case 3:
                        Obj     = new BigObject();
                        objSize = 10000;
                        break;

                    case 4:
                        Obj     = new BiggerObject();
                        objSize = 50000;
                        break;

                    default:
                        Obj     = new SampleObject();
                        objSize = 5000;
                        break;
                    }

                    _addStats.BeginSample();
                    _cache.Add(
                        key,
                        Obj
                        );
                    _addStats.EndSample();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR: " + ex.Message);
                }
            }
            return(objSize);
        }