コード例 #1
0
        public void GivenProperTypeAndCollectionWhenCollectionHandleInstantiatedThenShouldSetProperties()
        {
            var target = new CollectionHandle(dbType, products);

            Assert.Same(dbType, target.DbContextType);
            Assert.Same(products, target.Collection);
        }
コード例 #2
0
ファイル: Collection.cs プロジェクト: solyutor/ejdb-csharp
 /// <summary>
 /// Closes collection and disposes all owned resources
 /// </summary>
 public void Dispose()
 {
     if (CollectionHandle != null)
     {
         CollectionHandle.Dispose();
         CollectionHandle = null;
         _functions       = null;
         _serializer      = null;
     }
 }
コード例 #3
0
ファイル: Collection.cs プロジェクト: solyutor/ejdb-csharp
        //Creates new;
        private Collection(Database database, string name, Func <CollectionHandle> generator)
        {
            Database         = database;
            _name            = name;
            CollectionHandle = generator();

            _functions = database.Library.Functions.Collection;

            Serializer = database.Serializer;
        }
コード例 #4
0
        /// <summary>
        /// Pipeline to filter properly structured requests.
        /// </summary>
        /// <param name="httpContext">The <see cref="HttpContext"/>.</param>
        /// <param name="provider">The <see cref="IServiceProvider"/>.</param>
        /// <returns>A value indicating whether or not the pipeline was processed.</returns>
        private async Task <bool> FilterPipelineAsync(HttpContext httpContext, IServiceProvider provider)
        {
            if (httpContext.Request.Method != HttpMethods.Post)
            {
                return(false);
            }

            var path = httpContext.Request.RouteValues;

            var logger = provider.GetService(typeof(ILogger <ExpressionPowerToolsEFCoreMiddleware>))
                         as ILogger <ExpressionPowerToolsEFCoreMiddleware>;

            logger.LogInformation($"{nameof(ExpressionPowerToolsEFCoreMiddleware)} processing path {httpContext.Request.Path}.");

            var(context, collection) = routeProcessor.Value.ParseRoute(httpContext.Request.RouteValues);

            if (string.IsNullOrWhiteSpace(context) ||
                string.IsNullOrWhiteSpace(collection))
            {
                logger.LogWarning($"No context or collection found in path {path}.");
                return(false);
            }

            if (!adapter.Value.TryGetContext(
                    contextTypes,
                    context,
                    out Type dbContextType))
            {
                logger.LogWarning($"{context} is not an registered DbContext.");
                return(false);
            }

            if (!adapter.Value.TryGetDbSet(
                    dbContextType,
                    collection,
                    out PropertyInfo dbSet))
            {
                logger.LogWarning($"{collection} DbSet on DbContext {context} not found.");
                return(false);
            }

            var handle = new CollectionHandle(dbContextType, dbSet);

            await ProcessQueryAsync(httpContext, handle, provider);

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Task to process the query.
        /// </summary>
        /// <param name="httpContext">The <see cref="HttpContext"/>.</param>
        /// <param name="handle">The handle to the set to process.</param>
        /// <param name="provider">The service provider.</param>
        /// <returns>A <see cref="Task"/> for asynchronous processing.</returns>
        private async Task ProcessQueryAsync(
            HttpContext httpContext,
            CollectionHandle handle,
            IServiceProvider provider)
        {
            var dbContext = provider.GetService(handle.DbContextType) as DbContext;

            Ensure.VariableNotNull(() => dbContext);
            var rootQuery = adapter.Value.CreateQuery(dbContext, handle.Collection);
            var result    = await deserializer.Value.DeserializeAsync(
                rootQuery, httpContext.Request.Body, (ILogger)provider.GetService(typeof(ILogger <IQueryDeserializer>)));

            Ensure.VariableNotNull(() => result);
            await serializer.Value.SerializeAsync(
                httpContext.Response.Body,
                result.Query,
                result.QueryType);
        }