Example #1
0
        public (float?cpu, float?ram) GetData()
        {
            updateVisitor = new UpdateVisitor();
            computer      = new Computer();
            computer.Open();
            computer.CPUEnabled = true;
            computer.GPUEnabled = true;
            computer.HDDEnabled = true;
            computer.RAMEnabled = true;
            computer.Accept(updateVisitor);

            var ram       = computer.Hardware.First(x => x.HardwareType == HardwareType.RAM);
            var ramServer = ram.Sensors.FirstOrDefault(f => f.SensorType == SensorType.Load)?.Value;

            if (source.CPU && cpuinfo.Load)
            {
                var cpuServer = computer.Hardware[source.CPUindex].Sensors[cpuinfo.LoadSensorNum - 1].Value;
                return(cpuServer, ramServer);
            }

            return(null, ramServer);
        }
Example #2
0
        static void GetSystemInfo()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();
            computer.CPUEnabled = true;
            computer.Accept(updateVisitor);
            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
                        }
                    }
                }
            }
            computer.Close();
        }
        static void GetSystemInfo()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      MyComputer    = new Computer();

            MyComputer.Open();
            MyComputer.CPUEnabled           = true;
            MyComputer.GPUEnabled           = true;
            MyComputer.RAMEnabled           = true;
            MyComputer.MainboardEnabled     = true;
            MyComputer.FanControllerEnabled = true;
            MyComputer.HDDEnabled           = true;
            MyComputer.Accept(updateVisitor);
            for (int i = 0; i < MyComputer.Hardware.Length; i++)
            {
                for (int j = 0; j < MyComputer.Hardware[i].Sensors.Length; j++)
                {
                    Console.WriteLine("Hardware[" + i.ToString().PadRight(3) + "] sensor [" + j.ToString().PadRight(3) + "]-> " + MyComputer.Hardware[i].Sensors[j].Name.PadLeft(20) + MyComputer.Hardware[i].Sensors[j].SensorType.ToString().PadLeft(30) + "    " + MyComputer.Hardware[i].Sensors[j].Identifier.ToString().PadLeft(30) + "   ->   " + MyComputer.Hardware[i].Sensors[j].Value.ToString().PadLeft(10) + "\r");
                }
            }

            MyComputer.Close();
        }
Example #4
0
        public double GetCpuTemp()
        {
            if (updateVisitor == null)
            {
                updateVisitor = new UpdateVisitor();
            }

            if (computer == null)
            {
                computer = new Computer();
                computer.Open();
                computer.CPUEnabled = true;
            }

            computer.Accept(updateVisitor);

            if (sensor == null)
            {
                sensor = computer.Hardware.Where(i => i.HardwareType == HardwareType.CPU).FirstOrDefault()?.Sensors.Where(s => s.SensorType == SensorType.Temperature).LastOrDefault();
            }

            return((double)sensor.Value);
        }
        static void GetSystemInfo()
        {
            float[]       temps         = new float[5];
            int           idx           = 0;
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();
            computer.CPUEnabled = true;

            computer.Accept(updateVisitor);

            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "°\r");
                            temps[idx] = (float)computer.Hardware[i].Sensors[j].Value;
                            idx++;
                        }
                    }
                }
            }
            if (isFirst)
            {
                data.Add(temps);
            }
            else
            {
                data2.Add(temps);
            }
            computer.Close();
        }
Example #6
0
        public static SensorInfo[] CPUTemp(Computer computer, UpdateVisitor updateVisitor)
        {
            computer.Open();
            SensorInfo[] sensorInfos = new SensorInfo[4];
            computer.Accept(updateVisitor);


            foreach (IHardware hardware in computer.Hardware)
            {
                if (hardware.HardwareType == HardwareType.CPU)
                {
                    int coreCounter = 0;
                    foreach (ISensor sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Temperature)
                        {
                            if (coreCounter == sensorInfos.Length)
                            {
                                return(sensorInfos);
                            }


                            SensorInfo coreInfo = new SensorInfo();
                            coreInfo.sensorName  = sensor.Name.ToString();
                            coreInfo.sensorValue = sensor.Value;

                            sensorInfos[coreCounter] = coreInfo;

                            coreCounter++;
                        }
                    }
                }
            }
            computer.Close();
            return(sensorInfos);
        }
Example #7
0
        //static IEnumerable<string> GetSystemInfo(string device)
        //just adding new text to implement the commit to git hub
        static void GetSystemInfo()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();
            var           output        = new List <string>();

            computer.Open();
            computer.CPUEnabled           = true;
            computer.GPUEnabled           = true;
            computer.FanControllerEnabled = true;
            computer.HDDEnabled           = true;
            computer.MainboardEnabled     = true;
            computer.RAMEnabled           = true;

            computer.Accept(updateVisitor);
            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                // iterate through the computer.hardware
                //Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now.");
                Console.WriteLine($"Name: {computer.Hardware[i].Name}, Type: {computer.Hardware[i].HardwareType}");
                Console.WriteLine();
                //if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                //{
                for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                {
                    Console.WriteLine($"Name: {computer.Hardware[i].Sensors[j].Name}, Type: {computer.Hardware[i].Sensors[j].SensorType}, Value: {computer.Hardware[i].Sensors[j].Value}");

                    //if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                    //    Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
                }
                //}
            }
            computer.Close();
            Console.ReadLine();
            //return new string[] { "1","2" };
        }
Example #8
0
 public abstract void Update(UpdateVisitor visitor, float dt);
Example #9
0
 public override void Update(UpdateVisitor visitor, float dt)
 {
 }
Example #10
0
 public void Update(UpdateVisitor visitor, float dt)
 {
     //MISSING CODE HERE
 }
Example #11
0
        static void GetSystemInfo(ref int[,] screenBuffer)
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();
            computer.CPUEnabled = true;
            computer.GPUEnabled = true;
            computer.RAMEnabled = true;
            computer.Accept(updateVisitor);
            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                //**************************************************************************************************************
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                {
                    Console.WriteLine("*******************CPU**************");
                    //计算CPU频率
                    float CPUCoreClock = 0;
                    int   CPUCoreCount = 0;

                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        //CPU温度
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            if (computer.Hardware[i].Sensors[j].Name == "CPU Package")
                            {
                                Console.WriteLine("CPU 温度:" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");

                                //############################################ CPU温度 ##############################################################
                                //CPU温度开始的位置
                                bufferPosition CPUTemperatureBeginPos;
                                string         CPUTemperatureStr = computer.Hardware[i].Sensors[j].Value.ToString();

                                int CPUUsageTemp = 0;
                                //频率小数点左侧的数字
                                if (CPUTemperatureStr.Length == 3)
                                {
                                    CPUTemperatureBeginPos.BeginXPos = 33;
                                    CPUTemperatureBeginPos.BeginYPos = 49;
                                    AddInfoToBuffer(CPUTemperatureBeginPos, false, 10, ref screenBuffer);

                                    CPUTemperatureBeginPos.BeginXPos = 36;
                                    CPUTemperatureBeginPos.BeginYPos = 49;
                                    CPUUsageTemp = int.Parse(CPUTemperatureStr.Substring(1, 1));
                                    AddInfoToBuffer(CPUTemperatureBeginPos, false, CPUUsageTemp, ref screenBuffer);

                                    CPUTemperatureBeginPos.BeginXPos = 43;
                                    CPUTemperatureBeginPos.BeginYPos = 49;
                                    CPUUsageTemp = int.Parse(CPUTemperatureStr.Substring(2, 1));
                                    AddInfoToBuffer(CPUTemperatureBeginPos, false, CPUUsageTemp, ref screenBuffer);
                                }
                                else if (CPUTemperatureStr.Length == 2)
                                {
                                    CPUTemperatureBeginPos.BeginXPos = 36;
                                    CPUTemperatureBeginPos.BeginYPos = 49;
                                    CPUUsageTemp = int.Parse(CPUTemperatureStr.Substring(0, 1));
                                    AddInfoToBuffer(CPUTemperatureBeginPos, false, CPUUsageTemp, ref screenBuffer);

                                    CPUTemperatureBeginPos.BeginXPos = 43;
                                    CPUTemperatureBeginPos.BeginYPos = 49;
                                    CPUUsageTemp = int.Parse(CPUTemperatureStr.Substring(1, 1));
                                    AddInfoToBuffer(CPUTemperatureBeginPos, false, CPUUsageTemp, ref screenBuffer);
                                }
                                else if (CPUTemperatureStr.Length == 1)
                                {
                                    CPUTemperatureBeginPos.BeginXPos = 36;
                                    CPUTemperatureBeginPos.BeginYPos = 49;
                                    AddInfoToBuffer(CPUTemperatureBeginPos, false, 0, ref screenBuffer);

                                    CPUTemperatureBeginPos.BeginXPos = 43;
                                    CPUTemperatureBeginPos.BeginYPos = 49;
                                    CPUUsageTemp = int.Parse(CPUTemperatureStr.Substring(0, 1));
                                    AddInfoToBuffer(CPUTemperatureBeginPos, false, CPUUsageTemp, ref screenBuffer);
                                }
                            }
                        }
                        //CPU频率
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Clock)
                        {
                            if (computer.Hardware[i].Sensors[j].Name.Substring(0, 8) == "CPU Core")
                            {
                                //计算CPU的频率总和 和 CPU核心数
                                CPUCoreClock += (float)computer.Hardware[i].Sensors[j].Value;
                                CPUCoreCount++;
                            }
                        }
                        //CPU使用率
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                        {
                            if (computer.Hardware[i].Sensors[j].Name == "CPU Total")
                            {
                                Console.WriteLine("CPU 占用:" + computer.Hardware[i].Sensors[j].Value.ToString() + "%\r");

                                //############################################ CPU使用 ##############################################################
                                //CPU使用开始的位置
                                bufferPosition CPUUsageBeginPos;
                                CPUUsageBeginPos.BeginXPos = 64;
                                CPUUsageBeginPos.BeginYPos = 49;
                                string CPUUsageStr = computer.Hardware[i].Sensors[j].Value.ToString();

                                int CPUUsageTemp = 0;
                                //使用的第一位数字
                                if (CPUUsageStr.IndexOf('.') <= 1)
                                {
                                    AddInfoToBuffer(CPUUsageBeginPos, false, 0, ref screenBuffer);
                                }
                                else
                                {
                                    CPUUsageTemp = int.Parse(CPUUsageStr.Substring(CPUUsageStr.IndexOf('.') - 2, 1));
                                    AddInfoToBuffer(CPUUsageBeginPos, false, CPUUsageTemp, ref screenBuffer);
                                }
                                //使用的第二位数字
                                CPUUsageBeginPos.BeginXPos = 71;
                                CPUUsageBeginPos.BeginYPos = 49;
                                CPUUsageStr = computer.Hardware[i].Sensors[j].Value.ToString();

                                if (CPUUsageStr.IndexOf('.') <= 0)
                                {
                                    AddInfoToBuffer(CPUUsageBeginPos, false, 1, ref screenBuffer);
                                }
                                else
                                {
                                    CPUUsageTemp = int.Parse(CPUUsageStr.Substring(CPUUsageStr.IndexOf('.') - 1, 1));
                                    //最小使用率为1%
                                    if (CPUUsageTemp == 0)
                                    {
                                        CPUUsageTemp = 1;
                                    }
                                    AddInfoToBuffer(CPUUsageBeginPos, false, CPUUsageTemp, ref screenBuffer);
                                }
                            }
                        }
                    }
                    //计算CPU频率,多核取平均值
                    CPUCoreClock = CPUCoreClock / CPUCoreCount / 1024;
                    Console.WriteLine("CPU 频率:" + CPUCoreClock + "\r");

                    //############################################ CPU频率 ##############################################################
                    //CPU频率开始的位置
                    bufferPosition CPUColockBeginPos;
                    CPUColockBeginPos.BeginXPos = 89;
                    CPUColockBeginPos.BeginYPos = 49;
                    string CPUClockStr = CPUCoreClock.ToString();

                    //频率小数点左侧的数字
                    int CLockTemp = int.Parse(CPUClockStr.Substring(CPUClockStr.IndexOf('.') - 1, 1));
                    AddInfoToBuffer(CPUColockBeginPos, false, CLockTemp, ref screenBuffer);

                    //频率小数点右侧侧的数字
                    CPUColockBeginPos.BeginXPos = 99;
                    CPUColockBeginPos.BeginYPos = 49;
                    CLockTemp = int.Parse(CPUClockStr.Substring(CPUClockStr.IndexOf('.') + 1, 1));
                    AddInfoToBuffer(CPUColockBeginPos, false, CLockTemp, ref screenBuffer);
                }

                //**************************************************************************************************************

                if (computer.Hardware[i].HardwareType == HardwareType.RAM)
                {
                    //内存总量
                    float MemoryTotal = 0;
                    Console.WriteLine("**************Memory**********************");
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        //内存占用
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                        {
                            Console.WriteLine("内存 占用:" + computer.Hardware[i].Sensors[j].Value.ToString() + "%\r");
                            //############################################ 内存使用率 ##############################################################
                            bufferPosition MEMUsagePos;
                            string         MEMUsage = computer.Hardware[i].Sensors[j].Value.ToString();

                            float UsageMEMValue = Convert.ToSingle(computer.Hardware[i].Sensors[j].Value.ToString()) / 100;

                            if (MEMUsage.IndexOf('.') == 3)
                            {
                                MEMUsagePos.BeginXPos = 7;
                                MEMUsagePos.BeginYPos = 38;
                                AddInfoToBuffer(MEMUsagePos, false, 9, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 14;
                                MEMUsagePos.BeginYPos = 38;
                                AddInfoToBuffer(MEMUsagePos, false, 9, ref screenBuffer);
                            }
                            if (MEMUsage.IndexOf('.') == 2)
                            {
                                MEMUsagePos.BeginXPos = 7;
                                MEMUsagePos.BeginYPos = 38;
                                int MEMUsageValue = int.Parse(MEMUsage.Substring(0, 1));
                                AddInfoToBuffer(MEMUsagePos, false, MEMUsageValue, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 14;
                                MEMUsagePos.BeginYPos = 38;
                                MEMUsageValue         = int.Parse(MEMUsage.Substring(1, 1));
                                AddInfoToBuffer(MEMUsagePos, false, MEMUsageValue, ref screenBuffer);
                            }
                            if (MEMUsage.IndexOf('.') == 1)
                            {
                                MEMUsagePos.BeginXPos = 7;
                                MEMUsagePos.BeginYPos = 38;
                                AddInfoToBuffer(MEMUsagePos, false, 0, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 14;
                                MEMUsagePos.BeginYPos = 38;
                                int MEMUsageValue = int.Parse(MEMUsage.Substring(0, 1));
                                AddInfoToBuffer(MEMUsagePos, false, MEMUsageValue, ref screenBuffer);
                            }
                            if (MEMUsage.IndexOf('.') == 0)
                            {
                                MEMUsagePos.BeginXPos = 7;
                                MEMUsagePos.BeginYPos = 38;
                                AddInfoToBuffer(MEMUsagePos, false, 0, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 14;
                                MEMUsagePos.BeginYPos = 38;
                                AddInfoToBuffer(MEMUsagePos, false, 0, ref screenBuffer);
                            }


                            //############################################ 内存使用量 ##############################################################
                            UsageMEMValue = AllSYSMEM * UsageMEMValue;
                            string UsageMEMValueStr = UsageMEMValue.ToString();
                            Console.WriteLine(UsageMEMValueStr);
                            if (UsageMEMValueStr.IndexOf('.') == 2)
                            {
                                MEMUsagePos.BeginXPos = 2;
                                MEMUsagePos.BeginYPos = 17;
                                int NowValue = int.Parse(UsageMEMValueStr.Substring(UsageMEMValueStr.IndexOf('.') - 2, 1));
                                AddInfoToBuffer(MEMUsagePos, false, NowValue, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 9;
                                MEMUsagePos.BeginYPos = 17;
                                NowValue = int.Parse(UsageMEMValueStr.Substring(UsageMEMValueStr.IndexOf('.') - 1, 1));
                                AddInfoToBuffer(MEMUsagePos, false, NowValue, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 19;
                                MEMUsagePos.BeginYPos = 17;
                                NowValue = int.Parse(UsageMEMValueStr.Substring(UsageMEMValueStr.IndexOf('.') + 1, 1));
                                AddInfoToBuffer(MEMUsagePos, false, NowValue, ref screenBuffer);
                            }
                            if (UsageMEMValueStr.IndexOf('.') == 1)
                            {
                                MEMUsagePos.BeginXPos = 2;
                                MEMUsagePos.BeginYPos = 17;
                                AddInfoToBuffer(MEMUsagePos, false, 0, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 9;
                                MEMUsagePos.BeginYPos = 17;
                                Console.WriteLine(UsageMEMValueStr.Substring(UsageMEMValueStr.IndexOf('.') - 1, 1));

                                int NowValue = int.Parse(UsageMEMValueStr.Substring(UsageMEMValueStr.IndexOf('.') - 1, 1));
                                Console.WriteLine(NowValue);
                                AddInfoToBuffer(MEMUsagePos, false, NowValue, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 19;
                                MEMUsagePos.BeginYPos = 17;
                                NowValue = int.Parse(UsageMEMValueStr.Substring(UsageMEMValueStr.IndexOf('.') + 1, 1));
                                AddInfoToBuffer(MEMUsagePos, false, NowValue, ref screenBuffer);
                            }
                            if (UsageMEMValueStr.IndexOf('.') == 0)
                            {
                                MEMUsagePos.BeginXPos = 2;
                                MEMUsagePos.BeginYPos = 17;
                                AddInfoToBuffer(MEMUsagePos, false, 0, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 9;
                                MEMUsagePos.BeginYPos = 17;
                                AddInfoToBuffer(MEMUsagePos, false, 0, ref screenBuffer);

                                MEMUsagePos.BeginXPos = 19;
                                MEMUsagePos.BeginYPos = 17;
                                int NowValue = int.Parse(UsageMEMValueStr.Substring(UsageMEMValueStr.IndexOf('.') + 1, 1));
                                AddInfoToBuffer(MEMUsagePos, false, NowValue, ref screenBuffer);
                            }
                        }
                        //内存使用未使用信息
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Data)
                        {
                            MemoryTotal += (float)computer.Hardware[i].Sensors[j].Value;
                        }
                    }

                    //############################################ 内存总量 ##############################################################
                    int ALLMEM = (int)Math.Ceiling(MemoryTotal);
                    AllSYSMEM = ALLMEM;
                    Console.WriteLine("内存 总量:" + ALLMEM + "\r");

                    bufferPosition ALLMEMPos;
                    ALLMEMPos.BeginXPos = 31;
                    ALLMEMPos.BeginYPos = 17;
                    AddInfoToBuffer(ALLMEMPos, false, (ALLMEM / 10), ref screenBuffer);

                    ALLMEMPos.BeginXPos = 38;
                    ALLMEMPos.BeginYPos = 17;
                    AddInfoToBuffer(ALLMEMPos, false, (ALLMEM % 10), ref screenBuffer);
                }

                //**************************************************************************************************************
                if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia)
                {
                    Console.WriteLine("**************GPU************************");
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        //GPU温度
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            Console.WriteLine("GPU 温度:" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
                            //############################################ GPU温度 ##############################################################
                            //GPU使用开始的位置
                            bufferPosition GPUTemperatureBeginPos;
                            string         GPUTemperatureStr = computer.Hardware[i].Sensors[j].Value.ToString();
                            if (GPUTemperatureStr.Length == 3)
                            {
                                GPUTemperatureBeginPos.BeginXPos = 85;
                                GPUTemperatureBeginPos.BeginYPos = 21;
                                AddInfoToBuffer(GPUTemperatureBeginPos, true, 10, ref screenBuffer);

                                GPUTemperatureBeginPos.BeginXPos = 90;
                                GPUTemperatureBeginPos.BeginYPos = 21;
                                int GPUUsageTemp = int.Parse(GPUTemperatureStr.Substring(0, 1));
                                AddInfoToBuffer(GPUTemperatureBeginPos, true, GPUUsageTemp, ref screenBuffer);

                                GPUTemperatureBeginPos.BeginXPos = 103;
                                GPUTemperatureBeginPos.BeginYPos = 21;
                                GPUUsageTemp = int.Parse(GPUTemperatureStr.Substring(1, 1));
                                AddInfoToBuffer(GPUTemperatureBeginPos, true, GPUUsageTemp, ref screenBuffer);
                            }
                            if (GPUTemperatureStr.Length == 2)
                            {
                                GPUTemperatureBeginPos.BeginXPos = 90;
                                GPUTemperatureBeginPos.BeginYPos = 21;
                                int GPUUsageTemp = int.Parse(GPUTemperatureStr.Substring(0, 1));
                                AddInfoToBuffer(GPUTemperatureBeginPos, true, GPUUsageTemp, ref screenBuffer);

                                GPUTemperatureBeginPos.BeginXPos = 103;
                                GPUTemperatureBeginPos.BeginYPos = 21;
                                GPUUsageTemp = int.Parse(GPUTemperatureStr.Substring(1, 1));
                                AddInfoToBuffer(GPUTemperatureBeginPos, true, GPUUsageTemp, ref screenBuffer);
                            }
                            if (GPUTemperatureStr.Length == 1)
                            {
                                GPUTemperatureBeginPos.BeginXPos = 90;
                                GPUTemperatureBeginPos.BeginYPos = 21;
                                AddInfoToBuffer(GPUTemperatureBeginPos, true, 0, ref screenBuffer);

                                GPUTemperatureBeginPos.BeginXPos = 103;
                                GPUTemperatureBeginPos.BeginYPos = 21;
                                int GPUUsageTemp = int.Parse(GPUTemperatureStr.Substring(0, 1));
                                AddInfoToBuffer(GPUTemperatureBeginPos, true, GPUUsageTemp, ref screenBuffer);
                            }
                        }

                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.SmallData)
                        {
                            //显存总量
                            if (computer.Hardware[i].Sensors[j].Name == "GPU Memory Total")
                            {
                                Console.WriteLine("显存 总量:" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
                                //############################################ GPU显存总量 ##############################################################
                                bufferPosition GPUALlMEMPos;
                                int            GPUMEM = int.Parse(computer.Hardware[i].Sensors[j].Value.ToString()) / 1024;
                                if (GPUMEM > 10)
                                {
                                    GPUALlMEMPos.BeginXPos = 52;
                                    GPUALlMEMPos.BeginYPos = 20;
                                    AddInfoToBuffer(GPUALlMEMPos, false, 10, ref screenBuffer);
                                    GPUALlMEMPos.BeginXPos = 57;
                                    GPUALlMEMPos.BeginYPos = 20;
                                    GPUMEM = GPUMEM % 10;
                                    AddInfoToBuffer(GPUALlMEMPos, false, GPUMEM, ref screenBuffer);
                                }
                                else
                                {
                                    GPUALlMEMPos.BeginXPos = 57;
                                    GPUALlMEMPos.BeginYPos = 20;
                                    AddInfoToBuffer(GPUALlMEMPos, false, GPUMEM, ref screenBuffer);
                                }

                                GPUAllMEM = Convert.ToSingle(computer.Hardware[i].Sensors[j].Value.ToString()) / 1024;
                            }
                        }

                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                        {
                            //GPU使用率
                            if (computer.Hardware[i].Sensors[j].Name == "GPU Core")
                            {
                                Console.WriteLine("GPU 使用:" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");

                                //############################################ GPU使用 ##############################################################
                                //GPU使用开始的位置
                                bufferPosition GPUUsageBeginPos;

                                string GPUUsage = computer.Hardware[i].Sensors[j].Value.ToString();
                                if (GPUUsage.Length > 3)
                                {
                                    GPUUsage = "99";
                                }
                                if (GPUUsage.Length == 2)
                                {
                                    GPUUsageBeginPos.BeginXPos = 90;
                                    GPUUsageBeginPos.BeginYPos = 3;
                                    int GPUUsageTemp = int.Parse(GPUUsage.Substring(0, 1));
                                    AddInfoToBuffer(GPUUsageBeginPos, true, GPUUsageTemp, ref screenBuffer);

                                    GPUUsageBeginPos.BeginXPos = 103;
                                    GPUUsageBeginPos.BeginYPos = 3;
                                    GPUUsageTemp = int.Parse(GPUUsage.Substring(1, 1));
                                    AddInfoToBuffer(GPUUsageBeginPos, true, GPUUsageTemp, ref screenBuffer);
                                }
                                if (GPUUsage.Length == 1)
                                {
                                    GPUUsageBeginPos.BeginXPos = 90;
                                    GPUUsageBeginPos.BeginYPos = 3;
                                    AddInfoToBuffer(GPUUsageBeginPos, true, 0, ref screenBuffer);

                                    GPUUsageBeginPos.BeginXPos = 103;
                                    GPUUsageBeginPos.BeginYPos = 3;
                                    int GPUUsageTemp = int.Parse(GPUUsage.Substring(0, 1));
                                    AddInfoToBuffer(GPUUsageBeginPos, true, GPUUsageTemp, ref screenBuffer);
                                }
                            }

                            //显存使用
                            if (computer.Hardware[i].Sensors[j].Name == "GPU Memory")
                            {
                                Console.WriteLine("显存 使用:" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
                                //############################################ GPU显存总量 ##############################################################

                                float GPUMEMUsage = Convert.ToSingle(computer.Hardware[i].Sensors[j].Value.ToString()) / 100;
                                GPUMEMUsage = GPUAllMEM * GPUMEMUsage;
                                bufferPosition GPUMEMUsagePos;
                                string         GPUMEMUsageStr = GPUMEMUsage.ToString();
                                if (GPUMEMUsageStr.IndexOf('.') > 0)
                                {
                                    GPUMEMUsagePos.BeginXPos = 52;
                                    GPUMEMUsagePos.BeginYPos = 7;
                                    int UsageValue = int.Parse(GPUMEMUsageStr.Substring(GPUMEMUsageStr.IndexOf('.') - 1, 1));
                                    AddInfoToBuffer(GPUMEMUsagePos, false, UsageValue, ref screenBuffer);

                                    GPUMEMUsagePos.BeginXPos = 62;
                                    GPUMEMUsagePos.BeginYPos = 7;
                                    UsageValue = int.Parse(GPUMEMUsageStr.Substring(GPUMEMUsageStr.IndexOf('.') + 1, 1));
                                    AddInfoToBuffer(GPUMEMUsagePos, false, UsageValue, ref screenBuffer);
                                }
                                else if (GPUMEMUsageStr.IndexOf('.') == 0)
                                {
                                    GPUMEMUsagePos.BeginXPos = 52;
                                    GPUMEMUsagePos.BeginYPos = 7;
                                    AddInfoToBuffer(GPUMEMUsagePos, false, 0, ref screenBuffer);

                                    GPUMEMUsagePos.BeginXPos = 62;
                                    GPUMEMUsagePos.BeginYPos = 7;
                                    int UsageValue = int.Parse(GPUMEMUsageStr.Substring(GPUMEMUsageStr.IndexOf('.') + 1, 1));
                                    AddInfoToBuffer(GPUMEMUsagePos, false, UsageValue, ref screenBuffer);
                                }
                            }
                        }
                    }
                }
            }
            computer.Close();
        }
Example #12
0
        static void GetSystemInfo()
        {
            const int C_H_N_LENGTH     = 20;                            //ComputerHardwareName
            const int C_H_S_N_LENGTH   = 30;                            //ComputerHardwareSensorName
            const int C_H_S_T_N_LENGTH = 12;                            //ComputerHardwareSensorTypeName
            const int V_LENGTH         = 6;                             //Value

            const string C_H_N_NAME     = "Hardware Identifier";        //ComputerHardwareName
            const string C_H_S_N_NAME   = "Hardware Sensor Identifier"; //ComputerHardwareSensorName
            const string C_H_S_T_N_NAME = "Sensor Type";                //ComputerHardwareSensorTypeName
            const string V_NAME         = "Value";                      //Value

            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();

            computer.CPUEnabled = true;
            computer.GPUEnabled = true;
            computer.RAMEnabled = true;
            //computer.FanControllerEnabled = true;                 //Gets a weird exception: "Error: No se puede cargar el archivo o ensamblado 'HidLibrary, Version=3.2.46.0, Culture=neutral, PublicKeyToken=null' ni una de sus dependencias. El sistema no puede encontrar el archivo especificado."
            computer.HDDEnabled       = true;
            computer.MainboardEnabled = true;
            //computer.NICEnabled = true;                           //Shows Too much info from NIC that is not useful for me

            computer.Accept(updateVisitor);

            Console.WriteLine((C_H_N_NAME.Length > C_H_N_LENGTH ? C_H_N_NAME.Substring(0, C_H_N_LENGTH): C_H_N_NAME.PadRight(C_H_N_LENGTH)) + " | " +
                              (C_H_S_N_NAME.Length > C_H_S_N_LENGTH ? C_H_S_N_NAME.Substring(0, C_H_S_N_LENGTH) : C_H_S_N_NAME.PadRight(C_H_S_N_LENGTH)) + " | " +
                              (C_H_S_T_N_NAME.Length > C_H_S_T_N_LENGTH ? C_H_S_T_N_NAME.Substring(0, C_H_S_T_N_LENGTH) : C_H_S_T_N_NAME.PadRight(C_H_S_T_N_LENGTH)).PadRight(C_H_S_T_N_LENGTH) + " | " +
                              (V_NAME.Length > V_LENGTH ? V_NAME.Substring(0, V_LENGTH) : V_NAME.PadLeft(V_LENGTH)));
            Console.WriteLine(("-").PadLeft(C_H_N_LENGTH + C_H_S_N_LENGTH + C_H_S_T_N_LENGTH + V_LENGTH + 9, '-'));


            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                {
                    if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                    {
                        //var ComputerHardwareName = computer.Hardware[i].Name;
                        //var ComputerHardwareName = computer.Hardware[i].Identifier + " >>> " + computer.Hardware[i].Name;
                        var ComputerHardwareName = computer.Hardware[i].Identifier.ToString();
                        if (ComputerHardwareName.Length > C_H_N_LENGTH)
                        {
                            ComputerHardwareName = ComputerHardwareName.Substring(1, C_H_N_LENGTH);
                        }
                        else
                        {
                            ComputerHardwareName = ComputerHardwareName.PadRight(C_H_N_LENGTH);
                        }

                        //var ComputerHardwareSensorName = computer.Hardware[i].Sensors[j].Name;
                        //var ComputerHardwareSensorName = computer.Hardware[i].Sensors[j].Identifier + " >>> " + computer.Hardware[i].Sensors[j].Name;
                        var ComputerHardwareSensorName = computer.Hardware[i].Sensors[j].Identifier.ToString();
                        if (ComputerHardwareSensorName.Length > C_H_S_N_LENGTH)
                        {
                            ComputerHardwareSensorName = ComputerHardwareSensorName.Substring(1, C_H_S_N_LENGTH);
                        }
                        else
                        {
                            ComputerHardwareSensorName = ComputerHardwareSensorName.PadRight(C_H_S_N_LENGTH);
                        }

                        var ComputerHardwareSensorTypeName = computer.Hardware[i].Sensors[j].SensorType.ToString();
                        if (ComputerHardwareSensorTypeName.Length > C_H_S_T_N_LENGTH)
                        {
                            ComputerHardwareSensorTypeName = ComputerHardwareSensorTypeName.Substring(0, C_H_S_T_N_LENGTH);
                        }
                        else
                        {
                            ComputerHardwareSensorTypeName = ComputerHardwareSensorTypeName.PadRight(C_H_S_T_N_LENGTH);
                        }

                        var value = Math.Round((decimal)computer.Hardware[i].Sensors[j].Value, 1).ToString();

                        /*
                         * value = value.Replace(",", ".");
                         * if (!(value.Contains(".")))
                         * {
                         *  value = (value + ".0").ToString();
                         * }
                         */
                        value = value.PadLeft(V_LENGTH);

                        Console.WriteLine(ComputerHardwareName + " | " + ComputerHardwareSensorName + " | " + ComputerHardwareSensorTypeName + " | " + value + "\r");
                    }
                }
            }
            computer.Close();
        }
Example #13
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            int   delay = 1000;
            GetIP serv  = new GetIP();

            Task.Run(async() =>
            {
                HttpServer serv1 = new HttpServer(serv.ip.ToString());
                while (true)
                {
                    UpdateVisitor updateVisitor = new UpdateVisitor();
                    Computer computer           = new Computer();
                    computer.CPUEnabled         = true;
                    computer.GPUEnabled         = true;
                    computer.Open();
                    computer.Accept(updateVisitor);
                    for (int i = 0; i < computer.Hardware.Length; i++)
                    {
                        if (computer.Hardware[i].HardwareType == HardwareType.CPU)                 //Get CPU temp
                        {
                            for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                            {
                                if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                                {
                                    string str = ("CPU Temp: " + computer.Hardware[i].Sensors[j].Value.ToString() + "°C");
                                    await App.Current.Dispatcher.BeginInvoke(new Action(() => cpu.Text = str));
                                }
                            }
                        }
                    }
                    for (int i = 0; i < computer.Hardware.Length; i++)             //Get NVidia GPU temp
                    {
                        if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia)
                        {
                            for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                            {
                                if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                                {
                                    string str = ("GPU Temp: " + computer.Hardware[i].Sensors[j].Value.ToString() + "°C");
                                    await App.Current.Dispatcher.BeginInvoke(new Action(() => { gpu.Text = str; ip.Text = serv.ip.ToString(); }));
                                }
                            }
                        }
                    }
                    for (int i = 0; i < computer.Hardware.Length; i++)                     //Get CPU load
                    {
                        if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                        {
                            for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                            {
                                if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                                {
                                    string str = ("CPU Load: " + computer.Hardware[i].Sensors[j].Value.ToString() + "%");
                                    await App.Current.Dispatcher.BeginInvoke(new Action(() => { cpuLoad.Text = str; }));
                                }
                            }
                        }
                    }
                    for (int i = 0; i < computer.Hardware.Length; i++)                     //Get NVidia GPU load (not working correctly)
                    {
                        if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia)
                        {
                            for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                            {
                                if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                                {
                                    string str = ("GPU Load: " + computer.Hardware[i].Sensors[j].Value.ToString() + "%");
                                    await App.Current.Dispatcher.BeginInvoke(new Action(() => { gpuLoad.Text = str; }));
                                }
                            }
                        }
                    }
                    computer.Close();
                    await Task.Delay(delay);
                    await App.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        serv1.Update(cpu.Text.ToString(), gpu.Text.ToString(), cpuLoad.Text.ToString(), gpuLoad.Text.ToString());
                    }));
                }
            });
        }
Example #14
0
 public void Update(UpdateVisitor visitor, float dt)
 {
     visitor.UpdateGui(this, dt);
 }
Example #15
0
    public TrayApplicationContext()
    {
        _components = new System.ComponentModel.Container();

        // Clean old files if they exist
        if (File.Exists("settings.dat")) {
            File.Delete("settings.dat");
            MessageBox.Show("All stored preferences were cleared during the update.\nPlease set your preferences again by right-clicking the tray icon and selecting settings.");
        }
        if (File.Exists("devices.dat")) File.Delete("devices.dat");

        // Load settings
        Boolean first_time = false;
        if (File.Exists("settings.json")) {
            try {
                _settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText("settings.json"));
            } catch (Exception e) {
                MessageBox.Show("Could not load settings. Default values will be used.");

                _settings = new Settings();
                File.WriteAllText("settings.json", JsonConvert.SerializeObject(_settings));
            }
        } else {
            _settings = new Settings();
            _settings.Save();
            first_time = true;
        }

        // Create history directory if needed
        if (!Directory.Exists("History")) {
            Directory.CreateDirectory("History");
        }

        // Load devices
        _deviceManager = new DeviceManager(_settings);
        _deviceManager.SaveData();

        // Prepare notification system
        _notificationManager = new NotificationManager(_settings.ComputerName);

        // Create the icon
        _notifyIcon = new NotifyIcon(this._components);
        _notifyIcon.Icon = Resources.icon_app;
        _notifyIcon.Text = "Icy Monitor Server";
        _notifyIcon.DoubleClick += mSettings_Click;
        _notifyIcon.Visible = true;

        // Prepare context menu
        PrepareContextMenu();

        // Create computer object for data
        _computer = new Computer();
        _visitor = new UpdateVisitor();

        _computer.CPUEnabled = true;
        _computer.FanControllerEnabled = true;
        _computer.GPUEnabled = true;
        _computer.MainboardEnabled = true;
        _computer.HDDEnabled = true;

        _computer.Open();
        _computer.Accept(_visitor);

        // Collect sensors (for history and notifications)
        CollectSensors();

        // Create notifications timer
        StartNotificationsTimer();

        // Create history timer
        if (_settings.History) StartHistoryTimer();

        // Create server
        CreateServer();

        // Create the multicast timer
        if (_settings.Multicast) {
            try {
                StartMulticasting();
            } catch (SocketException e) {
                MessageBox.Show("Could not open socket for multicasting. Autodetection will be disabled.\n(Is another copy of Icy Monitor running?)");
            }
        }

        if (first_time) {
            DialogResult dialogResult = MessageBox.Show("It is essential that you open a port for the server to use, would you want to open the preferences window?\n\nYou can do this at any moment by double-clicking the tray icon.",
                "Icy Monitor Server", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes) {
                mSettings_Click(null, null);
            }
        }

        // Start the server
        if (_server.Start() == false) {
            if (_multicastSocket != null) _multicastSocket.Close();
            base.ExitThreadCore();
        }
    }
Example #16
0
        //Actually gets the system info, returns string array with values to send
        static string[] GetSystemInfo()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();
            computer.CPUEnabled = true;
            computer.GPUEnabled = true;
            computer.Accept(updateVisitor);
            String CPU_Temp  = "";
            String CPU_Speed = "";
            String CPU_Load  = "";
            String GPU_Temp  = "";
            String GPU_Load  = "";
            String GPU_Speed = "";
            String date      = "";
            String time      = "";

            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                //If sensor array is a CPU sensor array
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                {
                    List <Double> avgClockSum         = new List <Double>();
                    int           coreTempSensorCount = 0;

                    //Cycle through all CPU sensors
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        //If the sensor is a temperature sensor and named "CPU Package"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature && computer.Hardware[i].Sensors[j].Name == "CPU Package")
                        {
                            CPU_Temp = (computer.Hardware[i].Sensors[j].Value.ToString());
                        }

                        //If the sensor is a clock speed sensor not named "Bus Speed"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Clock && computer.Hardware[i].Sensors[j].Name != "Bus Speed")
                        {
                            avgClockSum.Add((double)computer.Hardware[i].Sensors[j].Value);
                            coreTempSensorCount++;
                        }

                        //If the sensor is a load percentage sensor and is named "CPU Total"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load && computer.Hardware[i].Sensors[j].Name == "CPU Total")
                        {
                            CPU_Load = (computer.Hardware[i].Sensors[j].Value.ToString());
                        }
                    }
                    CPU_Speed = "" + Math.Round(avgClockSum[0], 1);
                }

                //If sensor array is an NVidia GPU sensor array
                else if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia)
                {
                    //Cycle through all sensors in the array
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        //If the sensor is a temperature sensor named "GPU Core"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature && computer.Hardware[i].Sensors[j].Name == "GPU Core")
                        {
                            GPU_Temp = (computer.Hardware[i].Sensors[j].Value.ToString());
                        }

                        //If the sensor is a load percentage sensor named "GPU Core"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load && computer.Hardware[i].Sensors[j].Name == "GPU Core")
                        {
                            GPU_Load = (computer.Hardware[i].Sensors[j].Value.ToString());
                        }

                        //If the sensor is a clock speed sensor named "GPU Core"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Clock && computer.Hardware[i].Sensors[j].Name == "GPU Core")
                        {
                            GPU_Speed = (Math.Round((float)computer.Hardware[i].Sensors[j].Value, 1).ToString());
                        }
                    }
                }

                //If sensor array is an AMD GPU sensor array
                else if (computer.Hardware[i].HardwareType == HardwareType.GpuAti)
                {
                    //Cycle throguh all sensors in the array
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        //If the sensor is a temperature sensor named "GPU Core"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature && computer.Hardware[i].Sensors[j].Name == "GPU Core")
                        {
                            GPU_Temp = (computer.Hardware[i].Sensors[j].Value.ToString());
                        }

                        //If the sensor is a load percentage sensor named "GPU Core"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load && computer.Hardware[i].Sensors[j].Name == "GPU Core")
                        {
                            GPU_Load = (computer.Hardware[i].Sensors[j].Value.ToString());
                        }

                        //If the sensor is a clock speed sensor named "GPU Core"
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Clock && computer.Hardware[i].Sensors[j].Name == "GPU Core")
                        {
                            GPU_Speed = (Math.Round((float)computer.Hardware[i].Sensors[j].Value, 1).ToString());
                        }
                    }
                }
            }

            if (timeActive)
            {
                if (time24hrActive)
                {
                    time = DateTime.Now.ToString("HH:mm");
                }
                else if (!time24hrActive)
                {
                    time = DateTime.Now.ToString("hh:mm");
                }
            }

            if (dateActive)
            {
                date = DateTime.Now.ToString("MM/dd/yy");
            }

            string[] outputs = { " ", CPU_Temp, CPU_Speed, CPU_Load, GPU_Temp, GPU_Speed, GPU_Load, date, time };
            computer.Close();
            return(outputs);
        }
Example #17
0
        /// <summary>
        /// Performs analysis and returns a list of problems detected
        /// </summary>
        /// <param name="ruleExecutionContext">Contains the schema model and model element to analyze</param>
        /// <returns>
        /// The problems detected by the rule in the given element
        /// </returns>
        public override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext)
        {
            var problems = new List <SqlRuleProblem>();
            var sqlObj   = ruleExecutionContext.ModelElement;
            var model    = ruleExecutionContext.SchemaModel;

            if (sqlObj == null || sqlObj.IsWhiteListed())
            {
                return(problems);
            }

            var fragment = ruleExecutionContext.ScriptFragment.GetFragment(ProgrammingSchemaTypes);

            var updateVisitor = new UpdateVisitor();

            fragment.Accept(updateVisitor);
            foreach (var update in updateVisitor.NotIgnoredStatements(RuleId))
            {
                if (!(update.UpdateSpecification.Target is NamedTableReference target) || target.GetName().Contains("#"))
                {
                    continue;
                }

                //we have an aliased table we need to find out what the real table is so we can look up its columns
                if (update.UpdateSpecification.FromClause != null)
                {
                    var namedTableVisitor = new NamedTableReferenceVisitor()
                    {
                        TypeFilter = ObjectTypeFilter.PermanentOnly
                    };
                    update.UpdateSpecification.FromClause.Accept(namedTableVisitor);

                    target = namedTableVisitor.Statements
                             .FirstOrDefault(t => _comparer.Equals(t.Alias?.Value, target.SchemaObject.Identifiers.LastOrDefault()?.Value));
                    if (target == null)
                    {
                        continue;
                    }
                }

                var targetSqlObj = model.GetObject(Table.TypeClass, target.GetObjectIdentifier(), DacQueryScopes.All);
                if (targetSqlObj == null)
                {
                    continue;
                }

                var pk = targetSqlObj.GetReferencing(PrimaryKeyConstraint.Host, DacQueryScopes.UserDefined).FirstOrDefault();
                if (pk == null)
                {
                    continue;
                }
                var primaryKeyColumns = pk.GetReferenced(PrimaryKeyConstraint.Columns, DacQueryScopes.All);

                var hasOffense = update.UpdateSpecification.SetClauses.OfType <AssignmentSetClause>().Any(setClause =>
                {
                    if (setClause.Column?.MultiPartIdentifier == null)
                    {
                        return(false);
                    }
                    return(primaryKeyColumns.Any(pkc => pkc.Name.CompareTo(setClause.Column?.MultiPartIdentifier) >= 5));
                });

                if (hasOffense)
                {
                    problems.Add(new SqlRuleProblem(Message, sqlObj, update));
                }
            }
            return(problems);
        }
Example #18
0
        public static List <Measurement> GetUpdateData(DateTime dateTime)
        {
            var    measurements = new List <Measurement>();
            string t            = "";
            int    counter      = 0;

            MaxTemp.MTemp = "";
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer()
            {
                CPUEnabled = true,
                GPUEnabled = true,
                HDDEnabled = true
            };

            computer.Open();
            computer.Accept(updateVisitor);

            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)//temp of cpu
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            if (computer.Hardware[i].Sensors[j].Name.Contains("CPU Package"))
                            {
                                t += "Cpu Total: " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                            }
                            else
                            {
                                t += computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                            }
                            if (MaxTemp.MTemps[counter] < computer.Hardware[i].Sensors[j].Value)
                            {
                                MaxTemp.MTemps[counter] = (int)computer.Hardware[i].Sensors[j].Value;
                                if (computer.Hardware[i].Sensors[j].Name.Contains("CPU Package"))
                                {
                                    MaxTemp.MTemp += "Max " + "Cpu Total: " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                                }
                                else
                                {
                                    MaxTemp.MTemp += "Max " + computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                                }
                            }
                            else
                            {
                                if (computer.Hardware[i].Sensors[j].Name.Contains("CPU Package"))
                                {
                                    MaxTemp.MTemp += "Max " + "Cpu Total: " + MaxTemp.MTemps[counter] + "\n";
                                }
                                else
                                {
                                    MaxTemp.MTemp += "Max " + computer.Hardware[i].Sensors[j].Name + ": " + MaxTemp.MTemps[counter] + "\n";
                                }
                            }
                        }
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature && computer.Hardware[i].Sensors[j].Name.Contains("CPU Package"))
                        {
                            measurements.Add(new Measurement()
                            {
                                DetectorId = counter,
                                DateTime   = dateTime.AddSeconds(1),
                                Value      = (int)computer.Hardware[i].Sensors[j].Value,
                                Name       = computer.Hardware[i].Sensors[j].Name
                            });
                            counter++;
                            //heh2 += computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                        }
                    }
                }
                if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia || computer.Hardware[i].HardwareType == HardwareType.GpuAti)
                { //temp of videocard
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            if ((int)computer.Hardware[i].Sensors[j].Value != 0)
                            {
                                if (MaxTemp.MTemps[counter] < computer.Hardware[i].Sensors[j].Value)
                                {
                                    MaxTemp.MTemps[counter] = (int)computer.Hardware[i].Sensors[j].Value;
                                    MaxTemp.MTemp          += "Max " + computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                                }
                                else
                                {
                                    MaxTemp.MTemp += "Max " + computer.Hardware[i].Sensors[j].Name + ": " + MaxTemp.MTemps[counter] + "\n";
                                }
                                measurements.Add(new Measurement()
                                {
                                    DetectorId = counter,
                                    DateTime   = dateTime.AddSeconds(1),
                                    Value      = (int)computer.Hardware[i].Sensors[j].Value,
                                    Name       = computer.Hardware[i].Sensors[j].Name
                                });
                                counter++;
                                t += computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                            }
                        }
                    }
                }
                if (computer.Hardware[i].HardwareType == HardwareType.HDD)//temp of disk
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            if (MaxTemp.MTemps[counter] < computer.Hardware[i].Sensors[j].Value)
                            {
                                MaxTemp.MTemps[counter] = (int)computer.Hardware[i].Sensors[j].Value;
                                MaxTemp.MTemp          += "Max " + "Storage" + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                            }
                            else
                            {
                                MaxTemp.MTemp += "Max " + "Storage" + ": " + MaxTemp.MTemps[counter] + "\n";
                            }
                            try
                            {
                                measurements.Add(new Measurement()
                                {
                                    DetectorId = counter,
                                    DateTime   = dateTime.AddSeconds(1),
                                    Value      = (int)computer.Hardware[i].Sensors[j].Value,
                                    Name       = "Storage " + computer.Hardware[i].Sensors[j].Name
                                });
                                counter++;
                                t += "Storage" + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\n";
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show("Диск сильно нагружен! " + e.Message);
                            }
                        }
                    }
                }
            }
            measurements[0].Temp = t;
            computer.Close();
            return(measurements);
        }
Example #19
0
    public TrayApplicationContext()
    {
        _components = new System.ComponentModel.Container();

        // Clean old files if they exist
        if (File.Exists("settings.dat"))
        {
            File.Delete("settings.dat");
            MessageBox.Show("All stored preferences were cleared during the update.\nPlease set your preferences again by right-clicking the tray icon and selecting settings.");
        }
        if (File.Exists("devices.dat"))
        {
            File.Delete("devices.dat");
        }

        // Load settings
        Boolean first_time = false;

        if (File.Exists("settings.json"))
        {
            try {
                _settings = JsonConvert.DeserializeObject <Settings>(File.ReadAllText("settings.json"));
            } catch (Exception e) {
                MessageBox.Show("Could not load settings. Default values will be used.");

                _settings = new Settings();
                File.WriteAllText("settings.json", JsonConvert.SerializeObject(_settings));
            }
        }
        else
        {
            _settings = new Settings();
            _settings.Save();
            first_time = true;
        }

        // Create history directory if needed
        if (!Directory.Exists("History"))
        {
            Directory.CreateDirectory("History");
        }

        // Load devices
        _deviceManager = new DeviceManager(_settings);
        _deviceManager.SaveData();

        // Prepare notification system
        _notificationManager = new NotificationManager(_settings.ComputerName);

        // Create the icon
        _notifyIcon              = new NotifyIcon(this._components);
        _notifyIcon.Icon         = Resources.icon_app;
        _notifyIcon.Text         = "Icy Monitor Server";
        _notifyIcon.DoubleClick += mSettings_Click;
        _notifyIcon.Visible      = true;

        // Prepare context menu
        PrepareContextMenu();

        // Create computer object for data
        _computer = new Computer();
        _visitor  = new UpdateVisitor();

        _computer.CPUEnabled           = true;
        _computer.FanControllerEnabled = true;
        _computer.GPUEnabled           = true;
        _computer.MainboardEnabled     = true;
        _computer.HDDEnabled           = true;

        _computer.Open();
        _computer.Accept(_visitor);

        // Collect sensors (for history and notifications)
        CollectSensors();

        // Create notifications timer
        StartNotificationsTimer();

        // Create history timer
        if (_settings.History)
        {
            StartHistoryTimer();
        }

        // Create server
        CreateServer();

        // Create the multicast timer
        if (_settings.Multicast)
        {
            try {
                StartMulticasting();
            } catch (SocketException e) {
                MessageBox.Show("Could not open socket for multicasting. Autodetection will be disabled.\n(Is another copy of Icy Monitor running?)");
            }
        }

        if (first_time)
        {
            DialogResult dialogResult = MessageBox.Show("It is essential that you open a port for the server to use, would you want to open the preferences window?\n\nYou can do this at any moment by double-clicking the tray icon.",
                                                        "Icy Monitor Server", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                mSettings_Click(null, null);
            }
        }

        // Start the server
        if (_server.Start() == false)
        {
            if (_multicastSocket != null)
            {
                _multicastSocket.Close();
            }
            base.ExitThreadCore();
        }
    }
Example #20
0
 public void Update(UpdateVisitor visitor, float dt)
 {
 }
Example #21
0
        private void UpdateSenserData()
        {
            time_lbl.Text = DateTime.Now.ToString();
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.CPUEnabled = true;
            computer.GPUEnabled = true;
            computer.Open();
            computer.Accept(updateVisitor);

            foreach (IHardware hardware in computer.Hardware)
            {
                int ii = 0;
            }
            List <string> GPUNames = new List <string>();
            List <float>  GPUTemps = new List <float>();

            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                //查找硬件类型为CPU
                if (computer.Hardware[i].HardwareType == HardwareType.CPU ||
                    computer.Hardware[i].HardwareType == HardwareType.GpuNvidia ||
                    computer.Hardware[i].HardwareType == HardwareType.GpuAti)
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        //找到温度传感器
                        if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                        {
                            if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                            {
                                senserMonitorData.CPUName = computer.Hardware[i].Name;
                                senserMonitorData.CPUtemp = (float)computer.Hardware[i].Sensors[j].Value;
                            }
                        }
                        //NV
                        if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia)
                        {
                            if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                            {
                                string nvName  = computer.Hardware[i].Name;
                                float  _nvTemp = (float)computer.Hardware[i].Sensors[j].Value;
                                GPUNames.Add(nvName);
                                GPUTemps.Add(_nvTemp);
                            }
                        }
                        //AMD
                        if (computer.Hardware[i].HardwareType == HardwareType.GpuAti)
                        {
                            if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature && computer.Hardware[i].Sensors[j].Name.Contains("Hot Spot"))
                            {
                                string amdName  = computer.Hardware[i].Name;
                                float  _amdTemp = (float)computer.Hardware[i].Sensors[j].Value;
                                GPUNames.Add(amdName);
                                GPUTemps.Add(_amdTemp);
                            }
                        }
                    }
                }
                senserMonitorData.GPUName = GPUNames;
                senserMonitorData.GPUtemp = GPUTemps;
            }
        }
Example #22
0
 public void Update(UpdateVisitor visitor, float dt)
 {
     visitor.UpdateButton(this, dt);
 }
Example #23
0
 public abstract override void Update(UpdateVisitor visitor, float dt);
Example #24
0
        public MainWindow()
        {
            InitializeComponent();
            this.Show();

            Computer computer = new Computer();

            computer.CPUEnabled = true;

            RunMonitoring();

            async void RunMonitoring()
            {
                while (true)
                {
                    await Task.Run(() =>
                    {
                        UpdateVisitor updateVisitor           = new UpdateVisitor();
                        MonitorProcess.SensorInfo[] cputTemps = MonitorProcess.CPUTemp(computer, updateVisitor);

                        foreach (SensorInfo coreInfo in cputTemps)
                        {
                            Console.WriteLine(coreInfo.sensorName + " - " + coreInfo.sensorValue + "C°");
                            this.Dispatcher.Invoke(() => {
                                ProgressBar bar_1 = (ProgressBar)this.FindName("core_1_bar");
                                ProgressBar bar_2 = (ProgressBar)this.FindName("core_2_bar");
                                ProgressBar bar_3 = (ProgressBar)this.FindName("core_3_bar");
                                ProgressBar bar_4 = (ProgressBar)this.FindName("core_4_bar");
                                ProgressBar bar_5 = (ProgressBar)this.FindName("core_5_bar");
                                ProgressBar bar_6 = (ProgressBar)this.FindName("core_6_bar");

                                bar_5.Value = 0;
                                bar_6.Value = 0;


                                switch (coreInfo.sensorName)
                                {
                                case "CPU Core #1":
                                    bar_1.Value = Convert.ToDouble(coreInfo.sensorValue);
                                    ColorBar(bar_1, coreInfo.sensorValue);
                                    break;

                                case "CPU Core #2":
                                    bar_2.Value = Convert.ToDouble(coreInfo.sensorValue);
                                    ColorBar(bar_2, coreInfo.sensorValue);
                                    break;

                                case "CPU Core #3":
                                    bar_3.Value = Convert.ToDouble(coreInfo.sensorValue);
                                    ColorBar(bar_3, coreInfo.sensorValue);
                                    break;

                                case "CPU Core #4":
                                    bar_4.Value = Convert.ToDouble(coreInfo.sensorValue);
                                    ColorBar(bar_4, coreInfo.sensorValue);
                                    break;

                                case "CPU Core #5":
                                    bar_5.Value = Convert.ToDouble(coreInfo.sensorValue);
                                    ColorBar(bar_5, coreInfo.sensorValue);
                                    break;

                                case "CPU Core #6":
                                    bar_6.Value = Convert.ToDouble(coreInfo.sensorValue);
                                    ColorBar(bar_6, coreInfo.sensorValue);
                                    break;
                                }
                            });
                        }
                    });

                    //Thread.Sleep(100);
                }
            }

            void ColorBar(ProgressBar bar, float?value)
            {
                if (bar.Value >= 80)
                {
                    bar.Foreground = Brushes.Red;
                }
                else if (bar.Value >= 70)
                {
                    bar.Foreground = Brushes.Orange;
                }
                else
                {
                    bar.Foreground = Brushes.Green;
                }
            }
        }
Example #25
0
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            Socket    s         = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPAddress broadcast = IPAddress.Parse("10.0.0.164");


            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();
            computer.CPUEnabled = true;
            computer.RAMEnabled = true;
            computer.GPUEnabled = true;
            computer.Accept(updateVisitor);
            string cput                = "0";
            string cpuu                = "0";
            string gput                = "0";
            string gpuu                = "0";
            float  used_mem            = 0;
            float  free_mem            = 0;
            string used_mem_string     = "0";
            string total_mem           = "0";
            double total_mem_pre_round = 0;

            // Old way below

            /**
             * for (int i = 0; i < computer.Hardware.Length; i++)
             * {
             *  //GET CPU TEMP AND UTILIZATION
             *  if (computer.Hardware[i].HardwareType == HardwareType.CPU) ;
             *  {
             *      for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
             *      {
             *          //GET CPU TEMP
             *          if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
             *          {
             *              if (computer.Hardware[i].Sensors[j].Name == "CPU Package")
             *              {
             *                  //Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ": " + format_string(computer.Hardware[i].Sensors[j].Value.ToString()) + "\r");
             *                  cput = format_string(computer.Hardware[i].Sensors[j].Value.ToString());
             *
             *              }
             *          }
             *
             *          //GET CPU UTILIZATION
             *          if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
             *          {
             *              if (computer.Hardware[i].Sensors[j].Name == "CPU Total")
             *              {
             *                  //Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
             *                  cpuu = format_string(computer.Hardware[i].Sensors[j].Value.GetValueOrDefault().ToString());
             *              }
             *          }
             *      }
             *  }
             *  //GET GPY TEMP AND UTILIZATION
             *  if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia)
             *  {
             *      for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
             *      {
             *          //GET CPU TEMP
             *          if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
             *          {
             *
             *              Console.WriteLine("T:" + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
             *              gput = format_string(computer.Hardware[i].Sensors[j].Value.ToString());
             *          }
             *
             *          //GET CPU UTILIZATION
             *          if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
             *          {
             *
             *              if (computer.Hardware[i].Sensors[j].Name == "GPU Core")
             *              {
             *                  Console.WriteLine("U: " + computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
             *                  gpuu = format_string(computer.Hardware[i].Sensors[j].Value.ToString());
             *
             *              }
             *          }
             *      }
             *  }
             *
             *  if (hardware.HardwareType == HardwareType.GpuNvidia)
             *  {
             *      hardware.Update();
             *      foreach (var sensors in hardware.Sensors)
             *      {
             *          if (sensors.SensorType == SensorType.Load)
             *          {
             *              if (sensors.Name == "GPU Core")
             *              {
             *                  Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
             *                  gpuu = sensors.Value.ToString();
             *              }
             *
             *          }
             *
             *          if (sensors.SensorType == SensorType.Temperature)
             *          {
             *              if (sensors.Name == "GPU Core")
             *              {
             *                  Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
             *                  gput = sensors.Value.ToString();
             *              }
             *          }
             *
             *      }
             *  }
             *
             *  if (hardware.HardwareType == HardwareType.RAM)
             *  {
             *      hardware.Update();
             *      foreach (var sensors in hardware.Sensors)
             *      {
             *          if (sensors.SensorType == SensorType.Data)
             *          {
             *              if (sensors.Name == "Used Memory")
             *              {
             *                  Console.WriteLine(sensors.Name + ": " + Math.Round(sensors.Value.GetValueOrDefault(), 0));
             *                  used_mem = sensors.Value.GetValueOrDefault();
             *              }
             *
             *              if (sensors.Name == "Available Memory")
             *              {
             *                  Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
             *                  free_mem = sensors.Value.GetValueOrDefault();
             *              }
             *          }
             *      }
             *  }
             *
             *
             *
             *
             *  //end of for loop
             * }
             **/


            //New
            foreach (var hardware in computer.Hardware)
            {
                if (hardware.HardwareType == HardwareType.CPU)
                {
                    hardware.Update();
                    foreach (var sensors in hardware.Sensors)
                    {
                        if (sensors.SensorType == SensorType.Load)
                        {
                            if (sensors.Name == "CPU Total")
                            {
                                // Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                cpuu = format_string(sensors.Value.ToString());
                            }
                        }

                        if (sensors.SensorType == SensorType.Temperature)
                        {
                            if (sensors.Name == "CPU Package")
                            {
                                // Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                cput = format_string(sensors.Value.ToString());
                            }
                        }
                    }
                }

                if (hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    hardware.Update();
                    foreach (var sensors in hardware.Sensors)
                    {
                        if (sensors.SensorType == SensorType.Load)
                        {
                            if (sensors.Name == "GPU Core")
                            {
                                // Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                gpuu = format_string(sensors.Value.ToString());
                            }
                        }

                        if (sensors.SensorType == SensorType.Temperature)
                        {
                            if (sensors.Name == "GPU Core")
                            {
                                //Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                gput = format_string(sensors.Value.ToString());
                            }
                        }
                    }
                }

                if (hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    hardware.Update();
                    foreach (var sensors in hardware.Sensors)
                    {
                        if (sensors.SensorType == SensorType.Load)
                        {
                            if (sensors.Name == "GPU Core")
                            {
                                Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                gpuu = format_string(sensors.Value.ToString());
                            }
                        }

                        if (sensors.SensorType == SensorType.Temperature)
                        {
                            if (sensors.Name == "GPU Core")
                            {
                                Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                gput = format_string(sensors.Value.ToString());
                            }
                        }
                    }
                }

                if (hardware.HardwareType == HardwareType.RAM)
                {
                    hardware.Update();
                    foreach (var sensors in hardware.Sensors)
                    {
                        if (sensors.SensorType == SensorType.Data)
                        {
                            if (sensors.Name == "Used Memory")
                            {
                                Console.WriteLine(sensors.Name + ": " + Math.Round(sensors.Value.GetValueOrDefault(), 0));
                                used_mem = sensors.Value.GetValueOrDefault();
                            }

                            if (sensors.Name == "Available Memory")
                            {
                                Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                free_mem = sensors.Value.GetValueOrDefault();
                            }
                        }
                    }
                }



                //End of the the foreach loop
            }



            total_mem_pre_round = used_mem + free_mem;
            total_mem           = format_string(Math.Ceiling(total_mem_pre_round).ToString());
            used_mem_string     = format_string(Math.Round(used_mem, 0).ToString());

            string packet_pre = cput + cpuu + gput + gpuu + used_mem_string + total_mem;

            computer.Close();

            string packet_data = packet_pre;

            byte[]     sendbuff = Encoding.ASCII.GetBytes(packet_data);
            IPEndPoint ep       = new IPEndPoint(broadcast, 6666);

            s.SendTo(sendbuff, ep);
            //Random rnd = new Random();
            //int num = rnd.Next();
            // WriteToFile("Sent packet " + packet_data);
            //string packet_data = GetRandomNumber(0, 234957675).ToString();
        }
Example #26
0
        //This is the function that is called at the end of the specified interval
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            /** Modify the following line to set it as either the IP of the monitor, or the brodcast address of
             *  your LAN  (EXAMPLE: If your LAN is 10.0.0.0/24 it is 10.0.0.255, if it is 192.168.1.0/24 it would be 192.168.1.255)
             **/
            string broadcast_address = "192.168.1.255";



            IPAddress broadcast = IPAddress.Parse(broadcast_address);


            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();
            computer.CPUEnabled = true;
            computer.RAMEnabled = true;
            computer.GPUEnabled = true;
            computer.Accept(updateVisitor);
            string cput                = "0";
            string cpuu                = "0";
            string gput                = "0";
            string gpuu                = "0";
            float  used_mem            = 0;
            float  free_mem            = 0;
            string used_mem_string     = "0";
            string total_mem           = "0";
            double total_mem_pre_round = 0;

            foreach (var hardware in computer.Hardware)
            {
                //CPU Information
                if (hardware.HardwareType == HardwareType.CPU)
                {
                    hardware.Update();
                    foreach (var sensors in hardware.Sensors)
                    {
                        //Pull CPU Temperature Information
                        if (sensors.SensorType == SensorType.Temperature)
                        {
                            if (sensors.Name == "CPU Package")
                            {
                                cput = format_string(sensors.Value.ToString());
                            }
                        }
                    }
                }

                //GPU Information
                if (hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    hardware.Update();
                    foreach (var sensors in hardware.Sensors)
                    {
                        //Pull GPU utilization information
                        if (sensors.SensorType == SensorType.Load)
                        {
                            if (sensors.Name == "GPU Core")
                            {
                                gpuu = format_string(sensors.Value.ToString());
                            }
                        }

                        //Pull GPU temperature infomration
                        if (sensors.SensorType == SensorType.Temperature)
                        {
                            if (sensors.Name == "GPU Core")
                            {
                                //Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                gput = format_string(sensors.Value.ToString());
                            }
                        }
                    }
                }

                //Pull memory information
                if (hardware.HardwareType == HardwareType.RAM)
                {
                    hardware.Update();
                    foreach (var sensors in hardware.Sensors)
                    {
                        if (sensors.SensorType == SensorType.Data)
                        {
                            //Pulls used memory
                            if (sensors.Name == "Used Memory")
                            {
                                Console.WriteLine(sensors.Name + ": " + Math.Round(sensors.Value.GetValueOrDefault(), 0));
                                used_mem = sensors.Value.GetValueOrDefault();
                            }

                            //Pulls available memory
                            if (sensors.Name == "Available Memory")
                            {
                                Console.WriteLine(sensors.Name + ": " + sensors.Value.ToString());
                                free_mem = sensors.Value.GetValueOrDefault();
                            }
                        }
                    }
                }


                //End of the the foreach loop
            }

            //CPU utilization WMI query
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    cpuu = format_string(queryObj["LoadPercentage"].ToString());
                }
            }
            catch
            {
                //Send XXX out as a packet if there is an issue pulling the data
                cpuu = "XXX";
            }



            //Find the total amount   of memory
            total_mem_pre_round = used_mem + free_mem;
            total_mem           = format_string(Math.Ceiling(total_mem_pre_round).ToString());
            used_mem_string     = format_string(Math.Round(used_mem, 0).ToString());

            //Create the string to send in the UDP packet
            string packet_pre = cput + cpuu + gput + gpuu + used_mem_string + total_mem;

            computer.Close();

            //Networky packety stuffz
            string packet_data = packet_pre;

            byte[]     sendbuff = Encoding.ASCII.GetBytes(packet_data);
            IPEndPoint ep       = new IPEndPoint(broadcast, 6666);

            s.SendTo(sendbuff, ep);
        }
Example #27
0
        static string GetSystemInfo()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer      computer      = new Computer();

            computer.Open();
            computer.CPUEnabled = true;
            computer.GPUEnabled = true;
            computer.RAMEnabled = true;
            computer.Accept(updateVisitor);
            float cl = 0, ct = 0, gl = 0, gt = 0, rl = 0;

            for (int i = 0; i < computer.Hardware.Length; i++)
            {
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            if (computer.Hardware[i].Sensors[j].Name == "CPU Package")
                            {
                                ct = (float)(computer.Hardware[i].Sensors[j].Value ?? -1);
                            }
                        }
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                        {
                            if (computer.Hardware[i].Sensors[j].Name == "CPU Total")
                            {
                                cl = (float)(computer.Hardware[i].Sensors[j].Value ?? -1);
                            }
                        }
                    }
                }
                if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia || computer.Hardware[i].HardwareType == HardwareType.GpuAti)
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                        {
                            if (computer.Hardware[i].Sensors[j].Name == "GPU Core")
                            {
                                gt = (float)computer.Hardware[i].Sensors[j].Value;
                            }
                        }
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                        {
                            if (computer.Hardware[i].Sensors[j].Name == "GPU Core")
                            {
                                gl = (float)computer.Hardware[i].Sensors[j].Value;
                            }
                        }
                    }
                }
                if (computer.Hardware[i].HardwareType == HardwareType.RAM)
                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load)
                        {
                            if (computer.Hardware[i].Sensors[j].Name == "Memory")
                            {
                                rl = (float)computer.Hardware[i].Sensors[j].Value;
                            }
                        }
                    }
                }
            }
            computer.Close();
            // return $"CPU {cl:0.##}% {ct:0.##}C\nGPU {gl:0.##}% {gt:0.##}C\nRAM {rl:0.##}%";
            string cpu = (ct) >= 0 ? $"{ct:0.##}C" : "--";

            return($"CPU {cpu}\nGPU {gt:0.##}C\nRAM {rl:0.##}%");
        }