/// <summary> /// Clears component state. /// </summary> private void Cleanup() { if (this._timeout == 0) { return; } long cutOffTime = DateTimeOffset.Now.ToUnixTimeMilliseconds() - _timeout; // Cleanup obsolete entries foreach (var prop in this._states.Keys) { StateEntry entry = this._states[prop]; // Remove obsolete entry if (entry.GetLastUpdateTime() < cutOffTime) { _states.Remove(prop); } } }
/// <summary> /// Loads state from the store using its key. /// If value is missing in the store it returns null. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <param name="key">a unique state key.</param> /// <returns>the state value or null if value wasn't found.</returns> public async Task <T> LoadAsync <T>(string correlationId, string key) { if (key == null) { throw new Exception("Key cannot be null"); } // Cleanup the stored states Cleanup(); // Get entry from the store StateEntry entry = _states.ContainsKey(key) ? _states[key] : null; // Store has nothing if (entry == null) { return(default(T)); } return(entry.GetValue()); }