Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static async Task <ReliableStateInfo> GetCount(this IReliableState state, ITransaction tx)
        {
            var reliableStateInfo = new ReliableStateInfo();

            var type = state.GetType();

            reliableStateInfo.Type = type.GetFriendlyName();

            var methodInfo = state.GetType().GetMethod("GetCountAsync", new Type[] { typeof(ITransaction) }) ??
                             state.GetType().GetMethods().FirstOrDefault(m => m.Name == "GetCountAsync" && m.GetParameters().Length == 1);

            if (methodInfo != null)
            {
                var countTask = (Task <long>)methodInfo.Invoke(state, new object[] { tx });
                var count     = await countTask;
                reliableStateInfo.Count = count;
            }
            return(reliableStateInfo);
        }