Beispiel #1
0
        public async Task <List <string> > GetListAsync(string filter)
        {
            _ = filter ?? throw new ArgumentNullException(nameof(filter));

            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);

            int cnt = await chain.GetCountAsync();

            if (cnt == 0)
            {
                return(await Task.FromResult(new List <string>()));
            }

            List <string> list = new List <string>();

            while (cnt > 0)
            {
                list.AddRange(await chain.GetListAsync(filter));
                id++;
                chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
                cnt   = await chain.GetCountAsync();
            }

            list.Sort();
            return(await Task.FromResult(list));
        }
Beispiel #2
0
        public async Task <List <string> > GetListAsync()
        {
            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);

            int cnt = await chain.GetCountAsync();

            if (cnt == 0)
            {
                return(await Task.FromResult(new List <string>()));
            }

            List <string> list = new List <string>();

            while (cnt > 0)
            {
                list.AddRange(await chain.GetListAsync());
                id++;
                chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
                cnt   = await chain.GetCountAsync();
            }

            list.Sort();
            return(await Task.FromResult(list));
        }
Beispiel #3
0
        public async Task <List <string> > GetListAsync(int index, int pageSize, string filter)
        {
            if (index < 0)
            {
                throw new IndexOutOfRangeException(nameof(index));
            }

            if (pageSize < 0)
            {
                throw new IndexOutOfRangeException(nameof(pageSize));
            }

            _ = filter ?? throw new ArgumentNullException(nameof(filter));

            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);

            int cnt = await chain.GetCountAsync();

            if (cnt == 0)
            {
                return(await Task.FromResult(new List <string>()));
            }

            List <string> list = new List <string>();

            while (cnt > 0)
            {
                int filterCount = +await chain.GetCountAsync(filter);

                if (index > filterCount)
                {
                    id++;
                    chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
                    cnt   = await chain.GetCountAsync();
                }
                else
                {
                    int           stdIndex  = index - (Convert.ToInt32(id) - 1) * 1000;
                    List <string> chainList = await chain.GetListAsync(filter);

                    if (pageSize <= filterCount - index)
                    {
                        list.AddRange(chainList.Skip(stdIndex).Take(pageSize));
                        return(await Task.FromResult(list));
                    }

                    if (pageSize > filterCount - index)
                    {
                        list.AddRange(chainList.Skip(stdIndex).Take(filterCount - index));
                        pageSize -= filterCount - index;
                    }
                }
            }

            return(await Task.FromResult(list));
        }
Beispiel #4
0
        public async Task <bool> RemoveAsync(string resourceUriString)
        {
            bool result = false;

            if (State.Container.Contains(resourceUriString))
            {
                result = State.Container.Remove(resourceUriString);
                await ChainupAsync();

                return(await Task.FromResult(result));
            }

            while (!result)
            {
                long nextId = State.Id;
                nextId++;

                ISigmaAlgebraChain nextChain = GrainFactory.GetGrain <ISigmaAlgebraChain>(nextId);
                int cnt = await nextChain.GetCountAsync();

                if (cnt == 0)
                {
                    break;
                }

                result = await nextChain.RemoveAsync(resourceUriString);
            }

            if (result)
            {
                await ChainupAsync();
            }

            return(await Task.FromResult(result));
        }
Beispiel #5
0
        public async Task <bool> ContainsAsync(string resourceUriString)
        {
            _ = resourceUriString ?? throw new ArgumentNullException(nameof(resourceUriString));

            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);

            if (await chain.ContainsAsync(resourceUriString))
            {
                return(await Task.FromResult(true));
            }

            int cnt = await chain.GetCountAsync();

            while (cnt > 0)
            {
                id++;
                chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
                if (await chain.ContainsAsync(resourceUriString))
                {
                    return(await Task.FromResult(true));
                }
            }

            return(await Task.FromResult(false));
        }
Beispiel #6
0
        public async Task <int> GetCountAsync()
        {
            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
            int cnt = await chain.GetCountAsync();

            int total = cnt;

            while (cnt > 0)
            {
                id++;
                chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
                cnt   = await chain.GetCountAsync();

                total += cnt;
            }

            return(await Task.FromResult(total));
        }
Beispiel #7
0
        public async Task ClearAsync()
        {
            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
            int cnt = await chain.GetCountAsync();

            while (cnt > 0)
            {
                await chain.ClearAsync();

                id++;
                chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
                cnt   = await chain.GetCountAsync();
            }

            await logger?.LogInformationAsync("SigmaAlgebra cleared.");

            await ClearStateAsync();
        }
Beispiel #8
0
        public async Task ChainupAsync()
        {
            if (State.Container.Count == 0)
            {
                return;
            }

            long nextId = State.Id;

            nextId++;

            ISigmaAlgebraChain nextChain = GrainFactory.GetGrain <ISigmaAlgebraChain>(nextId);
            int count     = State.Container.Count;
            int nextCount = await nextChain.GetCountAsync();

            if (count <= 1000 && nextCount > 0)
            {
                List <string> list = await nextChain.GetListAsync();

                int qty   = 1000 - count;
                int delta = qty > list.Count ? list.Count : qty;

                for (int i = 0; i < delta; i++)
                {
                    State.Container.Add(list[i]);
                    await nextChain.RemoveAsync(list[i]);
                }

                nextCount = await nextChain.GetCountAsync();

                if (nextCount > 0)
                {
                    await nextChain.ChainupAsync();
                }
            }
        }
Beispiel #9
0
        public async Task <ListContinuationToken> GetListAsync(ListContinuationToken token)
        {
            _ = token ?? throw new ArgumentNullException(nameof(token));

            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);

            _ = token.Filter != null ? await chain.GetCountAsync(token.Filter) : await chain.GetCountAsync();

            if (token.Filter != null)
            {
                List <string> filterItems = await GetListAsync(token.Index, token.PageSize, token.Filter);

                return(await Task.FromResult(new ListContinuationToken(token.Index + filterItems.Count, token.Quantity,
                                                                       token.PageSize, token.Filter, filterItems)));
            }

            List <string> items = await GetListAsync(token.Index, token.PageSize);

            return(await Task.FromResult(new ListContinuationToken(token.Index + items.Count, token.Quantity,
                                                                   token.PageSize, items)));
        }
Beispiel #10
0
        public async Task <bool> AddAsync(string resourceUriString)
        {
            _ = resourceUriString ?? throw new ArgumentNullException(nameof(resourceUriString));

            if (State.Container.Count < 1000 && !State.Container.Contains(resourceUriString))
            {
                State.Container.Add(resourceUriString);
                return(await Task.FromResult(true));
            }

            long nextId = State.Id;

            nextId++;

            ISigmaAlgebraChain nextChain = GrainFactory.GetGrain <ISigmaAlgebraChain>(nextId);

            while (await nextChain.GetCountAsync() >= 1000)
            {
                if (await nextChain.ContainsAsync(resourceUriString))
                {
                    return(await Task.FromResult(false));
                }

                nextId++;
                nextChain = GrainFactory.GetGrain <ISigmaAlgebraChain>(nextId);
            }

            if (await nextChain.ContainsAsync(resourceUriString))
            {
                return(await Task.FromResult(false));
            }

            bool result = await nextChain.AddAsync(resourceUriString);

            return(await Task.FromResult(result));
        }