public async Task <ProviderResult> GetProviderResultByProviderIdAndSpecificationId(string providerId, string specificationId)
        {
            if (string.IsNullOrWhiteSpace(providerId))
            {
                throw new ArgumentNullException(nameof(providerId));
            }

            if (string.IsNullOrWhiteSpace(specificationId))
            {
                throw new ArgumentNullException(nameof(specificationId));
            }

            SqlQuerySpec sqlQuerySpec = new SqlQuerySpec
            {
                QueryText  = @"SELECT *
                            FROM    c 
                            WHERE   c.documentType = 'ProviderResult'
                                    AND c.content.specification.id = @SpecificationId",
                Parameters = new SqlParameterCollection
                {
                    new SqlParameter("@SpecificationId", specificationId)
                }
            };

            ProviderResult providerResult = (await _cosmosRepository.QueryPartitionedEntity <ProviderResult>(sqlQuerySpec, partitionEntityId: providerId)).FirstOrDefault();

            return(providerResult);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <ProviderSourceDataset> > GetProviderSourceDatasetsByProviderIdsAndSpecificationId(IEnumerable <string> providerIds, string specificationId)
        {
            if (providerIds.IsNullOrEmpty())
            {
                return(Enumerable.Empty <ProviderSourceDataset>());
            }

            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));

            ConcurrentBag <ProviderSourceDataset> results = new ConcurrentBag <ProviderSourceDataset>();

            List <Task>   allTasks  = new List <Task>();
            SemaphoreSlim throttler = new SemaphoreSlim(initialCount: _engineSettings.GetProviderSourceDatasetsDegreeOfParallelism);

            foreach (string providerId in providerIds)
            {
                await throttler.WaitAsync();

                allTasks.Add(
                    Task.Run(async() =>
                {
                    try
                    {
                        SqlQuerySpec sqlQuerySpec = new SqlQuerySpec
                        {
                            QueryText  = @"SELECT     *
                                            FROM    Root r 
                                            WHERE   r.documentType = @DocumentType
                                                    AND r.content.specificationId = @SpecificationId 
                                                    AND r.deleted = false",
                            Parameters = new SqlParameterCollection
                            {
                                new SqlParameter("@DocumentType", nameof(ProviderSourceDataset)),
                                new SqlParameter("@SpecificationId", specificationId)
                            }
                        };

                        IEnumerable <ProviderSourceDataset> providerSourceDatasetResults =
                            await _cosmosRepository.QueryPartitionedEntity <ProviderSourceDataset>(sqlQuerySpec, partitionEntityId: providerId);

                        foreach (ProviderSourceDataset repoResult in providerSourceDatasetResults)
                        {
                            results.Add(repoResult);
                        }
                    }
                    finally
                    {
                        throttler.Release();
                    }
                }));
            }
            await TaskHelper.WhenAllAndThrow(allTasks.ToArray());

            return(results.AsEnumerable());
        }
Ejemplo n.º 3
0
        public async Task <User> GetUserById(string id)
        {
            Guard.IsNullOrWhiteSpace(id, nameof(id));

            SqlQuerySpec sqlQuerySpec = new SqlQuerySpec
            {
                QueryText  = "SELECT * FROM Root r WHERE r.content.userId = @UserId AND r.documentType = @DocumentType AND r.deleted = false",
                Parameters = new SqlParameterCollection
                {
                    new SqlParameter("@UserId", id),
                    new SqlParameter("@DocumentType", nameof(User))
                }
            };
            IEnumerable <User> user = await _cosmosRepository.QueryPartitionedEntity <User>(sqlQuerySpec, partitionEntityId : id);

            if (!user.AnyWithNullCheck())
            {
                return(null);
            }

            return(user.Single());
        }