Example #1
0
        /// <summary>
        /// 1) Sets up overlay
        /// 2) Creates threadpool
        /// 3) Creates InteractiveCommandParser
        /// 4) ?????
        /// 5) Profit
        /// </summary>
        /// <param name="args"> No command line arguments for PiController </param>
        static void Main(string[] args)
        {
            // Step 1: Create Overlay
            Overlay overlay = new Overlay();

            List <string>      online = overlay.getOnline();
            List <RaspberryPi> pis    = overlay.getPis();
            int alive = online.Count;
            // Step 2: Create threadpool
            ThreadPoolManager threadPool = new ThreadPoolManager();

            threadPool.startThreadPool();
            Console.WriteLine("\n");
            // Step 3: Create Interactive command parser
            InteractiveCommandParser parser = new InteractiveCommandParser(ref overlay, ref threadPool);

            parser.ParseCommands(alive);
            try
            {
                System.Environment.Exit(0);
            }
            catch (Exception)
            {
                System.Environment.Exit(0);
            }
        }
Example #2
0
 private void tabMain_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (tabMain.SelectedTab.Text.Equals("木马查杀"))
     {
         txtScanFilePath.Text = Core.Configs.ConfigsControl.Instance.SitePath;
         ThreadPoolManager.Init(1);
     }
     else if (tabMain.SelectedTab.Text.Equals("实时文件监视"))
     {
         txtWatchPath.Text = Core.Configs.ConfigsControl.Instance.SitePath;
         txtWatchType.Text = Core.Configs.ConfigsControl.Instance.WatchType;
     }
     else if (tabMain.SelectedTab.Text.Equals("页面内容更新监控"))
     {
         if (lvPageUpdate.Items.Count == 0)
         {
             BindUpdateLink();
         }
     }
     else if (tabMain.SelectedTab.Text.Equals("死链监控"))
     {
         if (lv404links.Items.Count == 0)
         {
             BindBadLink();
         }
     }
     else if (tabMain.SelectedTab.Text.Equals("友情链接检控"))
     {
         if (lv404links.Items.Count == 0)
         {
             BindWebLink();
         }
     }
 }
Example #3
0
        static void Main(string[] args)
        {
            ThreadPoolManager pool  = new ThreadPoolManager(2);
            MyTask            task1 = new MyTask(5000);
            MyTask            task2 = new MyTask(5000);
            MyTask            task3 = new MyTask(5000);

            pool.execute(task1);
            pool.execute(task2);

            pool.JoinThreads();

            pool.execute(task3);

            pool.JoinThreads();

            foreach (Thread th in pool.GetThreadList())
            {
                Console.WriteLine(th.IsAlive);
                Console.WriteLine("ThreadState: {0}", th.ThreadState);
            }

            Console.WriteLine("End Thread.");

            //while (true)
            //{
            //    Console.WriteLine(" Thread {0} available ", pool.getThreadCount());
            //    Thread.Sleep(1000);
            //}
        }
 /* Constructor */
 public InteractiveCommandParser(ref Overlay network, ref ThreadPoolManager mgr)
 {
     this.network    = network;
     this.online     = network.getOnline();
     this.rasPis     = network.getPis();
     this.threadPool = mgr;
 }
 public static void Close()
 {
     if (Pool == null)
     {
         return;
     }
     Pool.CloseAll(true);
     Pool = null;
 }
 public static bool AddWork(ThreadPoolManager.EventFunc Func, object[] data = null)
 {
     if (Pool == null)
     {
         Pool = new ThreadPoolManager(Settings.Read().ThreadNum);
     }
     Pool.AddWork(Func, data);
     return(true);
 }
Example #7
0
 /// <summary>
 /// Add Download
 /// </summary>
 public static bool AddWork(ThreadPoolManager.EventFunc Func, object[] data = null)
 {
     if (Pool == null)
     {
         Pool = new ThreadPoolManager(int.Parse(Config.ThreadNum()));
     }
     Pool.AddWork(Func, data);
     return(true);
 }
 public static void SetThreadNum(int iNum)
 {
     if (Pool == null)
     {
         Pool = new ThreadPoolManager(iNum);
     }
     else
     {
         Pool.SetPoolSize(iNum);
     }
 }
 public static void SetThreadNum(int iNum)
 {
     if (Pool == null)
     {
         Pool = new ThreadPoolManager(iNum);
     }
     if (iNum < 1)
     {
         iNum = 1;
     }
     Pool.SetPoolSize(iNum);
 }
Example #10
0
        /// <summary>
        /// 实时队列消费者
        /// </summary>
        /// <param name="action"></param>
        public static void DoQueue <T>(Action <T> action, string queueName)
        {
            //  RedisCache redis=new RedisCache();

            ThreadPoolManager.Run(() =>
            {
                try
                {
                    while (true)
                    {
                        try
                        {
                            if (!RedisManager.Instance.GetDatabase().KeyExists(queueName) || RedisManager.Instance.GetDatabase().ListLength(queueName) == 0) //消息为空挂起
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("队列{0}为空,挂起1秒", queueName);
                                Thread.Sleep(1000);
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("从队列{0}拿出数据", queueName);

                                byte[] msg = RedisManager.Instance.GetDatabase().ListLeftPop(queueName);
                                var entity = msg.DeserializeToBin <T>();
                                if (entity != null)
                                {
                                    LoggerManager.Instance.Info("实时队列:" + queueName);
                                    action(entity);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LoggerManager.Instance.Info("实时队列出现异常:" + ex.Message);
                            Thread.Sleep(5000);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerManager.Instance.Info("Redis连接串出现异常:" + ex.Message);
                    Thread.Sleep(5000);
                }
            });
        }
Example #11
0
        static void Main(string[] args)
        {
            ThreadPoolManager tpm = new ThreadPoolManager();

            tpm.Start();

            for (int i = 0; i < 20; i++)
            {
                var i1 = i;
                tpm.AddWork(() =>
                {
                    ThreadTest(i1);
                    Thread.Sleep(1000);
                });
            }

            tpm.Stop();
        }
        [STAThread] // needed to show open folder dialogue
        static void Main(string[] args)
        {
            string[]          files       = args;
            ThreadPoolManager poolManager = new ThreadPoolManager();

            poolManager.ConFigurePoolByNumberOfCPUs();
            if (files.Length == 0)
            {
                files = getFiles();
            }
            foreach (string s in files)
            {
                IThreadPoolWorker pg = new GraphCreator(s);
                poolManager.AddWorker(pg);
            }

            poolManager.Wait();
            System.Environment.Exit(0);
        }
        private void ListenerCallback(HttpListenerContext result)
        {
            if (result != null)
            {
                HttpListenerRequest request = result.Request;

                if (request.HasEntityBody)
                {
                    ThreadPoolManager.AddTask(result);
                }
                else
                {
                    LogManager.PrintErrorMessage("Got message with no entity body!");
                }
            }
            else
            {
                LogManager.PrintErrorMessage("Got message with context null!");
            }
        }
        public void ListenerCallback(HttpListenerContext result)
        {
            if (result != null)
            {
                HttpListenerRequest request = result.Request;

                if (request.HasEntityBody)
                {
                    ThreadPoolManager.AddTask(result);

                    TotalMessages++;
                }
                else
                {
                    LogAddMessage("Got message with no entity body!");
                }
            }
            else
            {
                LogAddMessage("Got message with context null!");
            }
        }
Example #15
0
 protected AppHostHttpListenerLongRunningBase(string serviceName, string handlerPath, int poolSize, params Assembly[] assembliesWithServices)
     : base(serviceName, handlerPath, assembliesWithServices)
 {
     threadPoolManager = new ThreadPoolManager(poolSize);
 }
Example #16
0
 protected AppHostHttpListenerLongRunningBase(int poolSize = 500)
 {
     threadPoolManager = new ThreadPoolManager(poolSize);
 }
Example #17
0
        public MainApp()
        {
            InitializeComponent();
            //this.TopMost = true;

            this.StartPosition = FormStartPosition.CenterScreen;
            Splash.Status      = "状态:载入初始化数据";

            this.FormClosing += MainApp_FormClosing;

            ThreadPoolManager.Init(1);

            timerEmailSend.Interval = 5000;//10秒检测一次
            timerEmailSend.Tick    += ToSendReport;
            timerEmailSend.Start();

            #region 初始


            dtpStart.Width = 110;
            dtpEnd.Width   = 110;



            lstbFileList.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lstbFileList.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lstbFileList.GridLines     = true;         //显示网格线
            lstbFileList.FullRowSelect = true;         //选择时选择是行,而不是某列
            lstbFileList.Columns.Add("文件目录", 600, HorizontalAlignment.Center);
            lstbFileList.Columns.Add("状态", 100, HorizontalAlignment.Center);

            lstWatchList.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lstWatchList.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lstWatchList.GridLines     = true;         //显示网格线
            lstWatchList.FullRowSelect = true;         //选择时选择是行,而不是某列
            lstWatchList.Columns.Add("文件路径", 600, HorizontalAlignment.Center);
            lstWatchList.Columns.Add("操作", 100, HorizontalAlignment.Center);
            lstWatchList.Columns.Add("备注", 100, HorizontalAlignment.Center);

            lvErrSiteList.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lvErrSiteList.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lvErrSiteList.GridLines     = true;         //显示网格线
            lvErrSiteList.FullRowSelect = true;         //选择时选择是行,而不是某列
            lvErrSiteList.Columns.Add("网站名称", 100, HorizontalAlignment.Center);
            lvErrSiteList.Columns.Add("应用池", 100, HorizontalAlignment.Center);
            lvErrSiteList.Columns.Add("检测网址", 250, HorizontalAlignment.Left);
            lvErrSiteList.Columns.Add("间隔", 50, HorizontalAlignment.Center);
            lvErrSiteList.Columns.Add("错误数", 50, HorizontalAlignment.Center);
            lvErrSiteList.Columns.Add("报告数", 50, HorizontalAlignment.Center);
            lvErrSiteList.Columns.Add("最后错误时间", 100, HorizontalAlignment.Center);
            lvErrSiteList.Columns.Add("ID", 0);


            //winform中,listview是没有办法设置行高的,没行之间排得密密麻麻的,很不好!

            //可以加入一个imagelist来 撑大 行,实现行高的设置!

            //   设置行高   20
            ImageList imgList = new ImageList();
            imgList.ImageSize = new Size(1, 20);     //分别是宽和高

            lv404links.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lv404links.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lv404links.GridLines     = true;         //显示网格线
            lv404links.FullRowSelect = true;         //选择时选择是行,而不是某列
            lv404links.Columns.Add("检测目标地址", 350, HorizontalAlignment.Left);
            lv404links.Columns.Add("时间间隔", 80, HorizontalAlignment.Center);
            lv404links.Columns.Add("死链数", 80, HorizontalAlignment.Center);
            lv404links.Columns.Add("状态", 120, HorizontalAlignment.Center);
            lv404links.Columns.Add("最后汇报时间", 120, HorizontalAlignment.Center);
            lv404links.Columns.Add("最后汇报结果", 500, HorizontalAlignment.Center);
            lv404links.Columns.Add("ID", 0);
            lv404links.Columns.Add("页面名称", 80);
            lv404links.SmallImageList = imgList;   //这里设置listView的SmallImageList ,用imgList将其撑大


            lvBadWords.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lvBadWords.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lvBadWords.GridLines     = true;         //显示网格线
            lvBadWords.FullRowSelect = true;         //选择时选择是行,而不是某列
            lvBadWords.Columns.Add("检测目标地址", 350, HorizontalAlignment.Left);
            lvBadWords.Columns.Add("内容获取方式", 100, HorizontalAlignment.Center);
            lvBadWords.Columns.Add("状态", 120, HorizontalAlignment.Center);
            lvBadWords.Columns.Add("最后汇报时间", 120, HorizontalAlignment.Center);
            lvBadWords.Columns.Add("最后汇报结果", 500, HorizontalAlignment.Center);
            lvBadWords.SmallImageList = imgList;       //这里设置listView的SmallImageList ,用imgList将其撑大

            lvPageUpdate.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lvPageUpdate.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lvPageUpdate.GridLines     = true;         //显示网格线
            lvPageUpdate.FullRowSelect = true;         //选择时选择是行,而不是某列
            lvPageUpdate.Columns.Add("检测目标地址", 350, HorizontalAlignment.Left);
            lvPageUpdate.Columns.Add("时间间隔", 180, HorizontalAlignment.Center);
            lvPageUpdate.Columns.Add("状态", 120, HorizontalAlignment.Center);
            lvPageUpdate.Columns.Add("最后汇报时间", 120, HorizontalAlignment.Center);
            lvPageUpdate.Columns.Add("最后汇报结果", 500, HorizontalAlignment.Center);
            lvPageUpdate.Columns.Add("最近一次md5", 120, HorizontalAlignment.Center);
            lvPageUpdate.Columns.Add("ID", 0);

            lvPageUpdate.SmallImageList = imgList;   //这里设置listView的SmallImageList ,用imgList将其撑大


            lvWebLinkUrl.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lvWebLinkUrl.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lvWebLinkUrl.GridLines     = true;         //显示网格线
            lvWebLinkUrl.FullRowSelect = true;         //选择时选择是行,而不是某列
            lvWebLinkUrl.Columns.Add("检测目标地址", 350, HorizontalAlignment.Left);
            lvWebLinkUrl.Columns.Add("时间间隔", 180, HorizontalAlignment.Center);
            lvWebLinkUrl.Columns.Add("状态", 120, HorizontalAlignment.Center);
            lvWebLinkUrl.Columns.Add("友链数量", 100, HorizontalAlignment.Center);
            lvWebLinkUrl.Columns.Add("最后汇报时间", 120, HorizontalAlignment.Center);
            lvWebLinkUrl.Columns.Add("ID", 0);
            lvWebLinkUrl.SmallImageList = imgList;   //这里设置listView的SmallImageList ,用imgList将其撑大

            //WindowState = FormWindowState.Maximized;


            //MyHttpListener _MyHttpListener = new MyHttpListener("http://+:8089/");
            //_MyHttpListener.RequestEvent += OnHttpRequest;
            //_MyHttpListener.Start();
            //dglUpdateHttpWatch = OnUpdateHttpWatch;



            #endregion


            Splash.Status = "状态:启用监听事件";

            //监视cpu与内存
            GetCpuInfo();
            siMemoryInfo         = new SystemInfo();
            timerMemory.Interval = 3000;
            timerMemory.Tick    += new EventHandler(OntimerMemory);
            //timerMemory.Tick += new EventHandler(NetInfo);
            timerMemory.Start();
            Splash.Status       = "状态:获取网卡信息";
            cbNetCar.DataSource = GetNicList();
            if (!string.IsNullOrEmpty(Core.Configs.ConfigsControl.Instance.SelNetCar))
            {
                cbNetCar.Text = Core.Configs.ConfigsControl.Instance.SelNetCar;
                //StarShowNetInfo();
            }

            Splash.Status    = "状态:加载站点信息";
            drpTimeSpan.Text = "检测时间间隔(分钟)";
            BindErrSites();
            LoadPlugins();

            Splash.Close();
            this.Show();
            this.Activate();

            urlNoChecks = BLL.BadLinkNoCheck.Instance.GetList();

            //Log.ErrorLog.Error("fsdfsdfsd{0}");
        }
 protected AppHostHttpListenerPoolBase(string serviceName, string handlerPath, int poolSize, params Assembly[] assembliesWithServices)
     : base(serviceName, handlerPath, assembliesWithServices) { threadPoolManager = new ThreadPoolManager(poolSize); }
 protected AppHostHttpListenerLongRunningBase(string serviceName, int poolSize, params Assembly[] assembliesWithServices)
     : base(serviceName, assembliesWithServices) { _threadPoolManager = new ThreadPoolManager(poolSize); }
 protected AppHostHttpListenerLongRunningBase(int poolSize = 500) { _threadPoolManager = new ThreadPoolManager(poolSize); }
Example #21
0
 protected AppHostHttpListenerLongRunningBase(int poolSize, params Assembly[] assembliesWithServices)
     : base(assembliesWithServices)
 {
     _threadPoolManager = new ThreadPoolManager(poolSize);
 }
 protected AppHostHttpListenerPoolBase(string serviceName, int poolSize, params Assembly[] assembliesWithServices)
     : base(serviceName, assembliesWithServices)
 {
     threadPoolManager = new ThreadPoolManager(poolSize);
 }
 protected AppHostHttpListenerPoolBase(string serviceName, params Type[] serviceTypes)
     : this(serviceName, TypeConstants <Assembly> .EmptyArray)
 {
     threadPoolManager = new ThreadPoolManager(CalculatePoolSize());
     ServiceController = CreateServiceController(serviceTypes);
 }