public static async Task <IEnumerable <ReliableStateInfo> > GetAllStates(this IReliableStateManager stateManager, CancellationToken ct = default(CancellationToken)) { var states = new List <ReliableStateInfo>(); using (var tx = stateManager.CreateTransaction()) { var enumerable = stateManager.GetAsyncEnumerator(); while (await enumerable.MoveNextAsync(ct)) { var reliableStateInfo = new ReliableStateInfo() { Name = enumerable.Current.Name.ToString(), Count = -1 }; var conditionalValue = await stateManager.TryGetAsync <IReliableState>(enumerable.Current.Name); if (conditionalValue.HasValue) { var rsi = await conditionalValue.Value.GetCount(tx); reliableStateInfo.Count = rsi.Count; reliableStateInfo.Type = rsi.Type; } states.Add(reliableStateInfo); } } return(states); }
public async Task ClearAsync(params string[] storeNames) { var enumerator = _stateManager.GetAsyncEnumerator(); while (await enumerator.MoveNextAsync(CancellationToken.None)) { if (storeNames.Contains(enumerator.Current.Name.LocalPath)) { await _stateManager.RemoveAsync(enumerator.Current.Name.LocalPath); } } }
private static async Task <int> GetReliableStateCountAsync(IReliableStateManager stateManager) { int count = 0; var enumerator = stateManager.GetAsyncEnumerator(); while (await enumerator.MoveNextAsync(CancellationToken.None)) { count++; } return(count); }
/// <summary> /// Get the names and types of the reliable collections that are queryable from the reliable state manager. /// </summary> /// <param name="stateManager">Reliable state manager for the replica.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>The names and value types of the reliable collections that are queryable.</returns> private static async Task <IEnumerable <KeyValuePair <string, Type> > > GetQueryableTypes(this IReliableStateManager stateManager, CancellationToken cancellationToken = default(CancellationToken)) { var types = new Dictionary <string, Type>(); var enumerator = stateManager.GetAsyncEnumerator(); while (await enumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false)) { var state = enumerator.Current; if (state.ImplementsGenericType(typeof(IReliableDictionary <,>))) { types.Add(state.Name.AbsolutePath, state.GetValueType()); } } return(types); }
/// <summary> /// Get the names, ypes and count of the reliable collections that are queryable from the reliable state manager. /// </summary> /// <param name="stateManager">Reliable state manager for the replica.</param> /// <returns>Reliable.</returns> public static async Task <List <string> > GetMetadataAsync(this IReliableStateManager stateManager) { List <string> metadataList = new List <string>(); using (IAsyncEnumerator <IReliableState> reliableStatesEnumerator = stateManager.GetAsyncEnumerator()) { while (await reliableStatesEnumerator.MoveNextAsync(CancellationToken.None)) { IReliableState reliableState = reliableStatesEnumerator.Current; ReliableStateMetadata metadata = new ReliableStateMetadata { Name = reliableState.Name.AbsolutePath, Type = reliableState.GetType().Name, Count = await GetCount(stateManager, reliableState) }; metadataList.Add(metadata.ToString()); } } // Return the data as json string return(metadataList); }