コード例 #1
0
        private static void UseLuceneSearch(IHostEnvironment env, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions)
        {
            Task.Run(() =>
            {
                Console.WriteLine("正在导入自定义词库...");
                double time = HiPerfTimer.Execute(() =>
                {
                    var lines     = File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomKeywords.txt"));
                    var segmenter = new JiebaSegmenter();
                    foreach (var word in lines)
                    {
                        segmenter.AddWord(word);
                    }
                });
                Console.WriteLine($"导入自定义词库完成,耗时{time}s");
            });

            string lucenePath = Path.Combine(env.ContentRootPath, luceneIndexerOptions.Path);

            if (!Directory.Exists(lucenePath) || Directory.GetFiles(lucenePath).Length < 1)
            {
                Console.WriteLine("索引库不存在,开始自动创建Lucene索引库...");
                hangfire.CreateLuceneIndex();
                Console.WriteLine("索引库创建完成!");
            }
        }
コード例 #2
0
        internal static void UseLuceneSearch(this IApplicationBuilder app, IHostEnvironment env, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions)
        {
            Task.Run(() =>
            {
                Console.WriteLine("正在导入自定义词库...");
                double time = HiPerfTimer.Execute(() =>
                {
                    var posts     = app.ApplicationServices.GetRequiredService <DataContext>().Post;
                    var set       = posts.Select(p => p.Title).AsEnumerable().SelectMany(s => s.Split(',', ',', ' ', '+', '—', '(', ')', ':', '&', '(', ')', '-', '_', '[', ']')).Where(s => s.Length > 1).Union(posts.Select(p => $"{p.Label},{p.Keyword}").AsEnumerable().SelectMany(s => s.Split(','))).ToHashSet();
                    var lines     = File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomKeywords.txt")).Union(set);
                    var segmenter = new JiebaSegmenter();
                    foreach (var word in lines)
                    {
                        segmenter.AddWord(word);
                    }
                });
                Console.WriteLine($"导入自定义词库完成,耗时{time}s");
                Windows.ClearMemorySilent();
            });

            string lucenePath = Path.Combine(env.ContentRootPath, luceneIndexerOptions.Path);

            if (!Directory.Exists(lucenePath) || Directory.GetFiles(lucenePath).Length < 1)
            {
                Console.WriteLine("索引库不存在,开始自动创建Lucene索引库...");
                hangfire.CreateLuceneIndex();
                Console.WriteLine("索引库创建完成!");
            }
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: fengyeju/Masuit.MyBlogs
        private static void UseLuceneSearch(IHostEnvironment env, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions)
        {
            Task.Run(() =>
            {
                Console.WriteLine("正在导入自定义词库...");
                double time = HiPerfTimer.Execute(() =>
                {
                    var set       = ServiceProvider.GetRequiredService <DataContext>().Post.Select(p => $"{p.Title},{p.Label},{p.Keyword}").AsEnumerable().SelectMany(s => s.Split(new[] { ',', ' ', '+', '—' }, StringSplitOptions.RemoveEmptyEntries)).ToHashSet();
                    var lines     = File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomKeywords.txt")).Union(set);
                    var segmenter = new JiebaSegmenter();
                    foreach (var word in lines)
                    {
                        segmenter.AddWord(word);
                    }
                });
                Console.WriteLine($"导入自定义词库完成,耗时{time}s");
            });

            string lucenePath = Path.Combine(env.ContentRootPath, luceneIndexerOptions.Path);

            if (!Directory.Exists(lucenePath) || Directory.GetFiles(lucenePath).Length < 1)
            {
                Console.WriteLine("索引库不存在,开始自动创建Lucene索引库...");
                hangfire.CreateLuceneIndex();
                Console.WriteLine("索引库创建完成!");
            }
        }
コード例 #4
0
        /// <summary>
        /// Configure
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="db"></param>
        /// <param name="hangfire"></param>
        /// <param name="luceneIndexerOptions"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, DataContext db, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                //app.UseHsts();
                app.UseException();
            }

            //db.Database.Migrate();

            #region 导词库

            Console.WriteLine("正在导入自定义词库...");
            double time = HiPerfTimer.Execute(() =>
            {
                var lines     = File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomKeywords.txt"));
                var segmenter = new JiebaSegmenter();
                foreach (var word in lines)
                {
                    segmenter.AddWord(word);
                }
            });
            Console.WriteLine($"导入自定义词库完成,耗时{time}s");

            #endregion

            string lucenePath = Path.Combine(env.ContentRootPath, luceneIndexerOptions.Path);
            if (!Directory.Exists(lucenePath) || Directory.GetFiles(lucenePath).Length < 1)
            {
                Console.WriteLine(",索引库不存在,开始自动创建Lucene索引库...");
                hangfire.CreateLuceneIndex();
                Console.WriteLine("索引库创建完成!");
            }

            app.UseResponseCompression();
            app.UseHttpsRedirection().UseRewriter(new RewriteOptions().AddRedirectToNonWww()); // URL重写
            app.UseStaticHttpContext();                                                        //注入静态HttpContext对象

            app.UseSession().UseCookiePolicy();                                                //注入Session

            app.UseStaticFiles(new StaticFileOptions                                           //静态资源缓存策略
            {
                OnPrepareResponse = context =>
                {
                    context.Context.Response.Headers[HeaderNames.CacheControl] = "public,no-cache";
                    context.Context.Response.Headers[HeaderNames.Expires]      = DateTime.UtcNow.AddDays(7).ToString("R");
                },
                ContentTypeProvider = new FileExtensionContentTypeProvider(MimeMapper.MimeTypes),
            });

            app.UseFirewall().UseRequestIntercept();                                                //启用网站防火墙
            CommonHelper.SystemSettings = db.SystemSetting.ToDictionary(s => s.Name, s => s.Value); //初始化系统设置参数

            app.UseHangfireServer().UseHangfireDashboard("/taskcenter", new DashboardOptions()
            {
                Authorization = new[]
                {
                    new MyRestrictiveAuthorizationFilter()
                }
            }); //配置hangfire
            app.UseCors(builder =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowAnyOrigin();
                builder.AllowCredentials();
            });                       //配置跨域
            app.UseResponseCaching(); //启动Response缓存
            app.UseSignalR(hub => hub.MapHub <MyHub>("/hubs"));
            HangfireJobInit.Start();  //初始化定时任务
            app.UseMvcWithDefaultRoute();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            #region 配置automapper

            var mapper = new MapperConfiguration(e =>
            {
                e.CreateMap <TestClassA, TestClassB>().ReverseMap();
                e.CreateMap <TestClassC, TestClassD>().ReverseMap();
            }).CreateMapper();

            #endregion

            #region 配置ExpressionMapper

            ExpressionMapper.CreateMap <TestClassA, TestClassB>().ReverseMap();
            ExpressionMapper.CreateMap <TestClassC, TestClassD>().ReverseMap();

            #endregion

            #region  一个大对象

            var a = new TestClassA()
            {
                MyProperty = "ssssssssssssssssssssss",
                DateTime   = DateTime.Now,
                Double     = 123.33,
                Int        = 100,
                TestClassC = new TestClassC()
                {
                    MyProperty = "ccccccccccccccccccccccccccc",
                    DateTime   = DateTime.Now,
                    Double     = 2345.555,
                    Int        = 10100,
                    Obj        = new TestClassD()
                    {
                        MyProperty = "ddddddddddddddddddddddddd",
                        Obj        = new TestClassC()
                        {
                            MyProperty = "cccccc",
                            DateTime   = DateTime.Now,
                            Double     = 23458894.555,
                            Int        = 10100000,
                            Obj        = new TestClassD()
                        }
                    }
                },
                List = new List <TestClassC>()
                {
                    new TestClassC()
                    {
                        MyProperty = "cccccc",
                        DateTime   = DateTime.Now,
                        Double     = 2345.555,
                        Int        = 10100,
                        Obj        = new TestClassD()
                        {
                            MyProperty = "ddddddddddddddddddddddddddddddddddd",
                            DateTime   = DateTime.Now,
                            Double     = 2345.555,
                            Int        = 10100,
                            Obj        = new TestClassC()
                            {
                                MyProperty = "cccccccccccccccccccccccccccccc",
                                DateTime   = DateTime.Now,
                                Double     = 2345.555,
                                Int        = 10100,
                                Obj        = new TestClassD()
                            }
                        }
                    },
                    new TestClassC()
                    {
                        MyProperty = "cccccc",
                        DateTime   = DateTime.Now,
                        Double     = 2345.555,
                        Int        = 10100,
                        Obj        = new TestClassD()
                        {
                            MyProperty = "ddddddddddddddddddddddddddddddddddd",
                            DateTime   = DateTime.Now,
                            Double     = 2345.555,
                            Int        = 10100,
                            Obj        = new TestClassC()
                            {
                                MyProperty = "cccccccccccccccccccccccccccccc",
                                DateTime   = DateTime.Now,
                                Double     = 2345.555,
                                Int        = 10100,
                                Obj        = new TestClassD()
                            }
                        }
                    },
                    new TestClassC()
                    {
                        MyProperty = "cccccc",
                        DateTime   = DateTime.Now,
                        Double     = 2345.555,
                        Int        = 10100,
                        Obj        = new TestClassD()
                        {
                            MyProperty = "ddddddddddddddddddddddddddddddddddd",
                            DateTime   = DateTime.Now,
                            Double     = 2345.555,
                            Int        = 10100,
                            Obj        = new TestClassC()
                            {
                                MyProperty = "cccccccccccccccccccccccccccccc",
                                DateTime   = DateTime.Now,
                                Double     = 2345.555,
                                Int        = 10100,
                                Obj        = new TestClassD()
                            }
                        }
                    },
                    new TestClassC()
                    {
                        MyProperty = "cccccc",
                        DateTime   = DateTime.Now,
                        Double     = 2345.555,
                        Int        = 10100,
                        Obj        = new TestClassD()
                        {
                            MyProperty = "ddddddddddddddddddddddddddddddddddd",
                            DateTime   = DateTime.Now,
                            Double     = 2345.555,
                            Int        = 10100,
                            Obj        = new TestClassC()
                            {
                                MyProperty = "cccccccccccccccccccccccccccccc",
                                DateTime   = DateTime.Now,
                                Double     = 2345.555,
                                Int        = 10100,
                                Obj        = new TestClassD()
                            }
                        }
                    },
                    new TestClassC()
                    {
                        MyProperty = "cccccc",
                        DateTime   = DateTime.Now,
                        Double     = 2345.555,
                        Int        = 10100,
                        Obj        = new TestClassD()
                        {
                            MyProperty = "ddddddddddddddddddddddddddddddddddd",
                            DateTime   = DateTime.Now,
                            Double     = 2345.555,
                            Int        = 10100,
                            Obj        = new TestClassC()
                            {
                                MyProperty = "cccccccccccccccccccccccccccccc",
                                DateTime   = DateTime.Now,
                                Double     = 2345.555,
                                Int        = 10100,
                                Obj        = new TestClassD()
                            }
                        }
                    },
                }
            };

            #endregion

            var time = HiPerfTimer.Execute(() =>
            {
                a.Map <TestClassA, TestClassB>();
                a.Map <TestClassA, TestClassB>();
            });
            Console.WriteLine($"ExpressionMapper映射2次耗时:{time}s");
            time = HiPerfTimer.Execute(() =>
            {
                for (int i = 0; i < 1000000; i++)
                {
                    var b = a.Map <TestClassA, TestClassB>();
                }
            });
            Console.WriteLine($"ExpressionMapper映射100000次耗时:{time}s");

            time = HiPerfTimer.Execute(() =>
            {
                mapper.Map <TestClassB>(a);
                mapper.Map <TestClassB>(a);
            });
            Console.WriteLine($"AutoMapper映射2次耗时:{time}s");
            time = HiPerfTimer.Execute(() =>
            {
                for (int i = 0; i < 1000000; i++)
                {
                    var b = mapper.Map <TestClassB>(a);
                }
            });
            Console.WriteLine($"AutoMapper映射100000次耗时:{time}s");
        }