Ejemplo n.º 1
0
        public static void Register()
        {
            #region Hangfire配置

            //GlobalConfiguration.Configuration.UseMemoryStorage();
            GlobalConfiguration.Configuration.UseSqlServerStorage(ConfigurationManager.ConnectionStrings[QuickDbProvider.GetProviderName()].ConnectionString).UseConsole();

            #region 实现类注册

            GlobalConfiguration.Configuration.UseAutofacActivator(AutofacConfig.Container);

            #endregion

            #region  务启动

            Server = new BackgroundJobServer(new BackgroundJobServerOptions
            {
                ServerName = $"{Environment.MachineName}", //服务器名称
                SchedulePollingInterval = TimeSpan.FromSeconds(1),
                ServerCheckInterval     = TimeSpan.FromSeconds(1),
                WorkerCount             = Environment.ProcessorCount * 2,
                Queues = new[] { "OneLife" } //队列名
            });
            #endregion

            #endregion
            RecurringJob.AddOrUpdate(() => Windows.ClearMemorySilent(), Cron.Hourly);
            RecurringJob.AddOrUpdate(() => RemoveSuccessJob(), Cron.Daily, TimeZoneInfo.Local);
        }
Ejemplo n.º 2
0
        internal static void UseLuceneSearch(this IApplicationBuilder app, IHostEnvironment env, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions)
        {
            var are = new AutoResetEvent(false);

            Task.Run(() =>
            {
                Console.WriteLine("正在导入自定义词库...");
                double time = HiPerfTimer.Execute(() =>
                {
                    var db        = app.ApplicationServices.GetRequiredService <DataContext>();
                    using var set = db.Post.Select(p => $"{p.Title},{p.Label},{p.Keyword}").AsParallel().SelectMany(s => Regex.Split(s, @"\p{P}(?<!\.|#)|\p{Z}|\p{S}")).Where(s => s.Length > 1).ToPooledSet();
                    var lines     = File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomKeywords.txt")).Union(set);
                    KeywordsManager.AddWords(lines);
                    KeywordsManager.AddSynonyms(File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomSynonym.txt")).Where(s => s.Contains(" ")).Select(s =>
                    {
                        var arr = Regex.Split(s, "\\s");
                        return(arr[0], arr[1]);
                    }));
                });
                Console.WriteLine($"导入自定义词库完成,耗时{time}s");
                Windows.ClearMemorySilent();
                are.Set();
            });

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

            if (!Directory.Exists(lucenePath) || Directory.GetFiles(lucenePath).Length < 1)
            {
                are.WaitOne();
                Console.WriteLine("索引库不存在,开始自动创建Lucene索引库...");
                hangfire.CreateLuceneIndex();
                Console.WriteLine("索引库创建完成!");
            }
        }
Ejemplo n.º 3
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("索引库创建完成!");
            }
        }
Ejemplo n.º 4
0
 public void AggregateInterviews()
 {
     var(all, unique) = Analysis();
     AggregatedCounter.TotalInterviews  = all;
     AggregatedCounter.UniqueInterviews = unique;
     Windows.ClearMemorySilent();
 }
Ejemplo n.º 5
0
        public static void Start()
        {
            PushHub.PushData(a =>
            {
                try
                {
                    double time        = DateTime.Now.GetTotalMilliseconds();// - 28800000;
                    float load         = SystemInfo.CpuLoad;
                    double temperature = SystemInfo.GetCPUTemperature();
                    double mem         = (1 - SystemInfo.MemoryAvailable.To <double>() / SystemInfo.PhysicalMemory.To <double>()) * 100;
                    a.receiveLoad($"[{time},{load},{mem},{temperature}]");//CPU

                    var read  = SystemInfo.GetDiskData(DiskData.Read) / 1024;
                    var write = SystemInfo.GetDiskData(DiskData.Write) / 1024;
                    a.receiveReadWrite($"[{time},{read},{write}]");//磁盘IO

                    var up   = SystemInfo.GetNetData(NetData.Received) / 1024;
                    var down = SystemInfo.GetNetData(NetData.Sent) / 1024;
                    a.receiveUpDown($"[{time},{down},{up}]");//网络上下载

                    if (mem > 90)
                    {
                        Windows.ClearMemorySilent();
                    }
                    //缓存历史数据
                    if (CommonHelper.HistoryCpuLoad.Count < 50 || (time / 10000).ToInt32() % 12 == 0)
                    {
                        CommonHelper.HistoryCpuLoad.Add(new object[] { time, load });
                        CommonHelper.HistoryCpuTemp.Add(new object[] { time, temperature });
                        CommonHelper.HistoryMemoryUsage.Add(new object[] { time, mem });
                        CommonHelper.HistoryIORead.Add(new object[] { time, read });
                        CommonHelper.HistoryIOWrite.Add(new object[] { time, write });
                        CommonHelper.HistoryNetReceive.Add(new object[] { time, up });
                        CommonHelper.HistoryNetSend.Add(new object[] { time, down });
                        if (CommonHelper.HistoryCpuLoad.Count > 720)
                        {
                            CommonHelper.HistoryCpuLoad.RemoveAt(0);
                            CommonHelper.HistoryMemoryUsage.RemoveAt(0);
                            CommonHelper.HistoryCpuTemp.RemoveAt(0);
                        }
                        if (CommonHelper.HistoryIORead.Count > 720)
                        {
                            CommonHelper.HistoryIORead.RemoveAt(0);
                            CommonHelper.HistoryIOWrite.RemoveAt(0);
                            CommonHelper.HistoryNetReceive.RemoveAt(0);
                            CommonHelper.HistoryNetSend.RemoveAt(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogManager.Error(typeof(CollectRunningInfo), e.Message);
                }
            });
        }
Ejemplo n.º 6
0
        public static void Register()
        {
            #region Hangfire配置

            //GlobalConfiguration.Configuration.UseMemoryStorage();
            GlobalConfiguration.Configuration.UseSqlServerStorage(ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString).UseConsole();

            #region 实现类注册

            GlobalConfiguration.Configuration.UseAutofacActivator(AutofacConfig.Container);

            #endregion

            #region  务启动

            Server = new BackgroundJobServer(new BackgroundJobServerOptions
            {
                ServerName = $"{Environment.MachineName}", //服务器名称
                SchedulePollingInterval = TimeSpan.FromSeconds(1),
                ServerCheckInterval     = TimeSpan.FromSeconds(1),
                WorkerCount             = Environment.ProcessorCount * 2,
                //Queues = new[] { "masuit" } //队列名
            });

            #endregion

            #endregion

            HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.UpdateLucene)); //更新文章索引
            AggregateInterviews();                                                                    //访客统计
            RecurringJob.AddOrUpdate(() => Windows.ClearMemorySilent(), Cron.Hourly);                 //每小时清理系统内存
            RecurringJob.AddOrUpdate(() => CheckLinks(), Cron.HourInterval(5));                       //每5h检查友链
            RecurringJob.AddOrUpdate(() => EverydayJob(), Cron.Daily, TimeZoneInfo.Local);            //每天的任务
            RecurringJob.AddOrUpdate(() => AggregateInterviews(), Cron.Hourly(30));                   //每半小时统计访客
            using (RedisHelper redisHelper = RedisHelper.GetInstance())
            {
                if (!redisHelper.KeyExists("ArticleViewToken"))
                {
                    redisHelper.SetString("ArticleViewToken", string.Empty.CreateShortToken()); //更新加密文章的密码
                }
            }
        }
Ejemplo n.º 7
0
        public static void Register()
        {
            #region Hangfire配置

            //GlobalConfiguration.Configuration.UseMemoryStorage();

            GlobalConfiguration.Configuration.UseStorage(
                new MySqlStorage(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)
                ).UseConsole();

            #region 实现类注册

            GlobalConfiguration.Configuration.UseAutofacActivator(AutofacConfig.Container);

            #endregion

            #region  务启动

            Server = new BackgroundJobServer(new BackgroundJobServerOptions
            {
                ServerName = $"{Environment.MachineName}", //服务器名称
                SchedulePollingInterval = TimeSpan.FromSeconds(1),
                ServerCheckInterval     = TimeSpan.FromSeconds(1),
                WorkerCount             = Environment.ProcessorCount * 2,
                //Queues = new[] { "quick" } //队列名
            });
            #endregion

            #endregion

            RecurringJob.AddOrUpdate(() => Windows.ClearMemorySilent(), Cron.Hourly);//每小时清理系统内存
            //RecurringJob.AddOrUpdate(() => CheckLinks(), Cron.HourInterval(5));//每5h检查友链
            //RecurringJob.AddOrUpdate(() => EverydayJob(), Cron.Daily, TimeZoneInfo.Local);//每天的任务
            //RecurringJob.AddOrUpdate(() => FlushAddress(), Cron.Weekly(DayOfWeek.Sunday, 2), TimeZoneInfo.Local);//刷新没统计到的访客的信息
            //RecurringJob.AddOrUpdate(() => AggregateInterviews(), Cron.Hourly(30));//每半小时统计访客
        }