Пример #1
0
    static GlobalFilters BuildFilters()
    {
        var filters = new GlobalFilters();

        filters.Add <FilterParentEntity>((context, item) => item.Property != "Ignore");
        filters.Add <FilterChildEntity>((context, item) => item.Property != "Ignore");
        return(filters);
    }
    public void Simple()
    {
        GlobalFilters.Add <Target>((o, target) => target.Property != "Ignore");
        Assert.True(GlobalFilters.ShouldInclude(null, new Target()));
        Assert.False(GlobalFilters.ShouldInclude(null, null));
        Assert.True(GlobalFilters.ShouldInclude(null, new Target {
            Property = "Include"
        }));
        Assert.False(GlobalFilters.ShouldInclude(null, new Target {
            Property = "Ignore"
        }));

        GlobalFilters.Add <BaseTarget>((o, target) => target.Property != "Ignore");
        Assert.True(GlobalFilters.ShouldInclude(null, new ChildTarget()));
        Assert.True(GlobalFilters.ShouldInclude(null, new ChildTarget {
            Property = "Include"
        }));
        Assert.False(GlobalFilters.ShouldInclude(null, new ChildTarget {
            Property = "Ignore"
        }));

        GlobalFilters.Add <ITarget>((o, target) => target.Property != "Ignore");
        Assert.True(GlobalFilters.ShouldInclude(null, new ImplementationTarget()));
        Assert.True(GlobalFilters.ShouldInclude(null, new ImplementationTarget {
            Property = "Include"
        }));
        Assert.False(GlobalFilters.ShouldInclude(null, new ImplementationTarget {
            Property = "Ignore"
        }));

        Assert.True(GlobalFilters.ShouldInclude(null, new NonTarget {
            Property = "Foo"
        }));
    }
Пример #3
0
    static IntegrationTests()
    {
        GlobalFilters.Add <FilterParentEntity>((context, item) => item.Property != "Ignore");
        GlobalFilters.Add <FilterChildEntity>((context, item) => item.Property != "Ignore");

        using (var dataContext = BuildDataContext())
        {
            dataContext.Database.EnsureCreated();
        }
    }
Пример #4
0
        public Server()
        {
            Console.Title = "FastWebSocketServer";
            GlobalFilters.Add(new ExceptionFilterAttribute());
            this.BindService <CpuCounterService>();
            this.StartListen(8282);
            Console.WriteLine("FastWebSocketServer服务已启动,端口:" + this.LocalEndPoint.Port);

            CpuCounter.CpuTimeChanged += CpuCounter_CpuTimeChanged;
        }
    public void Add(ServiceCollection services, IModel model)
    {
        #region add-filter

        var filters = new GlobalFilters();
        filters.Add <MyEntity>(
            (userContext, item) =>
        {
            return(item.Property != "Ignore");
        });
        EfGraphQLConventions.RegisterInContainer(services, model, filters);

        #endregion
    }
        /// <summary>
        ///     Creates and return a filter associated with the specified key added for the context.
        /// </summary>
        /// <typeparam name="T">The type of elements of the query.</typeparam>
        /// <param name="key">The filter key associated to the filter.</param>
        /// <param name="queryFilter">The query filter to apply to the the context.</param>
        /// <param name="isEnabled">true if the filter is enabled.</param>
        /// <returns>The filter created and added to the the context.</returns>
        public static BaseQueryFilter Filter <T>(object key, Func <IQueryable <T>, IQueryable <T> > queryFilter, bool isEnabled = true)
        {
            BaseQueryFilter filter;

            if (!GlobalFilters.TryGetValue(key, out filter))
            {
                filter = new QueryFilter <T>(null, queryFilter)
                {
                    IsDefaultEnabled = isEnabled
                };
                GlobalFilters.Add(key, filter);
            }

            return(filter);
        }
    public async Task Simple()
    {
        var filters = new GlobalFilters();

        filters.Add <Target>((o, target) => target.Property != "Ignore");
        Assert.True(await filters.ShouldInclude(null, new Target()));
        Assert.False(await filters.ShouldInclude <object>(null, null));
        Assert.True(await filters.ShouldInclude(null, new Target {
            Property = "Include"
        }));
        Assert.False(await filters.ShouldInclude(null, new Target {
            Property = "Ignore"
        }));

        filters.Add <BaseTarget>((o, target) => target.Property != "Ignore");
        Assert.True(await filters.ShouldInclude(null, new ChildTarget()));
        Assert.True(await filters.ShouldInclude(null, new ChildTarget {
            Property = "Include"
        }));
        Assert.False(await filters.ShouldInclude(null, new ChildTarget {
            Property = "Ignore"
        }));

        filters.Add <ITarget>((o, target) => target.Property != "Ignore");
        Assert.True(await filters.ShouldInclude(null, new ImplementationTarget()));
        Assert.True(await filters.ShouldInclude(null, new ImplementationTarget {
            Property = "Include"
        }));
        Assert.False(await filters.ShouldInclude(null, new ImplementationTarget {
            Property = "Ignore"
        }));

        Assert.True(await filters.ShouldInclude(null, new NonTarget {
            Property = "Foo"
        }));
    }
Пример #8
0
        static void Main(string[] args)
        {
            Console.Title = "LuceneServer";

            GlobalFilters.Add(new ExceptionFilter());
            var server = new LnServer();

            server.BindService <LnService>().BindService <SystemService>();
            server.StartListen(int.Parse(ConfigurationManager.AppSettings["Port"]));

            Console.WriteLine("服务监听中:端口" + server.LocalEndPoint.Port);
            while (true)
            {
                Console.ReadLine();
            }
        }
Пример #9
0
        static void Main(string[] args)
        {
            GlobalFilters.Add(new ExceptionFilterAttribute());

            var fastServer = new FastServer();

            fastServer.Serializer = new FastJsonSerializer();
            fastServer.BindService(fastServer.GetType().Assembly);
            fastServer.RegisterResolver();
            fastServer.StartListen(1350);

            Console.Title = "FastServer V" + new SystemService().GetVersion();
            Console.WriteLine("服务已启动,端口:" + fastServer.LocalEndPoint.Port);
            while (true)
            {
                Console.ReadLine();
            }
        }
Пример #10
0
        /// <summary>
        ///     Creates and return a filter associated with the specified key added for the context.
        /// </summary>
        /// <typeparam name="T">The type of elements of the query.</typeparam>
        /// <param name="key">The filter key associated to the filter.</param>
        /// <param name="queryFilter">The query filter to apply to the the context.</param>
        /// <param name="isEnabled">true if the filter is enabled.</param>
        /// <returns>The filter created and added to the the context.</returns>
        public static AliasBaseQueryFilter Filter <T>(object key, Func <IQueryable <T>, IQueryable <T> > queryFilter, bool isEnabled = true)
        {
            AliasBaseQueryFilter filter;

            if (!GlobalFilters.TryGetValue(key, out filter))
            {
#if EF6
                filter = new QueryDbSetFilter <T>(null, queryFilter)
                {
                    IsDefaultEnabled = isEnabled
                };
#else
                filter = new QueryFilter <T>(null, queryFilter)
                {
                    IsDefaultEnabled = isEnabled
                };
#endif
                GlobalFilters.Add(key, filter);
            }

            return(filter);
        }
Пример #11
0
 /// <summary>
 /// Adds the global async filter.
 /// </summary>
 /// <param name="filter">The filter.</param>
 /// <returns>Instance of this options</returns>
 public LiteApiOptions AddGlobalFilter(IApiFilterAsync filter)
 {
     GlobalFilters.Add(new ApiFilterWrapper(filter));
     return(this);
 }