Exemplo n.º 1
0
        public async Task <bool> AddAsync(string resourceUriString)
        {
            long id = 1;
            ISigmaAlgebraChain chain = GrainFactory.GetGrain <ISigmaAlgebraChain>(id);
            bool result = await chain.AddAsync(resourceUriString);

            await logger?.LogInformationAsync($"SigmaAlgebra add '{result}' for '{resourceUriString}'");

            return(await Task.FromResult(result));
        }
Exemplo n.º 2
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));
        }