Exemplo n.º 1
0
 private void btnWired_Click(object sender, EventArgs e)
 {
     try
     {
         if (!serialPort1.IsOpen)
         {
             serialPort1.PortName = cbbCom.Text;
             Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
             _config.AppSettings.Settings["port"].Value = cbbCom.Text;
             _config.Save();
             serialPort1.Open();
             btnWired.Text            = "Disconnect";
             btnWired.ForeColor       = Color.Red;
             lblStatusWired.Text      = "Connected";
             lblStatusWired.ForeColor = Color.Green;
             AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
         }
         else
         {
             serialPort1.Close();
             btnWired.Text            = "Connect";
             btnWired.ForeColor       = Color.Green;
             lblStatusWired.Text      = "Disconnect";
             lblStatusWired.ForeColor = Color.Red;
             AppIcon.ShowBalloonTip(5000, "Đã ngắt kết nối ", "Disconnected", ToolTipIcon.Warning);
         }
     }
     catch
     {
         AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy COM", ToolTipIcon.Warning);
     }
 }
Exemplo n.º 2
0
        private void ckStartup_CheckedChanged(object sender, EventArgs e)
        {
            Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            _config.AppSettings.Settings["startTray"].Value = ckStartup.Checked.ToString();
            _config.Save();
            using (TaskService ts = new TaskService())
            {
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = "HardwareMonitorLite";
                td.Principal.RunLevel           = TaskRunLevel.Highest;
                td.Triggers.AddNew(TaskTriggerType.Logon);
                td.Actions.Add(new ExecAction(Application.ExecutablePath, null));
                if (ckStartup.Checked == true)
                {
                    ts.RootFolder.RegisterTaskDefinition("HardwareMonitorLite", td);
                    AppIcon.ShowBalloonTip(500, "Khởi động cùng windows !", "Start with windows ! ", ToolTipIcon.Info);
                }
                else
                {
                    ts.RootFolder.DeleteTask("HardwareMonitorLite");
                    AppIcon.ShowBalloonTip(500, "Không khởi động cùng windows!", "Does not start with windows ! ", ToolTipIcon.Info);
                }
            }
        }
Exemplo n.º 3
0
        private async Task RefreshLoadProcesses()
        {
            var apps = await AppList.GetRunningApplications();

            if (apps == null)
            {
                return;
            }
            foreach (var p in apps)
            {
                if (p == null)
                {
                    continue;
                }
                if (this._allAppWithPorts.All(x => x.InstancePid != p.InstancePid))
                {
                    var dispatcher = this.Dispatcher;
                    if (dispatcher != null)
                    {
                        await dispatcher.BeginInvoke(new ThreadStart(delegate
                        {
                            p.Icon = AppIcon.GetIcon(p.FullName, false);
                            this._allAppWithPorts.Add(p);
                        }));
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void UpdateIcon(AppIcon icon)
        {
            string tempPath = null;

            string path;

            if (icon == null || icon.Icons.Length == 0)
            {
                path = DefaultIconName;
            }
            else if (icon.Source == AppIcon.IconSource.File)
            {
                path = icon.DefaultIcon.Path;
            }
            else
            {
                tempPath = Path.GetTempFileName();
                using (var tmpStream = File.Open(tempPath, FileMode.Create))
                    using (var iconStream = icon.GetIconDataStream(icon.DefaultIcon))
                    {
                        iconStream.CopyTo(tmpStream);
                    }

                path = tempPath;
            }

            using (GLibString gpath = path)
            {
                AppIndicator.SetIcon(Handle, gpath);
            }

            ClearTempFile();
            tempIconFile = tempPath;
        }
        private void btnWired_Click(object sender, EventArgs e)
        {
            Thread threadWired = new Thread(() =>
            {
                MethodInvoker method = delegate
                {
                    try
                    {
                        if (!serialPort1.IsOpen)
                        {
                            serialPort1.PortName  = cbbCom.Text;
                            Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                            _config.AppSettings.Settings["port"].Value = cbbCom.Text;
                            _config.Save();
                            serialPort1.Open();
                            btnWired.Text            = "Disconnect";
                            btnWired.ForeColor       = Color.Red;
                            lblStatusWired.Text      = "Connected";
                            lblStatusWired.ForeColor = Color.Green;
                            AppIcon.ShowBalloonTip(2000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                            cbbCom.Enabled    = false;
                            btnReload.Enabled = false;
                        }
                        else
                        {
                            serialPort1.Close();
                            btnWired.Text            = "Connect";
                            btnWired.ForeColor       = Color.Black;
                            lblStatusWired.Text      = "Disconnect";
                            lblStatusWired.ForeColor = Color.Red;
                            AppIcon.ShowBalloonTip(2000, "Đã ngắt kết nối ", "Disconnected", ToolTipIcon.Warning);
                            cbbCom.Enabled    = true;
                            btnReload.Enabled = true;
                        }
                    }
                    catch
                    {
                        btnWired.Text            = "Connect";
                        btnWired.ForeColor       = Color.Black;
                        lblStatusWired.Text      = "Disconnect";
                        lblStatusWired.ForeColor = Color.Red;
                        AppIcon.ShowBalloonTip(2000, "Lỗi kêt nối", "Không tìm thấy PORT", ToolTipIcon.Warning);
                        cbbCom.Enabled = true;
                    }
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            });

            threadWired.IsBackground = true;
            threadWired.Start();
        }
Exemplo n.º 6
0
        internal Base(View view, string name, AppIcon icon)
        {
            View = view;
            Name = name;
            Icon = icon;

            NotificationsCounter = 0;
        }
Exemplo n.º 7
0
 public async static Task <AppIconDataContract> ToAppIconDataContract(this AppIcon appIcon)
 {
     return(new AppIconDataContract()
     {
         AppId = appIcon.AppId,
         Icon128X128 = null,  // this set on the server by resize Icon256X256
         Icon256X256 = await appIcon.Icon256X256StorageFile.AsByteArrayAsync(),
     });
 }
Exemplo n.º 8
0
        protected static void Run()
        {
            using (var window = new Window())
            {
                window.Title = "MyApp";
                window.Icon  = AppIcon.FromFile("icon", ".");

                Application.ContentProvider = new EmbeddedContentProvider("App");
                Application.Run(window, "index.html");
            }
        }
Exemplo n.º 9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (AppName != null ? AppName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AppLocation != null ? AppLocation.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AppArguments != null ? AppArguments.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AppIcon != null ? AppIcon.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (EnabledMods != null ? EnabledMods.GetHashCode() : 0);
         return(hashCode);
     }
 }
Exemplo n.º 10
0
        private void btnConnectWIFI_Click(object sender, EventArgs e)
        {
            if (btnConnectWIFI.Text == "Connect")
            {
                lblWIFIStatus.Text      = "Connecting...";
                lblWIFIStatus.ForeColor = Color.Black;
                btnConnectWIFI.Enabled  = false;

                try
                {
                    client.ConnectAsync(txtIP.Text, 80).Wait(5000);
                }
                catch
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Địa Chỉ IP không đúng !!", ToolTipIcon.Warning);
                    lblWIFIStatus.Text      = "Disconnected";
                    lblWIFIStatus.ForeColor = Color.Red;
                }
                if (client.Connected)
                {
                    txtIP.Enabled            = false;
                    btnConnectWIFI.Text      = "Disconnect";
                    btnConnectWIFI.ForeColor = Color.Red;
                    lblWIFIStatus.Text       = "Connected";
                    lblWIFIStatus.ForeColor  = Color.Green;
                    AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                    Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    _config.AppSettings.Settings["ip"].Value = txtIP.Text;
                    _config.Save();
                }
                else
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                    lblWIFIStatus.Text      = "Disconnect";
                    lblWIFIStatus.ForeColor = Color.Red;
                    client.Close();
                    client = new TcpClient();
                }
            }
            else
            {
                txtIP.Enabled            = true;
                btnConnectWIFI.Text      = "Connect";
                btnConnectWIFI.ForeColor = Color.Black;
                lblWIFIStatus.Text       = "Disconnect";
                lblWIFIStatus.ForeColor  = Color.Red;
                client.Close();
                client = new TcpClient();
            }
            btnConnectWIFI.Enabled = true;
        }
Exemplo n.º 11
0
        private unsafe void SetIcon(AppIcon icon)
        {
            if (icon == null || icon.Icons.Length == 0)
            {
                Gtk.Window.SetIcon(Handle, IntPtr.Zero);
            }
            else
            {
                IntPtr iconList = IntPtr.Zero;
                var    icons    = new IntPtr[icon.Icons.Length];

                try
                {
                    for (int i = 0; i < icons.Length; i++)
                    {
                        IntPtr iconStream = IntPtr.Zero;
                        try
                        {
                            byte[] data = icon.GetIconData(icon.Icons[i]);
                            fixed(byte *iconDataPtr = data)
                            {
                                iconStream = GLib.CreateStreamFromData((IntPtr)iconDataPtr, data.Length, IntPtr.Zero);
                                icons[i]   = Gdk.Pixbuf.NewFromStream(iconStream, IntPtr.Zero, IntPtr.Zero);
                                iconList   = GLib.ListPrepend(iconList, icons[i]);
                            }
                        }
                        finally { if (iconStream != IntPtr.Zero)
                                  {
                                      GLib.UnrefObject(iconStream);
                                  }
                        }
                    }

                    Gtk.Window.SetIconList(Handle, iconList);
                }
                finally
                {
                    if (iconList != IntPtr.Zero)
                    {
                        GLib.FreeList(iconList);
                    }
                    foreach (var item in icons)
                    {
                        if (item != IntPtr.Zero)
                        {
                            GLib.UnrefObject(item);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void SetIcon(AppIcon icon)
        {
            this.icon = icon;

            if (icon == null || icon.Icons.Length == 0)
            {
                Icon = null;
            }
            else
            {
                using var stream = icon.GetIconDataStream(icon.DefaultIcon);
                Icon             = new Icon(stream);
            }
        }
 private void UpdateIcon(AppIcon icon)
 {
     if (icon == null || icon.Icons.Length == 0)
     {
         notifyIcon.Icon = null;
     }
     else
     {
         using (var stream = icon.GetIconDataStream(icon.DefaultIcon))
         {
             notifyIcon.Icon = new System.Drawing.Icon(stream);
         }
     }
 }
Exemplo n.º 14
0
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            _config.AppSettings.Settings["startTray"].Value = checkBox1.Checked.ToString();
            _config.Save();
            if (checkBox1.Checked)
            {
                AppIcon.ShowBalloonTip(500, "Sẽ chạy cùng Windows ", "Will run with Windows", ToolTipIcon.Info);
            }
            else
            {
                AppIcon.ShowBalloonTip(500, "Sẽ không chạy cùng Windows", "Will not run with Windows", ToolTipIcon.Info);
            }
        }
Exemplo n.º 15
0
        public override async Task <AppIcon> DownloadIconAsync(AppMetadata meta)
        {
            if (string.IsNullOrEmpty(meta.IconUrl))
            {
                throw new ArgumentException("Metadata has empty icon url", nameof(meta));
            }
            var result     = new AppIcon();
            var httpResult = await Client.GetAsync(new Uri(meta.IconUrl));

            if (httpResult.Content != null)
            {
                result.ContentType = httpResult.Content?.Headers?.ContentType?.MediaType;
                result.Content     = await httpResult.Content.ReadAsByteArrayAsync();
            }
            return(result);
        }
Exemplo n.º 16
0
 private void Home_Resize(object sender, EventArgs e)
 {
     if (this.WindowState != FormWindowState.Normal)
     {
         this.Hide();
         AppIcon.ShowBalloonTip(500, "Đang Chạy Thu Nhỏ !", "Minimize to tray!", ToolTipIcon.Info);
     }
     else
     {
         //this.Visible = true;
         this.Show();
         this.WindowState = FormWindowState.Normal;
         this.Activate();
         this.Focus();
         this.ShowInTaskbar = true;
     }
 }
Exemplo n.º 17
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            log.Info("Starting Application...");

            ProcessMonitor.Start();
            using (var mi = new AppIcon())
            {
                mi.Display();

                Application.Run();
            }

//            var form = new SettingsDialog();
//            Application.Run(form);
        }
Exemplo n.º 18
0
        public Main()
        {
            InitializeComponent();
            base.WindowState   = FormWindowState.Minimized;         // Thu nhỏ của sổ ngay từ lúc đầu mở ra
            base.ShowInTaskbar = false;                             // Không hiển thị trên thanh Taskbar
            base.Visible       = true;                              // Ẩn chương trình
            base.Hide();
            AddMenu();                                              // Tạo menu
            this.thisComputer.CPUEnabled       = true;
            this.thisComputer.GPUEnabled       = true;
            this.thisComputer.HDDEnabled       = true;
            this.thisComputer.MainboardEnabled = true;
            this.thisComputer.RAMEnabled       = true;
            this.thisComputer.Open();
            XmlDocument file = new XmlDocument();                   // Đọc địa chỉ từ file xml

            file.Load("ipAddress.xml");
            XmlNode ip = file.SelectNodes("/data/Address")[0];      // Chọn node Address

            if (ip.InnerText == "")                                 // Chưa có địa chỉ IP trong file
            {
                AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không có địa chỉ IP để kết nối\r\nYêu cầu nhập địa chỉ IP của server", ToolTipIcon.Warning);
            }
            else
            {
                IPAddr.Text = ip.InnerText;                             // Đọc địa chỉ
                client.ConnectAsync(ip.InnerText, 80).Wait(3000);       // Thử kết nối với server, timeout 5000ms
                if (client.Connected)
                {
                    IPAddr.ReadOnly    = true;
                    connectButton.Text = "Disconnect";
                    status.Text        = "Connected";
                    status.ForeColor   = Color.Green;
                    timer.Enabled      = true;
                }
                else
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                    client.Close();
                    client = new TcpClient();
                }
            }
        }
Exemplo n.º 19
0
        /*--------------------------------------------------------------------------------------*/

        private void connectButton_Click(object sender, EventArgs e)
        {
            if (connectButton.Text == "Connect")
            {
                status.Text           = "Connecting...";
                status.ForeColor      = Color.Black;
                connectButton.Enabled = false;
                client.ConnectAsync(IPAddr.Text, 80).Wait(5000);       // Thử kết nối với server, timeout 5000ms
                if (client.Connected)
                {
                    IPAddr.Enabled     = false;
                    connectButton.Text = "Disconnect";
                    status.Text        = "Connected";
                    status.ForeColor   = Color.Green;
                    XmlDocument file = new XmlDocument();                   // Load file XML
                    file.Load("ipAddress.xml");
                    XmlNode ip = file.SelectNodes("/data/Address")[0];      // Chọn node Address
                    ip.InnerText = IPAddr.Text;                             // Thay đổi địa chỉ
                    file.Save("ipAddress.xml");                             // Lưu địa chỉ IP
                    timer.Enabled = true;
                }
                else
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                    status.Text      = "Disconnected";
                    status.ForeColor = Color.Red;
                    client.Close();
                    client = new TcpClient();
                }
            }
            else
            {
                IPAddr.Enabled     = true;
                timer.Enabled      = false;
                connectButton.Text = "Connect";
                status.Text        = "Disconnected";
                status.ForeColor   = Color.Red;
                client.Close();
                client = new TcpClient();
            }
            connectButton.Enabled = true;
        }
Exemplo n.º 20
0
        public static void Main(string[] args)
        {
            // Note: Program.cs is shared between all projects for convenience.
            // You could just as well have a separate startup logic for each platform.

            // this creates a new configuration with default values
            var config = new WindowConfiguration();
            var icon   = AppIcon.FromFile("icon", "Icons");

            // we have a separate assembly for the client side files
            config.ContentAssembly = typeof(DummyMarker).Assembly;
            // this relates to the path defined in the client .csproj file
            config.ContentFolder = "Angular\\dist";
            config.Icon          = icon;

            // this is only called in Debug mode:
            SetDevServer(config);

            // runs the application and opens a window with the given page loaded
            Application.Run(config, "index.html");
        }
Exemplo n.º 21
0
        protected static void Run()
        {
            // this creates a new window with default values
            using (var window = new Window())
            {
                window.Icon = AppIcon.FromFile("icon", ".");

                // these are only called in Debug mode:
                SetDevSettings(window);

                // the port number is defined in the angular.json file (under "architect"->"serve"->"options"->"port")
                // note that you have to run the angular dev server first (npm run watch)
                Application.UriWatcher = new AngularDevUriWatcher("http://localhost:65000");

                // this relates to the path defined in the .csproj file
                Application.ContentProvider = new EmbeddedContentProvider("Angular\\dist");

                // runs the application and opens the window with the given page loaded
                Application.Run(window, "/index.html");
            }
        }
Exemplo n.º 22
0
        protected static void Run(BotArguments botArguments)
        {
            using (var bot = new Bot())
                using (var window = new Window())
                {
                    bot.Execute(botArguments);

                    window.UseBrowserTitle = false;
                    window.Title           = "Bot Brown";
                    window.CanResize       = true;
                    window.SetWindowState(WindowState.Maximized);

                    window.Icon           = AppIcon.FromFile("botbrown", ".");
                    window.EnableDevTools = false;

                    // this relates to the path defined in the .csproj file
                    Application.ContentProvider = new EmbeddedContentProvider("App");

                    string port = botArguments.Port ?? (botArguments.IsDebug ? WebserverConstants.DebugPort : WebserverConstants.ProductivePort);
                    Application.Run(window, $"http://localhost:{port}");
                }
        }
Exemplo n.º 23
0
        private unsafe void UpdateIcon(AppIcon icon)
        {
            var image = IntPtr.Zero;

            if (icon != null && icon.Icons.Length > 0)
            {
                byte[] data = icon.GetIconData(icon.DefaultIcon);
                fixed(byte *dataPtr = data)
                {
                    IntPtr nsData = Foundation.Call(
                        "NSData",
                        "dataWithBytesNoCopy:length:freeWhenDone:",
                        (IntPtr)dataPtr,
                        new IntPtr(data.Length),
                        IntPtr.Zero);

                    image = AppKit.Call("NSImage", "alloc");
                    ObjC.Call(image, "initWithData:", nsData);
                    ObjC.Call(statusBarButton, "setImage:", image);
                }
            }

            ObjC.Call(statusBarButton, "setImage:", image);
        }
Exemplo n.º 24
0
        private void SetHomeMenuApp(int index, AppIcon icon, string name = "", int notifications = 0, float opacity = 1f)
        {
            Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Cellphone.Handle, "SET_DATA_SLOT");
            Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, (int)View.HomeMenu);

            // Index
            Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, index);

            // 0 - Icon
            Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, (int)icon);

            // 1 - Notifications count
            Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, notifications);

            // 2 - Name
            Function.Call(Hash._BEGIN_TEXT_COMPONENT, "STRING");
            Function.Call(Hash.ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME, name);
            Function.Call(Hash._END_TEXT_COMPONENT);

            // 3 - Opacity
            Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, (int)(opacity * 100f));

            Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
        }
Exemplo n.º 25
0
 public void ChangeIcon(AppIcon icon)
 {
     AppIconChanged?.Invoke(this, icon);
 }
Exemplo n.º 26
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            foreach (var hardware in thisComputer.Hardware)
            {
                hardware.Update();
                /*---------------------------------CPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.Cpu)
                {
                    cpuName = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "CPU Total")
                        {
                            cpuLoad = sensor.Value.Value;
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "CPU Package")
                        {
                            cpuTemp = sensor.Value.GetValueOrDefault();
                        }
                    }
                }
                /*---------------------------------GPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.GpuAmd || hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    gpuName = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "GPU Core")
                        {
                            gpuLoad = sensor.Value.Value;
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "GPU Core")
                        {
                            gpuTemp = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Fan && sensor.Name == "GPU Fan")
                        {
                            gpuFan = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Control && sensor.Name == "GPU Fan")
                        {
                            gpuFanLoad = sensor.Value.GetValueOrDefault();
                        }
                    }
                }
                /*---------------------------------RAM---------------------------------*/
                if (hardware.HardwareType == HardwareType.Memory)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Memory")
                        {
                            ramLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Used")
                        {
                            ramUse = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Available")
                        {
                            float ramAva = sensor.Value.GetValueOrDefault();
                            totalRam = ramAva + ramUse;
                        }
                    }
                }
                /*---------------------------------Connection---------------------------------*/
                if (hardware.HardwareType == HardwareType.Network)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Upload Speed")
                        {
                            upload = (sensor.Value.GetValueOrDefault()) * 8 / 1048576;
                        }
                        if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Download Speed")
                        {
                            download = (sensor.Value.GetValueOrDefault()) * 8 / 1048576;
                        }
                        strNw = Math.Round(download, 2).ToString("F2") + "/" + Math.Round(upload, 2).ToString("F2");
                        if (strNw.Length > 10)
                        {
                            strNw = "Connecting...";
                        }
                    }
                }
                /*---------------------------------Drive---------------------------------*/
                if (hardware.Name == "WDC WD10EZEX-00WN4A0")
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        hdd = hardware.Name;
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Total Activity")
                        {
                            hddLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "Temperature")
                        {
                            hddTemp = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Used Space")
                        {
                            hddUse = sensor.Value.GetValueOrDefault();
                        }
                    }
                }

                if (hardware.Name == "Samsung SSD 960 EVO 250GB")
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        ssd = hardware.Name.Substring(0, 19);
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Total Activity")
                        {
                            ssdLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "Temperature")
                        {
                            ssdTemp = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Used Space")
                        {
                            ssdUse = sensor.Value.GetValueOrDefault();
                        }
                    }
                }

                if (hardware.HardwareType == HardwareType.Heatmaster)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "CPU Total")
                        {
                            cpuLoad = sensor.Value.Value;
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "CPU Package")
                        {
                            cpuTemp = sensor.Value.GetValueOrDefault();
                        }
                    }
                }
                /*---------------------------------Display---------------------------------*/
                grCPU.Text      = cpuName;
                txtLoadCPU.Text = Math.Round(cpuLoad).ToString() + " %";
                txtTempCPU.Text = Math.Round(cpuTemp).ToString() + " °C";

                grGPU.Text      = gpuName;
                txtLoadGPU.Text = Math.Round(gpuLoad).ToString() + " %";
                txtTempGPU.Text = Math.Round(gpuTemp).ToString() + " °C";
                txtFanGPU.Text  = Math.Round(gpuFan).ToString() + " RPM";

                txtTotalRam.Text = Math.Round(totalRam).ToString() + " GB";
                txtRamUse.Text   = Math.Round(ramUse).ToString() + " GB";
                txtRamLoad.Text  = Math.Round(ramLoad).ToString() + " %";

                txtDown.Text = Math.Round(download, 2).ToString("F2") + " MB/s";
                txtUp.Text   = Math.Round(upload, 2).ToString("F2") + " MB/s";

                grHDD.Text      = hdd;
                txtHddLoad.Text = Math.Round(hddLoad).ToString() + " %";
                txtHddUse.Text  = Math.Round(hddUse).ToString() + " %";
                txtHddTemp.Text = Math.Round(hddTemp).ToString() + " °C";

                grSSD.Text      = ssd;
                txtSsdLoad.Text = Math.Round(ssdLoad).ToString() + " %";
                txtSsdUse.Text  = Math.Round(ssdUse).ToString() + " %";
                txtSsdTemp.Text = Math.Round(ssdTemp).ToString() + " °C";
                /*---------------------------------Send DATA---------------------------------*/
            }
            Processor dataCPU = new Processor
            {
                Name = cpuName,
                Load = Math.Round(cpuLoad, 1),
                Temp = Math.Round(cpuTemp, 1)
            };
            Graphic dataGPU = new Graphic
            {
                Name = gpuName,
                Load = Math.Round(gpuLoad, 1),
                Temp = Math.Round(gpuTemp, 1),
            };
            Ram dataRam = new Ram
            {
                Use = Math.Round(ramUse).ToString() + "/" + Math.Round(totalRam).ToString()
            };
            Connection dataNet = new Connection
            {
                Speed = strNw
            };
            HDD infoHDD = new HDD
            {
                Name = hdd,
                Use  = Math.Round(hddUse),
                Load = Math.Round(hddLoad),
                Temp = Math.Round(hddTemp)
            };
            SSD infoSSD = new SSD
            {
                Name = ssd,
                Use  = Math.Round(ssdUse),
                Load = Math.Round(ssdLoad),
                Temp = Math.Round(ssdTemp)
            };
            Infomation info = new Infomation
            {
                CPU      = dataCPU,
                GPU      = dataGPU,
                RAM      = dataRam,
                Net      = dataNet,
                hddDrive = infoHDD,
                ssdDrive = infoSSD
            };
            string obj = JsonConvert.SerializeObject(info);

            if (lblWIFIStatus.Text == "Connected")
            {
                try
                {
                    NetworkStream stream = client.GetStream();
                    byte[]        data   = Encoding.ASCII.GetBytes(obj + "\r\n");
                    stream.Write(data, 0, data.Length);
                }
                catch (Exception)
                {
                    AppIcon.ShowBalloonTip(5000, "Mất kêt nối", "Kiểm tra lại server", ToolTipIcon.Warning);
                    txtIP.Enabled           = true;
                    timer1.Enabled          = false;
                    btnConnectWIFI.Text     = "Connect";
                    lblWIFIStatus.Text      = "Disconnected";
                    lblWIFIStatus.ForeColor = Color.Red;
                    client.Close();
                    client = new TcpClient();
                }
            }
            if (lblStatusWired.Text == "Connected")
            {
                a = dataCPU.Name + "," + dataCPU.Load + "," + dataCPU.Temp + "," + dataGPU.Name + "," + dataGPU.Load + "," + dataGPU.Temp + "," + dataRam.Use + "," + dataNet.Speed + "," + infoHDD.Name + "," + infoHDD.Use + "," + infoHDD.Load + "," + infoHDD.Temp + "," + infoSSD.Name + "," + infoSSD.Use + "," + infoSSD.Load + "," + infoSSD.Temp + "*";
                serialPort1.Write(a);
            }
        }
Exemplo n.º 27
0
 public void SetIcon(AppIcon icon)
 {
     // windows on macOS don't have icons
 }
Exemplo n.º 28
0
        public Home()
        {
            InitializeComponent();
            timer.Interval = 1000;
            timer.Start();

            AddMenu();
            this.thisComputer.IsCpuEnabled         = true;
            this.thisComputer.IsGpuEnabled         = true;
            this.thisComputer.IsStorageEnabled     = true;
            this.thisComputer.IsMotherboardEnabled = true;
            this.thisComputer.IsMemoryEnabled      = true;
            this.thisComputer.IsNetworkEnabled     = true;
            this.thisComputer.Open();
            /*AUTO*/
            if (ConfigurationManager.AppSettings["autoConnectWifi"].ToString().ToLower().Equals("true"))
            {
                swWifiAuto.Value = true;
            }
            else
            {
                swWifiAuto.Value = false;
            }
            if (ConfigurationManager.AppSettings["autoConnectWired"].ToString().ToLower().Equals("true"))
            {
                swWiredAuto.Value = true;
            }
            else
            {
                swWiredAuto.Value = false;
            }
            if (ConfigurationManager.AppSettings["startTray"].ToString().ToLower().Equals("true"))
            {
                checkBox1.Checked = true;
            }
            if (ConfigurationManager.AppSettings["state"].ToString().ToLower().Equals("true"))
            {
                base.WindowState   = FormWindowState.Minimized;
                base.ShowInTaskbar = false;
                checkBox2.Checked  = true;
            }
            else
            {
                base.WindowState   = FormWindowState.Normal;
                base.ShowInTaskbar = true;
                checkBox2.Checked  = false;
            }
            /*WIRED*/
            serialPort1.BaudRate  = 9600;
            serialPort1.Parity    = Parity.None;
            serialPort1.StopBits  = StopBits.One;
            serialPort1.DataBits  = 8;
            serialPort1.Handshake = Handshake.None;
            serialPort1.RtsEnable = true;
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                cbbCom.Items.Add(port);
            }
            cbbCom.SelectedIndex = cbbCom.Items.IndexOf(ConfigurationManager.AppSettings["port"].ToString());
            if (swWiredAuto.Value == true)
            {
                if (cbbCom.Text != "")
                {
                    try
                    {
                        serialPort1.PortName = cbbCom.Text;
                        if (!serialPort1.IsOpen)
                        {
                            serialPort1.Open();
                            btnWired.Text            = "Disconnect";
                            btnWired.ForeColor       = Color.Red;
                            lblStatusWired.Text      = "Connected";
                            lblStatusWired.ForeColor = Color.Green;
                            AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                        }
                    }
                    catch
                    {
                        AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy Port", ToolTipIcon.Warning);
                        lblStatusWired.Text      = "Disconnected";
                        lblStatusWired.ForeColor = Color.Red;
                    }
                }
            }
            /*WIFI*/
            string ip = ConfigurationManager.AppSettings["ip"].ToString();

            if (ip != "")
            {
                txtIP.Text = ip;
            }
            if (swWifiAuto.Value == true)
            {
                if (ip == "")
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không có địa chỉ IP để kết nối\r\nYêu cầu nhập địa chỉ IP của server", ToolTipIcon.Warning);
                }
                else
                {
                    client.ConnectAsync(ip, 80).Wait(3000);
                    if (client.Connected)
                    {
                        txtIP.Enabled       = false;
                        btnConnectWIFI.Text = "Disconnect";
                        //btnConnectWIFI.BackColor = Color.Red;
                        lblStatusWifi.Text      = "Connected";
                        lblStatusWifi.ForeColor = Color.Green;
                        AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                    }
                    else
                    {
                        AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                        client.Close();
                        lblStatusWifi.Text      = "Disconnected";
                        lblStatusWifi.ForeColor = Color.Red;
                        client = new TcpClient();
                    }
                }
            }
        }
Exemplo n.º 29
0
        private void timer_Tick(object sender, EventArgs e)
        {
            string cpuName = "", gpuName = "";
            float  cpuLoad = 0, cpuTemp = 0;
            float  gpuLoad = 0, gpuTemp = 0, gpuFan = 0, gpuFanLoad = 0;
            float  ramLoad = 0, ramUse = 0, totalRam = 0, x, y;

            /*-------------------------------------Read Info-------------------------------------*/
            foreach (var hardware in thisComputer.Hardware)
            {
                hardware.Update();
                /*---------------------------------CPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.Cpu)
                {
                    cpuName         = hardware.Name;
                    lblCPUName.Text = cpuName;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "CPU Total")
                        {
                            cpuLoad = sensor.Value.Value;
                            int load = (int)cpuLoad;
                            psCPULoad.Value = load;
                            lblCPULoad.Text = load.ToString();
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "CPU Package")
                        {
                            cpuTemp = sensor.Value.GetValueOrDefault();
                            int temp = (int)cpuTemp;
                            psCPUTemp.Value = temp;
                            lblCpuTemp.Text = temp.ToString();
                        }
                    }
                }

                /*---------------------------------RAM---------------------------------*/
                if (hardware.HardwareType == HardwareType.Memory)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Memory")
                        {
                            ramLoad = sensor.Value.Value;
                            int load = (int)ramLoad;
                            psRamLoad.Value = load;
                            lblRamLoad.Text = load.ToString();
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Used")
                        {
                            ramUse = sensor.Value.GetValueOrDefault();
                            double ram = Math.Round(ramUse, 2);
                            lblRamUse.Text = ram.ToString();
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Available")
                        {
                            float ramAva = sensor.Value.GetValueOrDefault();
                            totalRam = ramAva + ramUse;
                            double ram = Math.Round(totalRam);
                            lblRamTotal.Text = ram.ToString() + " GB";
                        }
                    }
                }

                /*---------------------------------GPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.GpuAmd || hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    gpuName         = hardware.Name;
                    lblGPUName.Text = gpuName;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "GPU Core")
                        {
                            gpuLoad = sensor.Value.Value;
                            int load = (int)gpuLoad;
                            psGPULoad.Value = load;
                            lblGPULoad.Text = load.ToString();
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "GPU Core")
                        {
                            gpuTemp         = sensor.Value.GetValueOrDefault();
                            psGPUTemp.Value = (int)gpuTemp;
                            lblGPUTemp.Text = gpuTemp.ToString();
                        }
                        if (sensor.SensorType == SensorType.Fan && sensor.Name == "GPU Fan")
                        {
                            gpuFan         = sensor.Value.GetValueOrDefault();
                            lblGPUFan.Text = ((int)gpuFan).ToString();
                        }
                        if (sensor.SensorType == SensorType.Control && sensor.Name == "GPU Fan")
                        {
                            gpuFanLoad = sensor.Value.GetValueOrDefault();
                            int fanLoad = (int)gpuFanLoad;
                            psGPUFanLoad.Value = fanLoad;
                        }
                    }
                }
            }
            foreach (NetworkInterface inf in interfaces)
            {
                if (inf.OperationalStatus == OperationalStatus.Up &&
                    inf.NetworkInterfaceType != NetworkInterfaceType.Loopback &&
                    inf.NetworkInterfaceType != NetworkInterfaceType.Tunnel &&
                    inf.NetworkInterfaceType != NetworkInterfaceType.Unknown && !inf.IsReceiveOnly)
                {
                    byteRec  = inf.GetIPv4Statistics().BytesReceived;
                    byteSent = inf.GetIPv4Statistics().BytesSent;
                }
            }
            x       = byteRec - oldRec;
            y       = byteSent - oldSent;
            oldRec  = byteRec;
            oldSent = byteSent;
            string strNw = (x / 1048576).ToString("F2") + "/" + (y / 1048576).ToString("F2");

            if (strNw.Length > 10)
            {
                strNw = "Connecting...";
            }
            else
            {
                lblNet.Text = strNw + " Mb/s";
            }

            Processor dataCPU = new Processor
            {
                Name = cpuName,
                Load = Math.Round(cpuLoad, 1),
                Temp = Math.Round(cpuTemp, 1)
            };
            Graphic dataGPU = new Graphic
            {
                Name    = gpuName,
                Load    = Math.Round(gpuLoad, 1),
                Temp    = Math.Round(gpuTemp, 1),
                FanLoad = Math.Round(gpuFan, 1),
                Fan     = Math.Round(gpuFanLoad, 1)
            };
            Ram dataRam = new Ram
            {
                Total = Math.Round(totalRam),
                Use   = Math.Round(ramUse, 1),
                Load  = Math.Round(ramLoad, 1)
            };
            Net dataNet = new Net
            {
                net = strNw
            };
            Infomation info = new Infomation
            {
                CPU = dataCPU,
                GPU = dataGPU,
                RAM = dataRam,
                Net = dataNet
            };
            string obj = JsonConvert.SerializeObject(info);

            /*---------------------------------Send DATA---------------------------------*/
            if (lblStatusWifi.Text == "Connected")
            {
                try
                {
                    NetworkStream stream = client.GetStream();
                    byte[]        data   = Encoding.ASCII.GetBytes(obj + "\r\n");
                    stream.Write(data, 0, data.Length);
                }
                catch (Exception)
                {
                    AppIcon.ShowBalloonTip(5000, "Mất kêt nối", "Kiểm tra lại server", ToolTipIcon.Warning);
                    txtIP.Enabled           = true;
                    timer.Enabled           = false;
                    btnConnectWIFI.Text     = "Connect";
                    lblStatusWifi.Text      = "Disconnected";
                    lblStatusWifi.ForeColor = Color.Red;
                    client.Close();
                    client.Close();
                    client = new TcpClient();
                }
            }
            if (lblStatusWired.Text == "Connected")
            {
                serialPort1.Write(obj);
            }
        }
Exemplo n.º 30
0
 private void Exit(object sender, EventArgs e)               // Thoát chương trình
 {
     Application.Exit();
     AppIcon.Dispose();
 }