Ejemplo n.º 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();
 }
Ejemplo n.º 2
0
        private void DrawStaticPoints()
        {
            Dictionary <DateTime, BatteryInfo> batteryInfos = new Dictionary <DateTime, BatteryInfo>();

            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;
                }

                BatteryInfo battery = XmlHelper.GetBatteryInfo(element.ChildNodes.Cast <XmlElement>().FirstOrDefault(p => p.Name == "Battery"));
                batteryInfos.Add(dateTime, battery);
            }



            foreach (var item in batteryInfos)
            {
                DateTime    time    = item.Key;
                BatteryInfo battery = item.Value;

                TimeSpan currentSpan = time - dateRange.DateFrom.Value;

                double width  = currentSpan.TotalMilliseconds / span.TotalMilliseconds;
                double height = cvs.Height * (1 - battery.Percent / 100.0);
                DrawPoint(width, height, battery.PowerOnline ? Brushes.Green : Brushes.Red);
            }
        }
Ejemplo n.º 3
0
        private void DrawDynamicPoints()
        {
            Values.Clear();
            Dictionary <DateTime, BatteryInfo> batteryInfos = new Dictionary <DateTime, BatteryInfo>();

            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;
                }

                BatteryInfo battery = XmlHelper.GetBatteryInfo(element.ChildNodes.Cast <XmlElement>().FirstOrDefault(p => p.Name == "Battery"));
                batteryInfos.Add(dateTime, battery);
            }

            foreach (var item in batteryInfos)
            {
                DateTime    time    = item.Key;
                BatteryInfo battery = item.Value;
                Values.Add(new DateTimeBatteryInfo(time, battery.Percent, battery.PowerOnline));
            }
            axisX.MinValue = axisX.MaxValue = double.NaN;
        }
Ejemplo n.º 4
0
        private XmlElement GetBatteryXml(BatteryInfo battery)
        {
            XmlElement element = xmlDocument.CreateElement("Battery");

            element.SetAttribute("Percent", battery.Percent.ToString());
            element.SetAttribute("PowerOnline", battery.PowerOnline.ToString());
            return(element);
        }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 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);
        }