Пример #1
0
        internal CosmosClient BindForClient(CosmosAttribute attribute)
        {
            string         resolvedConnectionString = ResolveConnectionString(attribute.ConnectionStringSetting);
            ICosmosService service = GetService(resolvedConnectionString, attribute.ApplicationName, attribute.ApplicationRegion);

            return(service.GetClient());
        }
Пример #2
0
        public async Task <IEnumerable <T> > ConvertAsync(CosmosAttribute attribute, CancellationToken cancellationToken)
        {
            CosmosContext context = configProvider.CreateContext(attribute);

            List <T> finalResults = new List <T>();

            string continuation = null;

            QueryDefinition query = new QueryDefinition(context.ResolvedAttribute.SqlQuery);

            if ((context.ResolvedAttribute.SqlQueryParameters?.Count ?? 0) > 0)
            {
                foreach (var parameter in context.ResolvedAttribute.SqlQueryParameters)
                {
                    query = query.WithParameter(parameter.Key, parameter.Value);
                }
            }

            var response = context.Service.GetItemQueryIterator <T>(context.ResolvedAttribute.DatabaseName, context.ResolvedAttribute.ContainerName, query);

            do
            {
                await foreach (var page in response.AsPages(continuation))
                {
                    finalResults.AddRange(page.Values);
                    continuation = page.ContinuationToken;
                }
            }while (!string.IsNullOrEmpty(continuation));

            return(finalResults);
        }
Пример #3
0
 internal void ValidateConnection(CosmosAttribute attribute, Type paramType)
 {
     if (string.IsNullOrEmpty(options.ConnectionString) &&
         string.IsNullOrEmpty(attribute.ConnectionStringSetting))
     {
         string attributeProperty = $"{nameof(CosmosAttribute)}.{nameof(CosmosAttribute.ConnectionStringSetting)}";
         string optionsProperty   = $"{nameof(CosmosOptions)}.{nameof(CosmosOptions.ConnectionString)}";
         throw new InvalidOperationException(
                   $"The Cosmos connection string must be set either via the '{Constants.DefaultConnectionStringName}' IConfiguration connection string, via the {attributeProperty} property or via {optionsProperty}.");
     }
 }
Пример #4
0
        internal CosmosContext CreateContext(CosmosAttribute attribute)
        {
            string resolvedConnectionString = ResolveConnectionString(attribute.ConnectionStringSetting);

            ICosmosService service = GetService(resolvedConnectionString, attribute.ApplicationName, attribute.ApplicationRegion);

            return(new CosmosContext
            {
                Service = service,
                ResolvedAttribute = attribute,
            });
        }
Пример #5
0
        internal Task <IValueBinder> BindForItemAsync(CosmosAttribute attribute, Type type)
        {
            if (string.IsNullOrEmpty(attribute.Id))
            {
                throw new InvalidOperationException("The 'Id' property of a Cosmos single-item input binding cannot be null or empty.");
            }

            CosmosContext context = CreateContext(attribute);

            Type         genericType = typeof(CosmosItemValueBinder <>).MakeGenericType(type);
            IValueBinder binder      = (IValueBinder)Activator.CreateInstance(genericType, context);

            return(Task.FromResult(binder));
        }
        public IAsyncCollector <T> Convert(CosmosAttribute attribute)
        {
            CosmosContext context = configProvider.CreateContext(attribute);

            return(new CosmosAsyncCollector <T>(context));
        }