Пример #1
0
 private void NetDetailForm_Load(object sender, EventArgs e)
 {
     #region 启动任务
     IP = GetIP();
     Task.Factory.StartNew(() =>
     {
         try
         {
             while (!this.IsDisposed)
             {
                 GetNetProcess();
                 this.dataGridView1.Invoke(new Action(() =>
                 {
                     foreach (var p in netProcesses)
                     {
                         bool inView = false;
                         for (int i = 0; i < dataGridView1.Rows.Count; i++)
                         {
                             if (dataGridView1.Rows[i].Cells["Column3"].Value.ToString() == p.ProcessID.ToString())
                             {
                                 inView = true;
                                 dataGridView1.Rows[i].Cells["Column4"].Value = ByteConvertTool.Fmt(p.UpLoad) + "/s";
                                 dataGridView1.Rows[i].Cells["Column7"].Value = ByteConvertTool.Fmt(p.UpLoadCount);
                                 dataGridView1.Rows[i].Cells["Column5"].Value = ByteConvertTool.Fmt(p.DownLoad) + "/s";
                                 dataGridView1.Rows[i].Cells["Column8"].Value = ByteConvertTool.Fmt(p.DownLoadCount);
                                 dataGridView1.Rows[i].Cells["Column6"].Value = ByteConvertTool.Fmt(p.UpLoadCount + p.DownLoadCount);
                             }
                         }
                         if (!inView)
                         {
                             dataGridView1.Rows.Add(new object[] {
                                 p.ProcessICon,
                                 ProcessAPI.GetProcessNameByPID(p.ProcessID),
                                 p.ProcessID.ToString(),
                                 ByteConvertTool.Fmt(p.UpLoad) + "/s",
                                 ByteConvertTool.Fmt(p.UpLoadCount),
                                 ByteConvertTool.Fmt(p.DownLoad) + "/s",
                                 ByteConvertTool.Fmt(p.DownLoadCount),
                                 ByteConvertTool.Fmt(p.UpLoadCount + p.DownLoadCount)
                             });
                         }
                     }
                 }));
                 CalcBagFlow();
                 this.status.Invoke(new Action(() =>
                 {
                     status.Text = string.Format("信息:IP:{0},上传流量:{1},下载流量:{2}",
                                                 IP, ByteConvertTool.Fmt(NetWorkService.NowSent), ByteConvertTool.Fmt(NetWorkService.NowReceived));
                     status.Text += string.Format(",单位时间:{0}分钟,上传流量:{1},下载流量:{2},下次刷新时间:{3}",
                                                  NetWorkService.ThresholdTime, ByteConvertTool.Fmt(NetWorkService.UnitSent), ByteConvertTool.Fmt(NetWorkService.UnitReceived), NetWorkService.CalcTime.ToString("yyyy-MM-dd HH:mm:ss"));
                 }));
                 Thread.Sleep(1000);
             }
         }
         catch { }
     });
     CaptureInit();
     Task.Factory.StartNew(() => { try { _rs.Capture(); } catch { } });
     #endregion
 }
Пример #2
0
 private void UI()
 {
     Task.Factory.StartNew(() =>
     {
         try
         {
             while (!this.IsDisposed)
             {
                 this.Invoke(new Action(() =>
                 {
                     if (!this.IsDisposed)
                     {
                         label1.Text = ByteConvertTool.Fmt(NetWorkService.NowSent) + "/s";
                         label2.Text = ByteConvertTool.Fmt(NetWorkService.NowReceived) + "/s";
                         label6.Text = Math.Floor(NetWorkService.CpuLoad) + "%";
                         //流量超出报警
                         if ((NetWorkService.UnitSent + NetWorkService.UnitReceived) > NetWorkService.FlowThreshold)
                         {
                             if (report == null || report.IsDisposed)
                             {
                                 report = new NetReportForm();
                                 report.Show();
                             }
                         }
                     }
                 }));
                 Thread.Sleep(1000);
             }
         }
         catch
         { }
     });
 }
Пример #3
0
 private void TMMain_Tick(object sender, EventArgs e)
 {
     try
     {
         TSSLRamInfo.Text = ByteConvertTool.Fmt(R.AppRam);
     }
     catch { }
 }
 /// <summary>
 /// 修改窗口标题
 /// </summary>
 /// <param name="s"></param>
 public void UICaption(string s)
 {
     try
     {
         Invoke(new Action(() =>
         {
             Caption = s;
             Text    = $"{Caption} 的输出窗口    [ {ByteConvertTool.Fmt(ConsoleLength)} ]";
         }));
     }
     catch { }
 }
Пример #5
0
        /// <summary>
        /// 日志文件分析
        /// </summary>
        public static void LogFileAnalyse()
        {
            List <string> all_log          = GetAllLogFile();
            List <string> expire_log       = GetExpireLogFile(all_log, out long allSize, out long expireSize);
            int           all_log_count    = Ls.Ok(all_log) ? all_log.Count : 0;
            int           expire_log_count = Ls.Ok(expire_log) ? expire_log.Count : 0;

            R.SystemStatus.AllLogCount    = all_log_count;
            R.SystemStatus.AllLogSize     = (long)ByteConvertTool.Cvt(allSize, "KB");
            R.SystemStatus.ExpireLogCount = expire_log_count;
            R.SystemStatus.ExpireLogSize  = (long)ByteConvertTool.Cvt(expireSize, "KB");

            //R.Log.I($"全部日志文件:{all_log_count} 个, 共计:{ByteConvertTool.Cvt(allSize, "GB")} GB");
            //R.Log.I($"过期日志文件:{expire_log_count} 个, 共计:{ByteConvertTool.Cvt(expireSize, "GB")} GB");
        }
Пример #6
0
        private void TestComputerInfoForm_Load(object sender, EventArgs e)
        {
            var softwareinfos = Utils.SoftwareUtils.SoftwareTool.GetControlList();

            if (ListTool.HasElements(softwareinfos))
            {
                softwareinfos.ForEach(x =>
                {
                    if (x.Name != "")
                    {
                        Print(string.Format("{0} / 【{1}】 / {2} / {3} 【{4}】",
                                            x.Name, x.InstallDate, x.Publisher, x.Version,
                                            ByteConvertTool.Fmt(x.EstimatedSize * 1024)));
                    }
                });
            }
        }
Пример #7
0
        /// <summary>
        /// 1分钟任务
        /// </summary>
        public static void Do()
        {
            R.SystemStatus.DriveTotal = DriveTool.GetDriveTotalSize(R.Paths.App);
            R.SystemStatus.DriveAvail = DriveTool.GetDriveAvailableSize(R.Paths.App);

            LogCleaner.LogFileAnalyse();
            R.Log.I($"全部日志文件:{R.SystemStatus.AllLogCount} 个, 共计:{ByteConvertTool.Cvt(R.SystemStatus.AllLogSize, "MB")} GB");
            R.Log.I($"过期日志文件:{R.SystemStatus.ExpireLogCount} 个, 共计:{ByteConvertTool.Cvt(R.SystemStatus.ExpireLogSize, "MB")} GB");

            //string toMail = "*****@*****.**";
            //string subject = $"服务器状态报表:日报:{DateTime.Now.ToString("yyyy年MM月dd日")}";
            //string emailBody = "测试内容";
            //EmailTool et = new EmailTool(
            //    "*****@*****.**",
            //    toMail, subject, emailBody,
            //    "bigbird_server","bigbird528");
            //et.Send();
        }
Пример #8
0
        private void UIDgProcessDetailUpdate()
        {
            Dispatcher.Invoke(new Action(() =>
            {
                if (R.NFS != null && ListTool.HasElements(R.NFS.NetProcessInfoList))
                {
                    Status = string.Format("下载:{0},上传:{1}(丢包:{2})",
                                           ByteConvertTool.Fmt(R.NFS.NetFlow.DownloadData),
                                           ByteConvertTool.Fmt(R.NFS.NetFlow.UploadData),
                                           R.NFS.LostPacketCount);
                    ObNetPro = new ObservableCollection <NetProcessInfo>(R.NFS.NetProcessInfoList);

                    //label1.Text = "丢包数:" + R.NFS.LostPacketCount;
                    //LbStatus.Content = "下载:" + ByteConvertTool.Fmt(R.NFS.NetFlow.DownloadData) +
                    //                   " 上传:" + ByteConvertTool.Fmt(R.NFS.NetFlow.UploadData);
                    //R.NFS.NetProcessInfoList.ForEach(p =>
                    //{
                    //    bool isUpdate = false;
                    //    foreach (DataGridViewRow r in DgProcessDetail.Rows)
                    //    {
                    //        if (r.Cells["CoName"].Value.ToString() == p.ProcessName)
                    //        {
                    //            isUpdate = true;
                    //            r.Cells["CoDownload"].Value = ByteConvertTool.Fmt(p.DownloadData);
                    //            r.Cells["CoUpload"].Value = ByteConvertTool.Fmt(p.UploadData);
                    //            r.Cells["CoDownloadCount"].Value = ByteConvertTool.Fmt(p.DownloadDataCount);
                    //            r.Cells["CoUploadCount"].Value = ByteConvertTool.Fmt(p.UploadDataCount);
                    //            r.Cells["CoConnectionCount"].Value = p.ConnectCount;
                    //        }
                    //    }
                    //    if (!isUpdate)
                    //    {
                    //        DgProcessDetail.Rows.Add(new object[] {
                    //            p.ProcessIcon,p.ProcessName,
                    //            ByteConvertTool.Fmt(p.DownloadData),ByteConvertTool.Fmt(p.UploadData),
                    //            ByteConvertTool.Fmt(p.DownloadDataCount),ByteConvertTool.Fmt(p.UploadDataCount),
                    //           p.DownloadBagCount});
                    //    }
                    //});
                }
            }));
        }
Пример #9
0
        private void UIDgProcessDetailUpdate()
        {
            if (IsDisposed)
            {
                return;
            }

            BeginInvoke(new Action(() =>
            {
                if (R.NFS != null && ListTool.HasElements(R.NFS.NetProcessInfoList))
                {
                    label1.Text = "丢包数:" + R.NFS.LostPacketCount;
                    label2.Text = "下载:" + ByteConvertTool.Fmt(R.NFS.NetFlow.DownloadData) +
                                  " 上传:" + ByteConvertTool.Fmt(R.NFS.NetFlow.UploadData);
                    R.NFS.NetProcessInfoList.ForEach(p =>
                    {
                        bool isUpdate = false;
                        foreach (DataGridViewRow r in DgProcessDetail.Rows)
                        {
                            if (r.Cells["CoName"].Value.ToString() == p.ProcessName)
                            {
                                isUpdate = true;
                                r.Cells["CoDownload"].Value        = ByteConvertTool.Fmt(p.DownloadData);
                                r.Cells["CoUpload"].Value          = ByteConvertTool.Fmt(p.UploadData);
                                r.Cells["CoDownloadCount"].Value   = ByteConvertTool.Fmt(p.DownloadDataCount);
                                r.Cells["CoUploadCount"].Value     = ByteConvertTool.Fmt(p.UploadDataCount);
                                r.Cells["CoConnectionCount"].Value = p.NetConnectionInfoList.Count();
                            }
                        }
                        if (!isUpdate)
                        {
                            DgProcessDetail.Rows.Add(new object[] {
                                p.ProcessIcon, p.ProcessName,
                                ByteConvertTool.Fmt(p.DownloadData), ByteConvertTool.Fmt(p.UploadData),
                                ByteConvertTool.Fmt(p.DownloadDataCount), ByteConvertTool.Fmt(p.UploadDataCount),
                                p.DownloadBagCount
                            });
                        }
                    });
                }
            }));
        }
Пример #10
0
        /// <summary>
        /// 启动监测APP自身资源占用情况
        /// </summary>
        private void TaskOfStatus()
        {
            if (!RunStatusTask)
            {
                Task.Factory.StartNew(() =>
                {
                    RunStatusTask      = true;
                    TimeSpan beginTime = TimeSpan.Zero;
                    while (!IsDisposed)
                    {
                        try
                        {
                            bool cpuflag  = ComputerStatusTool.TryGetNextValue(ComputerProcessor, out float cpu);
                            string ram    = ByteConvertTool.Fmt(ComputerInfoTool.AvailablePhysicalMemory() * 1024);
                            int appcpu    = (int)AppInfoTool.CalcCpuRate(Process, ref beginTime, STATUS_INTERVAL);
                            string appram = ByteConvertTool.Fmt(AppInfoTool.RAM() * 1024);

                            R.SystemStatus.AppID          = R.AppID;
                            R.SystemStatus.Name           = R.Tx.LocalName;
                            R.SystemStatus.IP             = R.Tx.LocalIP;
                            R.SystemStatus.Cpu            = (int)cpu;
                            R.SystemStatus.Ram            = (long)ComputerInfoTool.TotalPhysicalMemory() / 1024;
                            R.SystemStatus.RamAvail       = (long)ComputerInfoTool.AvailablePhysicalMemory() / 1024;
                            R.SystemStatus.AppCpu         = appcpu;
                            R.SystemStatus.AppRam         = AppInfoTool.RAM() / 1024;
                            R.SystemStatus.CreateTime     = DateTime.Now;
                            R.SystemStatus.BigBirdVersion = R.Version;
                            TxSendQueue.Add(20002000, Json.Object2String(R.SystemStatus));

                            Invoke(new Action(() =>
                            {
                                LBStatus.Text = $"CPU: {(int)cpu}% , RAM: {ram} [ cpu: {appcpu}% , ram: {appram} ]";
                            }));
                        }
                        catch { }
                        Thread.Sleep(STATUS_INTERVAL);
                    }
                });
            }
        }
Пример #11
0
 /// <summary>
 /// 读取备份文件目录
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void TmReadPaths_Tick(object sender, EventArgs e)
 {
     if (R.Services.FBS.StatusOfReadBackupPaths)
     {
         TmReadPaths.Enabled = false;
         Task.Factory.StartNew(() =>
         {
             if (ListTool.HasElements(R.Services.FBS.Paths))
             {
                 foreach (var p in R.Services.FBS.Paths)
                 {
                     using (var db = new Muse())
                     {
                         long size   = db.Do <BackupFiles>().Where(x => x.FullPath.Contains(p.Path)).Sum(x => x.Size);
                         string name = DirTool.GetPathName(p.Path);     //获取目录名称
                         UIDgvPathAdd(name, ByteConvertTool.Fmt(size)); //添加到列表UI
                     }
                 }
             }
             UIEnableButton(true);
         });
     }
 }
Пример #12
0
        private void NetReportForm_Load(object sender, EventArgs e)
        {
            #region 启动功能
            this.ShowInTaskbar = false;
            this.Hide();
            IP = GetIP();
            Task.Factory.StartNew(() =>
            {
                try
                {
                    while (!this.IsDisposed)
                    {
                        GetNetProcess();
                        CalcBagFlow();
                        this.Invoke(new Action(() =>
                        {
                            status.Text = string.Format("信息:IP:{0},上传流量:{1},下载流量:{2}",
                                                        IP, ByteConvertTool.Fmt(NetWorkService.NowSent), ByteConvertTool.Fmt(NetWorkService.NowReceived));
                            status.Text += string.Format("\n单位时间:{0}分钟,上传流量:{1},下载流量:{2}",
                                                         NetWorkService.ThresholdTime, ByteConvertTool.Fmt(NetWorkService.UnitSent), ByteConvertTool.Fmt(NetWorkService.UnitReceived));
                            status.Text += string.Format("\n当前时间:{0},下次刷新时间:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), NetWorkService.CalcTime.ToString("yyyy-MM-dd HH:mm:ss"));

                            if ((NetWorkService.UnitSent + NetWorkService.UnitReceived) < NetWorkService.FlowThreshold || DateTime.Now > MaxTime)
                            {
                                NetWorkService.WriteRecord(BeginTime, DateTime.Now, netProcesses, IP);
                                this.Dispose();
                            }
                        }));
                        Thread.Sleep(1000);
                    }
                }
                catch { }
            });
            CaptureInit();
            Task.Factory.StartNew(() => { try { _rs.Capture(); } catch { } });
            #endregion
        }
Пример #13
0
 /// <summary>
 /// 获取文件大小信息(自动适配)(如:1MB,10KB...)
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static string SizeFormat(string fileName)
 {
     return(ByteConvertTool.Fmt(Size(fileName)));
 }
Пример #14
0
 /// <summary>
 /// 获取文件大小(根据单位换算)
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="unit">B,KB,MB,GB</param>
 /// <returns></returns>
 public static double Size(string fileName, string unit)
 {
     return(ByteConvertTool.Cvt(Size(fileName), unit));
 }
Пример #15
0
 public void DataMonitorEvent(NetFlowTool n)
 {
     R.Log.v("upload data: " + ByteConvertTool.Fmt(n.UploadData) +
             " download data: " + ByteConvertTool.Fmt(n.DownloadData));
 }
Пример #16
0
 private void DGVList_Select(int index)
 {
     if (index >= 0 && index < DGVList.RowCount)
     {
         string        id   = DGVList.Rows[index].Cells["COLId"].Value.ToString();
         ClipboardData data = ClipboardDataMan.Get(id);
         if (data != null)
         {
             TBText.Clear();
             PBImage.Image = null;
             DGVData.Rows.Clear();
             DGVData.Columns.Clear();
             //显示信息大小
             TSSLDataSize.Text = ByteConvertTool.Fmt(data.Size);
             //设置富文本
             //if (data.RichText != null)
             //{
             //    try
             //    {
             //        using (Stream s = new MemoryStream())
             //        {
             //            s.Position = 0;
             //            s.Write(data.RichText, 0, data.RichText.Length);
             //            s.Position = 0;
             //            RTBRich.LoadFile(s, RichTextBoxStreamType.RichText);
             //        }
             //    }
             //    catch (Exception e) { }
             //}
             //设置纯文本
             if (data.Text != null)
             {
                 //TCData.SelectTab("TPText");
                 TBText.AppendText(data.Text);
             }
             //设置表格
             if (data.Text != null)
             {
                 string[] rows = data.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                 foreach (var _r in rows)
                 {
                     string[] _d = _r.Split('\t');
                     if (ListTool.HasElements(_d))
                     {
                         if (DGVData.Columns.Count < _d.Length)
                         {
                             for (int i = DGVData.Columns.Count; i < _d.Length; i++)
                             {
                                 DGVData.Columns.Add($"DGVData_COL{i}", $"{i + 1}");
                             }
                         }
                         DGVData.Rows.Add(_d);
                     }
                 }
             }
             //设置图片
             if (data.Image != null)
             {
                 //TCData.SelectTab("TPImage");
                 PBImage.Image = data.Image;
                 PBImage.Update();
             }
         }
     }
 }
Пример #17
0
        private void FileRestoreForm_Load(object sender, EventArgs e)
        {
            //读取该文件的备份记录
            using (var db = new Muse())
            {
                Files = db.Gets <BackupFiles>(x => x.FullPath == FilePath, null).OrderBy(x => x.Id).ToList();
            }
            if (ListTool.HasElements(Files))
            {
                //获取文件名及路径信息
                var first = Files.FirstOrDefault();
                LbFileName.Text = Path.GetFileName(first.FullPath);
                LbPath.Text     = first.FullPath;
                LbVersion.Text  = "共 " + Files.Count + " 版";

                TtLabel.SetToolTip(LbFileName, Path.GetFileName(first.FullPath));
                TtLabel.SetToolTip(LbPath, first.FullPath);

                //显示所有备份记录
                int index = 1;
                foreach (var file in Files)
                {
                    DgvFiles.Rows.Add(string.Format("第 {0} 版", index++), file.LastWriteTime, ByteConvertTool.Fmt(file.Size));
                }
            }
        }