Beispiel #1
0
 public void ReflexAsync(BsonDocument Bson)
 {
     if (!BSON.Contains("SYSTEM") || !BSON["SYSTEM"].IsBsonDocument)
     {
         BSON.Set("SYSTEM", new BsonDocument("ASYNCCOUNT", 0));
     }
     if (!BSON["SYSTEM"].AsBsonDocument.Contains("ASYNCCOUNT") || !BSON["SYSTEM"]["ASYNCCOUNT"].IsInt32)
     {
         BSON["SYSTEM"].AsBsonDocument.Set("ASYNCCOUNT", 0);
     }
     else
     {
         int asyncCount = (int)BSON["SYSTEM"]["ASYNCCOUNT"];
         if (asyncCount < 10)
         {
             BSON["SYSTEM"].AsBsonDocument.Set("ASYNCCOUNT", (int)BSON["SYSTEM"]["ASYNCCOUNT"] + 1);
             bson = new BsonDocument(Bson);
             bson.Remove("right");
             bson.Remove("power");
             mongo.ReadAsync(bson);
         }
         else
         {
             Console.WriteLine("Please wait after " + asyncCount);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Removes the specified cache entry with the specified key.
        /// If the key is not found, no exception is thrown, the statement is just ignored.
        /// </summary>
        /// <param name="key">The cache-key to remove.</param>
        public void Remove(K key)
        {
            if (disposed)
            {
                return;
            }

            locker.EnterWriteLock();
            try
            {
                byte[] bytes;
                if (cache.TryGetValue(key, out bytes))
                {
                    try { timers[key].Dispose(); }
                    catch { }

                    memory -= bytes.Length;
                    timers.Remove(key);
                    cache.Remove(key);

                    if (OnRemove != null)
                    {
                        System.Threading.Tasks.Task.Factory.StartNew(() =>
                        {
                            if (OnRemove != null)
                            {
                                OnRemove(key, BSON.Deserialize <T>(bytes));
                            }
                        });
                    }
                }
            }
            finally { locker.ExitWriteLock(); }
        }
Beispiel #3
0
        /// <summary>
        /// Tries to gets the cache entry with the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">(out) The value, if found, or <c>default(byte[])</c>, if not.</param>
        /// <returns><c>True</c>, if <c>key</c> exists, otherwise <c>false</c>.</returns>
        public bool TryGet(K key, out T value)
        {
            if (disposed)
            {
                value = default(T);
                return(false);
            }

            locker.EnterReadLock();

            bool ret = false;

            value = default(T);

            try
            {
                byte[] bytes;
                ret = cache.TryGetValue(key, out bytes);
                if (ret)
                {
                    value = BSON.Deserialize <T>(bytes);
                }
                else if (Load != null)
                {
                    value = Load(key);
                    ret   = true;
                }
            }
            finally { locker.ExitReadLock(); }
            return(ret);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the cache entry with the specified key or return <c>default(byte[])</c> if the key is not found.
        /// </summary>
        /// <param name="key">The cache-key to retrieve.</param>
        /// <returns>The object from the cache or <c>default(byte[])</c>, if not found.</returns>
        public T Get(K key)
        {
            if (disposed)
            {
                return(default(T));
            }

            locker.EnterReadLock();
            T val = default(T);

            try
            {
                byte[] rv;
                if (cache.TryGetValue(key, out rv))
                {
                    val = BSON.Deserialize <T>(rv);
                }
                else if (Load != null)
                {
                    val = Load(key);
                }
            }
            finally { locker.ExitReadLock(); }
            return(val);
        }
Beispiel #5
0
        /// <summary>
        /// Adds or updates the specified cache-key with the specified cacheObject and applies a specified timeout (in seconds) to this key.
        /// </summary>
        /// <param name="key">The cache-key to add or update.</param>
        /// <param name="cacheObject">The cache object to store.</param>
        /// <param name="cacheTimeout">The cache timeout (lifespan) of this object. Must be 1 or greater.
        /// Specify Timeout.Infinite to keep the entry forever.</param>
        /// <param name="restartTimerIfExists">(Optional). If set to <c>true</c>, the timer for this cacheObject will be reset if the object already
        /// exists in the cache. (Default = false).</param>
        public void AddOrUpdate(K key, T cacheObject, int cacheTimeout, bool restartTimerIfExists = false)
        {
            if (disposed)
            {
                return;
            }

            if (cacheTimeout != Timeout.Infinite && cacheTimeout < 1)
            {
                throw new ArgumentOutOfRangeException("cacheTimeout must be greater than zero.");
            }

            if (memory >= MemoryLimit)
            {
                Dump();
            }

            locker.EnterWriteLock();
            try
            {
                CheckTimer(key, cacheTimeout, restartTimerIfExists);

                var b = BSON.Serialize(cacheObject);

                if (!cache.ContainsKey(key))
                {
                    memory += b.Length;
                    cache.Add(key, b);
                }
                else
                {
                    memory    -= cache[key].Length;
                    memory    += b.Length;
                    cache[key] = b;
                }
            }
            finally { locker.ExitWriteLock(); }
        }
Beispiel #6
0
        public override string ToString()
        {
            StringBuilder __sb    = new StringBuilder("LogicalType(");
            bool          __first = true;

            if (STRING != null && __isset.@STRING)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("STRING: ");
                __sb.Append(STRING == null ? "<null>" : STRING.ToString());
            }
            if (MAP != null && __isset.MAP)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("MAP: ");
                __sb.Append(MAP == null ? "<null>" : MAP.ToString());
            }
            if (LIST != null && __isset.LIST)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("LIST: ");
                __sb.Append(LIST == null ? "<null>" : LIST.ToString());
            }
            if (ENUM != null && __isset.@ENUM)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("ENUM: ");
                __sb.Append(ENUM == null ? "<null>" : ENUM.ToString());
            }
            if (DECIMAL != null && __isset.@DECIMAL)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("DECIMAL: ");
                __sb.Append(DECIMAL == null ? "<null>" : DECIMAL.ToString());
            }
            if (DATE != null && __isset.DATE)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("DATE: ");
                __sb.Append(DATE == null ? "<null>" : DATE.ToString());
            }
            if (TIME != null && __isset.TIME)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("TIME: ");
                __sb.Append(TIME == null ? "<null>" : TIME.ToString());
            }
            if (TIMESTAMP != null && __isset.TIMESTAMP)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("TIMESTAMP: ");
                __sb.Append(TIMESTAMP == null ? "<null>" : TIMESTAMP.ToString());
            }
            if (INTEGER != null && __isset.INTEGER)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("INTEGER: ");
                __sb.Append(INTEGER == null ? "<null>" : INTEGER.ToString());
            }
            if (UNKNOWN != null && __isset.UNKNOWN)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("UNKNOWN: ");
                __sb.Append(UNKNOWN == null ? "<null>" : UNKNOWN.ToString());
            }
            if (JSON != null && __isset.JSON)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("JSON: ");
                __sb.Append(JSON == null ? "<null>" : JSON.ToString());
            }
            if (BSON != null && __isset.BSON)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("BSON: ");
                __sb.Append(BSON == null ? "<null>" : BSON.ToString());
            }
            if (UUID != null && __isset.UUID)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("UUID: ");
                __sb.Append(UUID == null ? "<null>" : UUID.ToString());
            }
            __sb.Append(")");
            return(__sb.ToString());
        }
Beispiel #7
0
 public void Write(TProtocol oprot)
 {
     oprot.IncrementRecursionDepth();
     try
     {
         TStruct struc = new TStruct("LogicalType");
         oprot.WriteStructBegin(struc);
         TField field = new TField();
         if (STRING != null && __isset.@STRING)
         {
             field.Name = "STRING";
             field.Type = TType.Struct;
             field.ID   = 1;
             oprot.WriteFieldBegin(field);
             STRING.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (MAP != null && __isset.MAP)
         {
             field.Name = "MAP";
             field.Type = TType.Struct;
             field.ID   = 2;
             oprot.WriteFieldBegin(field);
             MAP.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (LIST != null && __isset.LIST)
         {
             field.Name = "LIST";
             field.Type = TType.Struct;
             field.ID   = 3;
             oprot.WriteFieldBegin(field);
             LIST.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (ENUM != null && __isset.@ENUM)
         {
             field.Name = "ENUM";
             field.Type = TType.Struct;
             field.ID   = 4;
             oprot.WriteFieldBegin(field);
             ENUM.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (DECIMAL != null && __isset.@DECIMAL)
         {
             field.Name = "DECIMAL";
             field.Type = TType.Struct;
             field.ID   = 5;
             oprot.WriteFieldBegin(field);
             DECIMAL.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (DATE != null && __isset.DATE)
         {
             field.Name = "DATE";
             field.Type = TType.Struct;
             field.ID   = 6;
             oprot.WriteFieldBegin(field);
             DATE.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (TIME != null && __isset.TIME)
         {
             field.Name = "TIME";
             field.Type = TType.Struct;
             field.ID   = 7;
             oprot.WriteFieldBegin(field);
             TIME.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (TIMESTAMP != null && __isset.TIMESTAMP)
         {
             field.Name = "TIMESTAMP";
             field.Type = TType.Struct;
             field.ID   = 8;
             oprot.WriteFieldBegin(field);
             TIMESTAMP.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (INTEGER != null && __isset.INTEGER)
         {
             field.Name = "INTEGER";
             field.Type = TType.Struct;
             field.ID   = 10;
             oprot.WriteFieldBegin(field);
             INTEGER.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (UNKNOWN != null && __isset.UNKNOWN)
         {
             field.Name = "UNKNOWN";
             field.Type = TType.Struct;
             field.ID   = 11;
             oprot.WriteFieldBegin(field);
             UNKNOWN.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (JSON != null && __isset.JSON)
         {
             field.Name = "JSON";
             field.Type = TType.Struct;
             field.ID   = 12;
             oprot.WriteFieldBegin(field);
             JSON.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (BSON != null && __isset.BSON)
         {
             field.Name = "BSON";
             field.Type = TType.Struct;
             field.ID   = 13;
             oprot.WriteFieldBegin(field);
             BSON.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (UUID != null && __isset.UUID)
         {
             field.Name = "UUID";
             field.Type = TType.Struct;
             field.ID   = 14;
             oprot.WriteFieldBegin(field);
             UUID.Write(oprot);
             oprot.WriteFieldEnd();
         }
         oprot.WriteFieldStop();
         oprot.WriteStructEnd();
     }
     finally
     {
         oprot.DecrementRecursionDepth();
     }
 }