Beispiel #1
0
 public DataInfo()
 {
     time = DateTime.Now;
     if (Set.IncludeProcesses)
     {
         processes = ProcessInfo.GetProcessInfos(GetProcessList()).ToArray();
     }
     if (Set.IncludeWindows)
     {
         windows = GetAllWindowsInfo();
     }
     if (Set.IncludeBattery)
     {
         battery = new BatteryInfo(GetBatteryStatus());
     }
     if (Set.IncludeNetwork)
     {
         pingInfos = GetNetworkStatus();
     }
     if (Set.IncludePerformance)
     {
         performance = new PerformanceInfo();
     }
     foregroundWindow = GetForegroundWindowInfo();
     mouseMoved       = MouseMoved();
 }
Beispiel #2
0
        private XmlElement GetPerformanceXml(PerformanceInfo p)
        {
            XmlElement element = xmlDocument.CreateElement("Performance");

            element.SetAttribute("CpuUsagePercent", p.CpuUsagePercent.ToString());
            element.SetAttribute("FreePhysical", p.FreePhysicalMemory.ToString());
            element.SetAttribute("TotalPhysical", p.TotalPhysicalMemory.ToString());
            element.SetAttribute("FreePage", p.FreePageFile.ToString());
            element.SetAttribute("TotalPage", p.TotalPageFile.ToString());
            element.SetAttribute("MainDiskPartitionTotalSize", p.MainDiskPartitionTotalSize.ToString());
            element.SetAttribute("MainDiskPartitionFreeSize", p.MainDiskPartitionFreeSize.ToString());
            return(element);
        }
        public PgPerformanceDetail(PerformanceInfo performances)
        {
            InitializeComponent();
            lvw.CloseTriggers();


            infos.Add(new KeyValueRawValueInfo("CPU使用率", performances.CpuUsagePercent + "%", performances.CpuUsagePercent));
            infos.Add(new KeyValueRawValueInfo());
            infos.Add(new KeyValueRawValueInfo("物理内存总量", ByteToFitString(performances.TotalPhysicalMemory), performances.TotalPhysicalMemory));
            infos.Add(new KeyValueRawValueInfo("物理内存已用", ByteToFitString(performances.TotalPhysicalMemory - performances.FreePhysicalMemory), performances.TotalPhysicalMemory - performances.FreePhysicalMemory));
            infos.Add(new KeyValueRawValueInfo("物理内存可用", ByteToFitString(performances.FreePhysicalMemory), performances.FreePhysicalMemory));
            infos.Add(new KeyValueRawValueInfo());
            infos.Add(new KeyValueRawValueInfo("页面文件总量", ByteToFitString(performances.TotalPageFile), performances.TotalPageFile));
            infos.Add(new KeyValueRawValueInfo("页面文件已用", ByteToFitString(performances.TotalPageFile - performances.FreePageFile), performances.TotalPageFile - performances.FreePageFile));
            infos.Add(new KeyValueRawValueInfo("页面文件可用", ByteToFitString(performances.FreePageFile), performances.FreePageFile));
            infos.Add(new KeyValueRawValueInfo());
            infos.Add(new KeyValueRawValueInfo("主分区总量", performances.MainDiskPartitionTotalSize == -1 ? "未知" : ByteToFitString(performances.MainDiskPartitionTotalSize), performances.MainDiskPartitionTotalSize));
            infos.Add(new KeyValueRawValueInfo("主分区已用", performances.MainDiskPartitionFreeSize == -1 || performances.MainDiskPartitionTotalSize == -1 ? "未知" : ByteToFitString(performances.MainDiskPartitionTotalSize - performances.MainDiskPartitionFreeSize), performances.MainDiskPartitionTotalSize - performances.MainDiskPartitionFreeSize));
            infos.Add(new KeyValueRawValueInfo("主分区可用", performances.MainDiskPartitionFreeSize == -1 ? "未知" : ByteToFitString(performances.MainDiskPartitionFreeSize), performances.MainDiskPartitionFreeSize));



            lvw.ItemsSource = infos;
        }
Beispiel #4
0
 public DataInfo(DateTime time,
                 IEnumerable <ProcessInfo> processes,
                 IEnumerable <WindowInfo> windows,
                 BatteryInfo battery,
                 WindowInfo foregroundWindow,
                 bool mouseMoved,
                 List <PingInfo> network,
                 PerformanceInfo performance)
 {
     this.time = time;
     if (processes != null)
     {
         this.processes = processes.ToArray();
     }
     if (windows != null)
     {
         this.windows = windows.ToArray();
     }
     this.battery          = battery;
     this.foregroundWindow = foregroundWindow;
     this.mouseMoved       = mouseMoved;
     this.pingInfos        = network;
     this.performance      = performance;
 }
Beispiel #5
0
        private void DrawPoints()
        {
            Values.Clear();
            Dictionary <DateTime, PerformanceInfo> performanceInfos = new Dictionary <DateTime, PerformanceInfo>();

            foreach (var element in xml.dataElements)
            {
                DateTime dateTime = DateTime.Parse(element.GetAttribute("Time"));
                DateTime date     = dateTime.Date;
                if (date > dateRange.DateTo || date < dateRange.DateFrom)
                {
                    continue;
                }

                XmlElement child = element.ChildNodes.Cast <XmlElement>().FirstOrDefault(p => p.Name == "Performance");
                if (child != null)
                {
                    try
                    {
                        performanceInfos.Add(dateTime, XmlHelper.GetPerformanceInfo(child));
                    }
                    catch
                    {
                    }
                }
            }



            foreach (var item in performanceInfos)
            {
                DateTime        time = item.Key;
                PerformanceInfo per  = item.Value;
                switch (cbbType.SelectedIndex)
                {
                case 0:
                    Values.Add(new DateTimePerformanceInfo(time, per.TotalPhysicalMemory - per.FreePhysicalMemory));
                    break;

                case 1:
                    Values.Add(new DateTimePerformanceInfo(time, per.FreePhysicalMemory));
                    break;

                case 2:
                    Values.Add(new DateTimePerformanceInfo(time, per.TotalPageFile - per.FreePageFile));
                    break;

                case 3:
                    Values.Add(new DateTimePerformanceInfo(time, per.FreePageFile));
                    break;

                case 4:
                    Values.Add(new DateTimePerformanceInfo(time, per.MainDiskPartitionTotalSize - per.MainDiskPartitionFreeSize));
                    break;

                case 5:
                    Values.Add(new DateTimePerformanceInfo(time, per.MainDiskPartitionFreeSize));
                    break;

                case 6:
                    Values.Add(new DateTimePerformanceInfo(time, per.CpuUsagePercent));
                    break;
                }
            }

            isCpuUsage = false;
            switch (cbbType.SelectedIndex)
            {
            case 0:
                axisY.MaxValue = performanceInfos.Max(p => p.Value.TotalPhysicalMemory);
                break;

            case 1:
                axisY.MaxValue = performanceInfos.Max(p => p.Value.TotalPhysicalMemory);
                break;

            case 2:
                axisY.MaxValue = performanceInfos.Max(p => p.Value.TotalPageFile);
                break;

            case 3:
                axisY.MaxValue = performanceInfos.Max(p => p.Value.TotalPageFile);
                break;

            case 4:
                axisY.MaxValue = performanceInfos.Max(p => p.Value.MainDiskPartitionTotalSize);
                break;

            case 5:
                axisY.MaxValue = performanceInfos.Max(p => p.Value.MainDiskPartitionTotalSize);
                break;

            case 6:
                isCpuUsage     = true;
                axisY.MaxValue = 100;
                break;
            }

            axisY.MinValue = 0;
            axisX.MinValue = axisX.MaxValue = double.NaN;
        }
Beispiel #6
0
        public List <DataInfo> ReadDataHistory(int first, int last)
        {
            List <DataInfo> infos   = new List <DataInfo>();
            int             current = first;

            while (current <= last)
            {
                if (current >= DataCount)
                {
                    break;
                }

                XmlElement element                 = dataElements[current] as XmlElement;
                XmlElement winElements             = null;
                XmlElement batteryElement          = null;
                XmlElement processElements         = null;
                XmlElement foregroundWindowElement = null;
                XmlElement networkElement          = null;
                XmlElement performanceElement      = null;
                foreach (XmlElement child in element.ChildNodes)
                {
                    switch (child.Name)
                    {
                    case "Battery":
                        batteryElement = child;
                        break;

                    case "Processes":
                        processElements = child;
                        break;

                    case "Windows":
                        winElements = child;
                        break;

                    case "ForegroundWindow":
                        foregroundWindowElement = child;
                        break;

                    case "NetworkStatus":
                        networkElement = child;
                        break;

                    case "Performance":
                        performanceElement = child;
                        break;
                    }
                }

                //if (batteryElement == null || processElements == null || winElements == null || foregroundWindowElement == null)
                //{
                //    throw new Exception("XML文档被篡改");
                //}
                DateTime time = DateTime.Parse(element.GetAttribute("Time"));

                //窗口
                List <WindowInfo> wins = null;
                if (winElements != null)
                {
                    try
                    {
                        wins = new List <WindowInfo>();
                        foreach (XmlElement winElement in winElements.ChildNodes)
                        {
                            wins.Add(GetWindowInfo(winElement));
                        }
                    }
                    catch
                    {
                        wins = null;
                    }
                }

                //进程
                List <ProcessInfo> pros = null;
                if (processElements != null)
                {
                    try
                    {
                        pros = new List <ProcessInfo>();
                        foreach (XmlElement processElement in processElements.ChildNodes)
                        {
                            pros.Add(GetProcessInfo(processElement));
                        }
                    }
                    catch
                    {
                        pros = null;
                    }
                }

                //电池
                BatteryInfo battery = null;
                if (batteryElement != null)
                {
                    try
                    {
                        battery = GetBatteryInfo(batteryElement);
                    }
                    catch
                    {
                        battery = null;
                    }
                }

                //前台窗口
                WindowInfo foreground = GetWindowInfo(foregroundWindowElement);
                bool       mouseMoved = false;
                if (element.HasAttribute("MouseMoved"))
                {
                    mouseMoved = bool.Parse(element.GetAttribute("MouseMoved"));
                }

                //网络
                List <PingInfo> pings = new List <PingInfo>();
                if (networkElement != null)
                {
                    try
                    {
                        foreach (XmlElement child in networkElement)
                        {
                            pings.Add(new PingInfo(child.GetAttribute("Address"),
                                                   int.Parse(child.GetAttribute("Time")),
                                                   child.HasAttribute("Result") ? ((IPStatus)Enum.Parse(typeof(IPStatus), child.GetAttribute("Result"))) : IPStatus.Unknown));
                        }
                    }
                    catch
                    {
                        pings = null;
                    }
                }

                PerformanceInfo performance = null;
                //性能
                if (performanceElement != null)
                {
                    try
                    {
                        performance = GetPerformanceInfo(performanceElement);
                    }
                    catch
                    {
                        performance = null;
                    }
                }

                DataInfo history = new DataInfo(time, pros, wins, battery, foreground, mouseMoved, pings, performance);
                infos.Add(history);

                current++;
            }
            return(infos);
        }