Пример #1
0
        public void Thread_WriteData(object sender, DoWorkEventArgs e)
        {
            // Work forever
            for(long i=0; ; i++)
            {

                
                    Application.Current.Dispatcher.BeginInvoke
                    (
                        DispatcherPriority.DataBind,
                        new Action(() =>
                        {
                            try
                            {

                                /*
                                 *  Data Read
                                */
                                #region Read

                                int iCPUcore1_usage = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName == "CPU [#0]: Intel Core-2400").sensorReaders.Find(f => f.szName == "Core #0 Thread #0 Usage").Value);
                                int iCPUcore2_usage = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026532608).sensorReaders.Find(f => f.szName == "Core #1 Thread #0 Usage").Value);
                                int iCPUcore3_usage = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026532608).sensorReaders.Find(f => f.szName == "Core #2 Thread #0 Usage").Value);
                                int iCPUcore4_usage = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026532608).sensorReaders.Find(f => f.szName == "Core #3 Thread #0 Usage").Value);
                                int iCPUtotal_usage = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026532608).sensorReaders.Find(f => f.szName == "Total CPU Usage").Value);
                                double fCPUCLOCK = Math.Round(this.sensorElementsDataArray.Find(f => f.szName == "CPU [#0]: Intel Core-2400").sensorReaders.Find(f => f.szName == "Core #0 Clock").Value);
                                double fCPUPOWER = Math.Round(this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026542592).sensorReaders.Find(f => f.szName == "CPU Package Power").Value, 1);
                                int iCPUTEMPERATURE = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026542592).sensorReaders.Find(f => f.szName == "CPU Package").Value);

                                // Memory
                                int memoryUsed = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName == "System").sensorReaders.Find(f => f.szName == "Physical Memory Used").Value);
                                int memoryAvailable = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName == "System").sensorReaders.Find(f => f.szName == "Physical Memory Available").Value);
                                int memoryUsage = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName == "System").sensorReaders.Find(f => f.szName == "Physical Memory Load").Value);


                                //Network
                                int networkTotalDL = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Total DL").Value);
                                int networkTotalUL = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Total UP").Value);
                                double networkCurrentDL = Math.Round(this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Current DL rate").Value, 1);
                                double networkCurrentUL = Math.Round(this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Current UP rate").Value, 1);


                                #region Disks
                                ObservableCollection<Disk> tempDiskColl = new ObservableCollection<Disk>();
                                foreach(Disk disk in Database.DISKS)
                                {
                                    Disk tempdisk = new Disk(disk.driveLetter, disk.sensorName);
                                    tempdisk.readRate = Math.Round(this.sensorElementsDataArray.Find(f => f.szName.Contains(disk.sensorName)).sensorReaders.Find(f => f.szName == "Read Rate").Value, 1).ToString() + " MB/s";
                                    tempdisk.writeRate = Math.Round(this.sensorElementsDataArray.Find(f => f.szName.Contains(disk.sensorName)).sensorReaders.Find(f => f.szName == "Write Rate").Value, 1).ToString() + " MB/s";
                                    tempdisk.diskUsage = Math.Round(this.sensorElementsDataArray.Find(f => f.szName.Contains(disk.sensorName)).sensorReaders.Find(f => f.szName == "Total Activity").Value, 1);
                                    tempdisk.totalSpace = Math.Round((((double)this.DriveDataList.First(f => f.Name == disk.driveLetter + @":\").TotalSize / 1048576) / 1024), 1).ToString() + " GB";
                                    tempdisk.freeSpace = Math.Round((((double)this.DriveDataList.First(f => f.Name == disk.driveLetter + @":\").TotalFreeSpace / 1048576) / 1024), 1).ToString() + " GB";
                                    tempdisk.spaceUsage = Math.Abs(Math.Round((Math.Round((((double)this.DriveDataList.First(f => f.Name == disk.driveLetter + @":\").TotalFreeSpace / 1048576) / 1024), 1) / Math.Round((((double)this.DriveDataList.First(f => f.Name == disk.driveLetter + @":\").TotalSize / 1048576) / 1024), 1)) * 100) - 100);
                                    tempDiskColl.Add(tempdisk);
                                }

                                Database.DISKS.Clear();

                                foreach(Disk disk in tempDiskColl)
                                {
                                    Database.DISKS.Add(disk);
                                }
                                tempDiskColl.Clear();
                                #endregion

                                #region GPUS
                                ObservableCollection<GPU> tempGPUColl = new ObservableCollection<GPU>();

                                foreach (GPU gpu in Database.GPUS)
                                {
                                    GPU tempGPU = new GPU(gpu.sensorName);

                                    tempGPU.voltage = Math.Round(this.sensorElementsDataArray.Find(f => f.szName.Contains(tempGPU.sensorName)).sensorReaders.Find(f => f.szName == "GPU Core Voltage").Value, 3).ToString() + " V";
                                    tempGPU.temp = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName.Contains(tempGPU.sensorName)).sensorReaders.Find(f => f.szName == "GPU Temperature").Value).ToString() + " °C";
                                    tempGPU.coreClock = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName.Contains(tempGPU.sensorName)).sensorReaders.Find(f => f.szName == "GPU Clock").Value).ToString() + " MHz";
                                    tempGPU.vramClock = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName.Contains(tempGPU.sensorName)).sensorReaders.Find(f => f.szName == "GPU Memory Clock").Value).ToString() + " MHz";
                                    tempGPU.usedVRAM = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName.Contains(tempGPU.sensorName)).sensorReaders.Find(f => f.szName == "GPU Memory Allocated").Value).ToString() + " MB";
                                    tempGPU.usedVRAMUsage = Convert.ToInt32(this.sensorElementsDataArray.Find(f => f.szName.Contains(tempGPU.sensorName)).sensorReaders.Find(f => f.szName == "GPU Memory Usage").Value);

                                    tempGPUColl.Add(tempGPU);
                                }

                                Database.GPUS.Clear();

                                foreach (GPU gpu in tempGPUColl)
                                {
                                    Database.GPUS.Add(gpu);
                                }

                                tempGPUColl.Clear();

                                #endregion

                                #endregion

                                /*
                                 *  Data Write
                                */
                                #region Write

                                //CPU
                                Database.CPU_CPUCLOCK = fCPUCLOCK.ToString() + " MHz"; // + this.sensorElementsDataArray.Find(f => f.szName == "CPU [#0]: Intel Core-2400").sensorReaders.Find(f => f.szName == "Core #0 Clock").szUnit;
                                Database.CPU_CPUPOWER = fCPUPOWER.ToString() + " W"; // +this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026542592).sensorReaders.Find(f => f.szName == "CPU Package Power").szUnit;
                                Database.CPU_CPUTEMPERATURE = iCPUTEMPERATURE.ToString() + " °C";// +this.sensorElementsDataArray.Find(f => f.dwSensorID == 4026542592).sensorReaders.Find(f => f.szName == "CPU Package").szUnit;
                                
                                // RAM
                                Database.RAM_FREERAM = memoryAvailable.ToString()  + " MB"; // + this.sensorElementsDataArray.Find(f => f.szName == "System").sensorReaders.Find(f => f.szName == "Physical Memory Used").szUnit;
                                Database.RAM_USEDRAM = memoryUsed.ToString() + " MB"; // this.sensorElementsDataArray.Find(f => f.szName == "System").sensorReaders.Find(f => f.szName == "Physical Memory Used").szUnit;
                                Database.RAM_USAGE = (double)memoryUsage;

                                // Network
                                Database.NETWORK_DL_TOTAL = networkTotalDL.ToString() + " MB"; //+ this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Total DL").szUnit;
                                Database.NETWORK_UL_TOTAL = networkTotalUL.ToString() + " MB"; // + this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Total UP").szUnit;
                                Database.NETWORK_DL_CURRENT = networkCurrentDL.ToString() + " KB/s"; // + this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Current DL rate").szUnit;
                                Database.NETWORK_UL_CURRENT = networkCurrentUL.ToString() + " KB/s"; // + this.sensorElementsDataArray.Find(f => f.szName.Contains(CONFIG_NETWORK_SENSOR_NAME)).sensorReaders.Find(f => f.szName == "Current UP rate").szUnit;


                                if (CONFIG_USES_CPU_CHART)
                                {
                                    // CPU Chart
                                    if (Database.CPU_CHART_VALUES.Count >= CHARTS_NODES)
                                        Database.CPU_CHART_VALUES.Remove(Database.CPU_CHART_VALUES[0]);
                                    Database.CPU_CHART_VALUES.Add(new KeyValuePair<string, int>(i.ToString(), iCPUtotal_usage));
                                    Database.CPU_CPUUSAGE = iCPUtotal_usage;
                                }

                                if (CONFIG_USES_NETWORK_CHART)
                                {
                                    // Network Chart
                                    if (Database.NETWORK_CHART_VALUES.Count >= CHARTS_NODES)
                                        Database.NETWORK_CHART_VALUES.Remove(Database.NETWORK_CHART_VALUES[0]);
                                    Database.NETWORK_CHART_VALUES.Add(new KeyValuePair<string, int>(i.ToString(), Convert.ToInt32(networkCurrentDL)));
                                }

                                #endregion

                            }
                            catch(Exception )
                            {
                                // Honestly I dont give a shit at the moment :)
                            }
                            
                        })
                    );
                

                Thread.Sleep(this.SLEEP_INTERVAL);
 
            }
            
        }
Пример #2
0
        private void Window_Initialized(object sender, EventArgs e)
        {


            IntPtr hWnd = new WindowInteropHelper(this).Handle;


            
            SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);

            IntPtr windowHandle = (new WindowInteropHelper(this)).Handle;
            HwndSource src = HwndSource.FromHwnd(windowHandle);
            src.AddHook(new HwndSourceHook(WndProc));


            this.hwW = new HWiNFOWrapper();
            this.sensorElementsDataArray = hwW.GetSensorData();
            this.DriveDataList = DriveInfo.GetDrives();

            #region TEST MODE
            // DEBUG PURPOSES ONLY
            if (TEST_MODE)
            {

                if (!System.IO.File.Exists(@"C:\Users\Kama3\Documents\Visual Studio 2013\Projects\GodlikeWidgets\GodlikeWidgets\test2.txt"))
                    System.IO.File.Create(@"C:\Users\Kama3\Documents\Visual Studio 2013\Projects\GodlikeWidgets\GodlikeWidgets\test2.txt");

                FileStream fs = File.Open(@"C:\Users\Kama3\Documents\Visual Studio 2013\Projects\GodlikeWidgets\GodlikeWidgets\test2.txt", FileMode.Truncate, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);

                foreach (Struct_SensorElement sensorElement in sensorElementsDataArray)
                {
                    sw.WriteLine(String.Format("Sensor Name: {0}", sensorElement.szName));
                    sw.WriteLine(String.Format("Sensor ID: {0}", sensorElement.dwSensorID));

                    foreach (Struct_SensorElementReader sensorReader in sensorElement.sensorReaders)
                    {
                        sw.WriteLine(String.Format("\tSensor Name: {0}", sensorReader.szName));
                        sw.WriteLine(String.Format("\tSensor Units: {0}", sensorReader.szUnit));
                        sw.WriteLine(String.Format("\tSensor Type: {0}", Enum.GetName(typeof(SENSOR_READING_TYPE), sensorReader.tReading)));
                        sw.WriteLine(String.Format("\tSensor Value: {0}", sensorReader.Value));
                        sw.Write("\n");
                    }

                    sw.Write("\n");
                }


                sw.Flush();
                fs.Flush();
                sw.Close();
                fs.Close();
            }
            #endregion

            // Initialize lists, just one time
            Database.CPU_CHART_VALUES = new ObservableCollection<KeyValuePair<string, int>>();
            Database.NETWORK_CHART_VALUES = new ObservableCollection<KeyValuePair<string, int>>();
            this.processUsageList = new Dictionary<string, int>();
            Database.DISKS = new ObservableCollection<Disk>();
            Database.GPUS = new ObservableCollection<GPU>();


            // Test disk
            Disk disk_C = new Disk("C", CONFIG_DISK1_SENSOR_NAME);
            Disk disk_F = new Disk("F", CONFIG_DISK2_SENSOR_NAME);

            Database.DISKS.Add(disk_C);
            Database.DISKS.Add(disk_F);

            // Test GPU

            GPU gpu1 = new GPU(CONFIG_GPU1_SENSOR_NAME);
            GPU gpu2 = new GPU(CONFIG_GPU2_SENSOR_NAME);

            Database.GPUS.Add(gpu1);
            Database.GPUS.Add(gpu2);


            // Fil charts with zeroes
            for (int i = 0; i < CHARTS_NODES + 1; i++)
            {
                Database.CPU_CHART_VALUES.Add(new KeyValuePair<string, int>(i.ToString(), 0));
            }


            for (int i = 0; i < CHARTS_NODES+1; i++)
            {
                Database.NETWORK_CHART_VALUES.Add(new KeyValuePair<string, int>(i.ToString(), 0));
            }

            // Start ReadData Thread
            t_oReadDataBackgroundWorker = new BackgroundWorker();
            t_oReadDataBackgroundWorker.DoWork += new DoWorkEventHandler(Thread_ReadData);
            t_oReadDataBackgroundWorker.WorkerSupportsCancellation = true;
            t_oReadDataBackgroundWorker.WorkerReportsProgress = false;
            t_oReadDataBackgroundWorker.RunWorkerAsync();

            // Start WriteData Thread
            t_oWriteDataBackgroundWorker = new BackgroundWorker();
            t_oWriteDataBackgroundWorker.DoWork += new DoWorkEventHandler(Thread_WriteData);
            t_oWriteDataBackgroundWorker.WorkerSupportsCancellation = true;
            t_oWriteDataBackgroundWorker.WorkerReportsProgress = false;
            t_oWriteDataBackgroundWorker.RunWorkerAsync();

           
        }