Exemplo n.º 1
0
        /// <summary>
        /// Event excuted with the timer.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private async void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            int fpsValue  = 0;
            int cpuValue  = GetCpuPercentage();
            int gpuValue  = 0;
            int ramValue  = GetRamPercentage();
            int gpuTValue = 0;
            int cpuTValue = 0;


            if (settings.UseMsiAfterburner)
            {
                var MSIAfterburner = new MSIAfterburnerNET.HM.HardwareMonitor();

                fpsValue  = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.FRAMERATE).Data;
                gpuValue  = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.GPU_USAGE).Data;
                gpuTValue = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.GPU_TEMPERATURE).Data;
                cpuTValue = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.CPU_TEMPERATURE).Data;
            }
            else if (settings.UseHWiNFO)
            {
                HWiNFODumper HWinFO = new HWiNFODumper();
                List <HWiNFODumper.JsonObj> dataHWinfo = HWinFO.ReadMem();

                foreach (var sensorItems in dataHWinfo)
                {
                    JObject sensorItemsOBJ = JObject.Parse(JsonConvert.SerializeObject(sensorItems));

                    string sensorsID = "0x" + ((uint)sensorItemsOBJ["szSensorSensorID"]).ToString("X");

                    // Find sensors fps
                    if (sensorsID.ToLower() == settings.HWiNFO_fps_sensorsID.ToLower())
                    {
                        // Find data fps
                        foreach (var items in sensorItemsOBJ["sensors"])
                        {
                            JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                            string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                            //logger.Info("----- " + dataID.ToLower() + " - " + settings.HWiNFO_fps_elementID.ToLower());

                            if (dataID.ToLower() == settings.HWiNFO_fps_elementID.ToLower())
                            {
                                fpsValue = (int)Math.Round((Double)itemOBJ["Value"]);
                            }
                        }
                    }

                    // Find sensors gpu usage
                    if (sensorsID.ToLower() == settings.HWiNFO_gpu_sensorsID.ToLower())
                    {
                        // Find data gpu
                        foreach (var items in sensorItemsOBJ["sensors"])
                        {
                            JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                            string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                            //logger.Info("----- " + dataID.ToLower() + " - " + settings.HWiNFO_gpu_elementID.ToLower());

                            if (dataID.ToLower() == settings.HWiNFO_gpu_elementID.ToLower())
                            {
                                gpuValue = (int)Math.Round((Double)itemOBJ["Value"]);
                            }
                        }
                    }

                    // Find sensors gpu temp
                    if (sensorsID.ToLower() == settings.HWiNFO_gpuT_sensorsID.ToLower())
                    {
                        // Find data gpu
                        foreach (var items in sensorItemsOBJ["sensors"])
                        {
                            JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                            string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                            //logger.Info("----- " + dataID.ToLower() + " - " + settings.HWiNFO_gpu_elementID.ToLower());

                            if (dataID.ToLower() == settings.HWiNFO_gpuT_elementID.ToLower())
                            {
                                gpuTValue = (int)Math.Round((Double)itemOBJ["Value"]);
                            }
                        }
                    }

                    // Find sensors cpu temp
                    if (sensorsID.ToLower() == settings.HWiNFO_cpuT_sensorsID.ToLower())
                    {
                        // Find data gpu
                        foreach (var items in sensorItemsOBJ["sensors"])
                        {
                            JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                            string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                            //logger.Info("----- " + dataID.ToLower() + " - " + settings.HWiNFO_gpu_elementID.ToLower());

                            if (dataID.ToLower() == settings.HWiNFO_cpuT_elementID.ToLower())
                            {
                                cpuTValue = (int)Math.Round((Double)itemOBJ["Value"]);
                            }
                        }
                    }
                }
            }


            // Listing warnings
            bool WarningMinFps      = false;
            bool WarningMaxCpuTemp  = false;
            bool WarningMaxGpuTemp  = false;
            bool WarningMaxCpuUsage = false;
            bool WarningMaxGpuUsage = false;
            bool WarningMaxRamUsage = false;

            if (settings.EnableWarning)
            {
                if (settings.MinFps != 0 && settings.MinFps >= fpsValue)
                {
                    WarningMinFps = true;
                }
                if (settings.MaxCpuTemp != 0 && settings.MaxCpuTemp <= cpuTValue)
                {
                    WarningMaxCpuTemp = true;
                }
                if (settings.MaxGpuTemp != 0 && settings.MaxGpuTemp <= gpuTValue)
                {
                    WarningMaxGpuTemp = true;
                }
                if (settings.MaxCpuUsage != 0 && settings.MaxCpuUsage <= cpuValue)
                {
                    WarningMaxCpuUsage = true;
                }
                if (settings.MaxGpuUsage != 0 && settings.MaxGpuUsage <= gpuValue)
                {
                    WarningMaxGpuUsage = true;
                }
                if (settings.MaxRamUsage != 0 && settings.MaxRamUsage <= ramValue)
                {
                    WarningMaxRamUsage = true;
                }

                JArray Message = new JArray
                {
                    new JObject(new JProperty("At", resources.GetString("LOCGameActivityWarningAt") + " " + DateTime.Now.ToString("HH:mm"))),
                    new JObject(new JProperty("Name", resources.GetString("LOCGameActivityFps")), new JProperty("Value", fpsValue), new JProperty("isWarm", WarningMinFps)),
                    new JObject(new JProperty("Name", resources.GetString("LOCGameActivityCpuTemp")), new JProperty("Value", cpuTValue), new JProperty("isWarm", WarningMaxCpuTemp)),
                    new JObject(new JProperty("Name", resources.GetString("LOCGameActivityGpuTemp")), new JProperty("Value", gpuTValue), new JProperty("isWarm", WarningMaxGpuTemp)),
                    new JObject(new JProperty("Name", resources.GetString("LOCGameActivityCpuUsage")), new JProperty("Value", cpuValue), new JProperty("isWarm", WarningMaxCpuUsage)),
                    new JObject(new JProperty("Name", resources.GetString("LOCGameActivityGpuUsage")), new JProperty("Value", gpuValue), new JProperty("isWarm", WarningMaxGpuUsage)),
                    new JObject(new JProperty("Name", resources.GetString("LOCGameActivityRamUsage")), new JProperty("Value", ramValue), new JProperty("isWarm", WarningMaxRamUsage))
                };

                if (WarningMinFps || WarningMaxCpuTemp || WarningMaxGpuTemp || WarningMaxCpuUsage || WarningMaxGpuUsage)
                {
                    WarningsMessage.Add(Message);
                }
            }



            JObject Data = new JObject();

            Data["datelog"] = DateTime.Now.ToUniversalTime().ToString("o");
            Data["fps"]     = fpsValue;
            Data["cpu"]     = cpuValue;
            Data["gpu"]     = gpuValue;
            Data["ram"]     = ramValue;
            Data["gpuT"]    = gpuTValue;
            Data["cpuT"]    = cpuTValue;

            LoggingData.Add(Data);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event excuted with the timer.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private async void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            int fpsValue  = 0;
            int cpuValue  = PerfCounter.GetCpuPercentage();
            int gpuValue  = PerfCounter.GetGpuPercentage();
            int ramValue  = PerfCounter.GetRamPercentage();
            int gpuTValue = PerfCounter.GetGpuTemperature();
            int cpuTValue = PerfCounter.GetCpuTemperature();


            if (settings.UseMsiAfterburner && CheckGoodForLogging())
            {
                MSIAfterburnerNET.HM.HardwareMonitor MSIAfterburner = null;

                try
                {
                    MSIAfterburner = new MSIAfterburnerNET.HM.HardwareMonitor();
                }
                catch (Exception ex)
                {
                    logger.Warn("GameActivity - Fail initialize MSIAfterburnerNET");
#if DEBUG
                    Common.LogError(ex, "GameActivity [Ignored]", "Fail initialize MSIAfterburnerNET");
#endif
                }

                if (MSIAfterburner != null)
                {
                    try
                    {
                        fpsValue = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.FRAMERATE).Data;
                    }
                    catch (Exception ex)
                    {
                        logger.Warn("GameActivity - Fail get fpsValue");
#if DEBUG
                        Common.LogError(ex, "GameActivity [Ignored]", "Fail get fpsValue");
#endif
                    }

                    try
                    {
                        if (gpuValue == 0)
                        {
                            gpuValue = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.GPU_USAGE).Data;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn("GameActivity - Fail get gpuValue");
#if DEBUG
                        Common.LogError(ex, "GameActivity [Ignored]", "Fail get gpuValue");
#endif
                    }

                    try
                    {
                        if (gpuTValue == 0)
                        {
                            gpuTValue = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.GPU_TEMPERATURE).Data;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn("GameActivity - Fail get gpuTValue");
#if DEBUG
                        Common.LogError(ex, "GameActivity [Ignored]", "Fail get gpuTValue");
#endif
                    }

                    try
                    {
                        if (cpuTValue == 0)
                        {
                            cpuTValue = (int)MSIAfterburner.GetEntry(MONITORING_SOURCE_ID.CPU_TEMPERATURE).Data;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn("GameActivity - Fail get cpuTValue");
#if DEBUG
                        Common.LogError(ex, "GameActivity [Ignored]", "Fail get cpuTValue");
#endif
                    }
                }
            }
            else if (settings.UseHWiNFO && CheckGoodForLogging())
            {
                HWiNFODumper HWinFO = null;
                List <HWiNFODumper.JsonObj> dataHWinfo = null;

                try
                {
                    HWinFO     = new HWiNFODumper();
                    dataHWinfo = HWinFO.ReadMem();
                }
                catch (Exception ex)
                {
                    logger.Warn("GameActivity - Fail initialize HWiNFODumper");
#if DEBUG
                    Common.LogError(ex, "GameActivity [Ignored]", "Fail initialize HWiNFODumper");
#endif
                }

                if (HWinFO != null && dataHWinfo != null)
                {
                    try
                    {
                        foreach (var sensorItems in dataHWinfo)
                        {
                            JObject sensorItemsOBJ = JObject.Parse(JsonConvert.SerializeObject(sensorItems));

                            string sensorsID = "0x" + ((uint)sensorItemsOBJ["szSensorSensorID"]).ToString("X");

                            // Find sensors fps
                            if (sensorsID.ToLower() == settings.HWiNFO_fps_sensorsID.ToLower())
                            {
                                // Find data fps
                                foreach (var items in sensorItemsOBJ["sensors"])
                                {
                                    JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                                    string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                                    if (dataID.ToLower() == settings.HWiNFO_fps_elementID.ToLower())
                                    {
                                        fpsValue = (int)Math.Round((Double)itemOBJ["Value"]);
                                    }
                                }
                            }

                            // Find sensors gpu usage
                            if (sensorsID.ToLower() == settings.HWiNFO_gpu_sensorsID.ToLower())
                            {
                                // Find data gpu
                                foreach (var items in sensorItemsOBJ["sensors"])
                                {
                                    JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                                    string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                                    if (dataID.ToLower() == settings.HWiNFO_gpu_elementID.ToLower())
                                    {
                                        gpuValue = (int)Math.Round((Double)itemOBJ["Value"]);
                                    }
                                }
                            }

                            // Find sensors gpu temp
                            if (sensorsID.ToLower() == settings.HWiNFO_gpuT_sensorsID.ToLower())
                            {
                                // Find data gpu
                                foreach (var items in sensorItemsOBJ["sensors"])
                                {
                                    JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                                    string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                                    if (dataID.ToLower() == settings.HWiNFO_gpuT_elementID.ToLower())
                                    {
                                        gpuTValue = (int)Math.Round((Double)itemOBJ["Value"]);
                                    }
                                }
                            }

                            // Find sensors cpu temp
                            if (sensorsID.ToLower() == settings.HWiNFO_cpuT_sensorsID.ToLower())
                            {
                                // Find data gpu
                                foreach (var items in sensorItemsOBJ["sensors"])
                                {
                                    JObject itemOBJ = JObject.Parse(JsonConvert.SerializeObject(items));
                                    string  dataID  = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");

                                    if (dataID.ToLower() == settings.HWiNFO_cpuT_elementID.ToLower())
                                    {
                                        cpuTValue = (int)Math.Round((Double)itemOBJ["Value"]);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn("GameActivity - Fail get HWiNFO");
#if DEBUG
                        Common.LogError(ex, "GameActivity [Ignored]", "Fail get HWiNFO");
#endif
                    }
                }
            }


            // Listing warnings
            bool WarningMinFps      = false;
            bool WarningMaxCpuTemp  = false;
            bool WarningMaxGpuTemp  = false;
            bool WarningMaxCpuUsage = false;
            bool WarningMaxGpuUsage = false;
            bool WarningMaxRamUsage = false;

            if (settings.EnableWarning)
            {
                if (settings.MinFps != 0 && settings.MinFps >= fpsValue)
                {
                    WarningMinFps = true;
                }
                if (settings.MaxCpuTemp != 0 && settings.MaxCpuTemp <= cpuTValue)
                {
                    WarningMaxCpuTemp = true;
                }
                if (settings.MaxGpuTemp != 0 && settings.MaxGpuTemp <= gpuTValue)
                {
                    WarningMaxGpuTemp = true;
                }
                if (settings.MaxCpuUsage != 0 && settings.MaxCpuUsage <= cpuValue)
                {
                    WarningMaxCpuUsage = true;
                }
                if (settings.MaxGpuUsage != 0 && settings.MaxGpuUsage <= gpuValue)
                {
                    WarningMaxGpuUsage = true;
                }
                if (settings.MaxRamUsage != 0 && settings.MaxRamUsage <= ramValue)
                {
                    WarningMaxRamUsage = true;
                }

                WarningData Message = new WarningData
                {
                    At      = resources.GetString("LOCGameActivityWarningAt") + " " + DateTime.Now.ToString("HH:mm"),
                    FpsData = new Data {
                        Name = resources.GetString("LOCGameActivityFps"), Value = fpsValue, IsWarm = WarningMinFps
                    },
                    CpuTempData = new Data {
                        Name = resources.GetString("LOCGameActivityCpuTemp"), Value = cpuTValue, IsWarm = WarningMaxCpuTemp
                    },
                    GpuTempData = new Data {
                        Name = resources.GetString("LOCGameActivityGpuTemp"), Value = gpuTValue, IsWarm = WarningMaxGpuTemp
                    },
                    CpuUsageData = new Data {
                        Name = resources.GetString("LOCGameActivityCpuUsage"), Value = cpuValue, IsWarm = WarningMaxCpuUsage
                    },
                    GpuUsageData = new Data {
                        Name = resources.GetString("LOCGameActivityGpuUsage"), Value = gpuValue, IsWarm = WarningMaxGpuUsage
                    },
                    RamUsageData = new Data {
                        Name = resources.GetString("LOCGameActivityRamUsage"), Value = ramValue, IsWarm = WarningMaxRamUsage
                    },
                };

                if (WarningMinFps || WarningMaxCpuTemp || WarningMaxGpuTemp || WarningMaxCpuUsage || WarningMaxGpuUsage)
                {
                    WarningsMessage.Add(Message);
                }
            }


            List <ActivityDetailsData> ActivitiesDetailsData = GameActivitiesLog.ItemsDetails.Get(GameActivitiesLog.GetLastSession());
            ActivitiesDetailsData.Add(new ActivityDetailsData
            {
                Datelog = DateTime.Now.ToUniversalTime(),
                FPS     = fpsValue,
                CPU     = cpuValue,
                CPUT    = cpuTValue,
                GPU     = gpuValue,
                GPUT    = gpuTValue,
                RAM     = ramValue
            });
        }