Beispiel #1
0
        public static void Monitor()
        {
            running = true;
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer computer = new Computer();

            computer.Open();

            while (running)
            {
                computer.Accept(updateVisitor);
                MonitoringInfo currentInfo = new MonitoringInfo();

                foreach (IHardware hardware in computer.Hardware)
                {
                    if (hardware.HardwareType == HardwareType.CPU)
                    {
                        CPU cpu = new CPU();
                        AddCPUInfo(hardware.Sensors, cpu);

                        currentInfo.CPUs.Add(cpu);
                    }
                    else if (hardware.HardwareType == HardwareType.GpuAti)
                    {
                        GPU gpu = new GPU();
                        gpu.GPUTempMax = 100; // assume max gpu temp is 100 *C
                        AddGPUInfo(hardware.Sensors, gpu);

                        currentInfo.GPUs.Add(gpu);
                    }
                    else if (hardware.HardwareType == HardwareType.GpuNvidia)
                    {
                        GPU gpu = new GPU();
                        gpu.GPUTempMax = 100; // assume max gpu temp is 100 *C
                        AddGPUInfo(hardware.Sensors, gpu);

                        currentInfo.GPUs.Add(gpu);
                    }
                }

                RAM ram = new RAM();
                MEMORYSTATUSEX memoryUsage = new MEMORYSTATUSEX();
                if (GlobalMemoryStatusEx(memoryUsage))
                {
                    ram.FreeMemory = (int)(memoryUsage.ullAvailPhys / (1024 * 1024)); // in MB
                    ram.TotalMemory = (int)(memoryUsage.ullTotalPhys / (1024 * 1024)); // in MB
                }

                currentInfo.RAM = ram;

                Info = currentInfo;

                Thread.Sleep(1000);
            }
        }
Beispiel #2
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();
        }
    }