internal static string GetDescription(this PowerStatus value) { switch (value) { case PowerStatus.FlightMode: return("flight mode"); case PowerStatus.Minimum: return("minimum"); case PowerStatus.Off: return("OFF"); case PowerStatus.On: return("ON"); case PowerStatus.PowerOnSequenceIsRunning: return("power on sequence is running"); case PowerStatus.Unknown: return("unknown"); default: return(""); } }
private void TimerTick(object sender, EventArgs e) { PowerStatus powerStatus = SystemInformation.PowerStatus; String percentage = (powerStatus.BatteryLifePercent * 100).ToString(); bool isCharging = SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online; String bitmapText = isCharging ? percentage + "*" : percentage; using (Bitmap bitmap = new Bitmap(GetTextBitmap(bitmapText, new Font(font, fontSize), Color.White))) { System.IntPtr intPtr = bitmap.GetHicon(); try { using (Icon icon = Icon.FromHandle(intPtr)) { notifyIcon.Icon = icon; String toolTipText = percentage + "%" + (isCharging ? " Charging" : ""); notifyIcon.Text = toolTipText; } } finally { DestroyIcon(intPtr); } } }
private void ShowPowerStatus() { PowerStatus status = SystemInformation.PowerStatus; batteryPercent = status.BatteryLifePercent * 100; textBoxChargeStatus.Text = status.BatteryChargeStatus.ToString(); if (status.BatteryFullLifetime == -1) { textBoxFullLifeTime.Text = "Unknown"; } else { textBoxFullLifeTime.Text = status.BatteryFullLifetime.ToString(); } textBoxCharge.Text = status.BatteryLifePercent.ToString("P0"); if (status.BatteryLifeRemaining == -1) { textBoxLifeRemaining.Text = "Unknown"; } else { textBoxLifeRemaining.Text = status.BatteryLifeRemaining.ToString(); } textBoxLineStatus.Text = status.PowerLineStatus.ToString(); }
public void MainLoop(int minimum, int maximum) { minimumBatteryPercentage = minimum; maximumBatteryPercentage = maximum; while (true) { PowerStatus pw = SystemInformation.PowerStatus; int batteryPercent = (int)(pw.BatteryLifePercent // gets the battery percentage as a float -> 0.75 * 100); // that's why we multiply it by 100 if (IsBelowMinimum(minimum, batteryPercent)) { DisplayLowBatteryAlertWindow(minimum); break; } else if (IsAboveMaximum(maximum, batteryPercent)) { DisplayHighBatteryAlertWindow(maximum); break; } Thread.Sleep(60000); // Check every one minute. } }
private void updatePowerStatus(PowerStatus powerStatus) { lock (this._powerStatusLock) { this.PowerStatus = powerStatus; } }
public Worker(FConstants.WorkerType type, Status status, FIpcClient rc = null, LogWriter logwriter = null) { this.Type = type; _logger = logwriter; radioClient = rc; _machineName = Environment.MachineName; apiPort = FFunc.FreePortHelper.GetFreePort(FConstants.WorkerAPIPort_Start); idletime = 0; isRunning = false; AlwaysRun = false; filename = ""; workerStatus = new WorkerStatus(); WatchDogCounter = 60; s = status; Level = -1; PowerStatus powerStatus = SystemInformation.PowerStatus; powerLineAttached = (powerStatus.PowerLineStatus == PowerLineStatus.Online) ? true : false; _p = new Process(); _p.StartInfo.RedirectStandardOutput = true; _p.StartInfo.UseShellExecute = false; _p.StartInfo.CreateNoWindow = true; //** Timer for ProcessMonitor pMonitorTimer = new System.Timers.Timer(); pMonitorTimer.Elapsed += new ElapsedEventHandler(ProcessMonitor); pMonitorTimer.Interval = 1000; CleanUpDuplicateProcess(); log($"Initalized with MachineName {_machineName} at apiPort {apiPort}."); }
public void TearDown() { MockedTimerAutomaticOff = null; TestTimers = null; TestPowerStatus = null; TestPowerEventArgs = null; }
private void ShowPowerStatus() { while (true) { PowerStatus status = SystemInformation.PowerStatus; string pbarstat = status.BatteryLifePercent.ToString("P0").TrimEnd('%'); string chargerPlugged = status.PowerLineStatus.ToString(); int pbarCount = Int32.Parse(pbarstat); power = pbarCount; if (chargerPlugged.Equals("Online")) { charger.Invoke(new MethodInvoker(delegate { charger.Text = "SYS is Plugged In"; })); charging = "Y"; } else { charging = "N"; } if (progressBar1.Value != pbarCount) { progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.Value = pbarCount; })); } else { Thread.Sleep(1000); } } }
private static string GetChargeStatus(PowerStatus status) { string chargeStatus = ""; chargeStatus = status.PowerLineStatus.ToString(); return(chargeStatus); }
public void getBattreylevel() { PowerStatus power = SystemInformation.PowerStatus; float battreylevel = power.BatteryLifePercent * 100; TimeSpan ts = TimeSpan.FromSeconds(power.BatteryLifeRemaining); progressBar3.Maximum = 100; progressBar3.Value = (int)battreylevel; if (battreylevel >= 0) { label3.Text = battreylevel.ToString() + "%"; } else { label3.Text = string.Empty; } if (power.PowerLineStatus == PowerLineStatus.Offline) { progressBar3.ForeColor = Color.Red; } else { progressBar3.ForeColor = Color.Green; } if (ts.Seconds > 0) { label4.Text = ts.Hours.ToString() + "h:" + ts.Seconds + "m"; } else { label4.Text = string.Empty; } }
private static string GetBatteryPercent(PowerStatus status) { string batteryPercent = ""; batteryPercent = status.BatteryLifePercent.ToString("P0"); return(batteryPercent); }
public void SendBattaryState() { PowerStatus ps = SystemInformation.PowerStatus; int percent = (int)(ps.BatteryLifePercent * 100); Connect("battery.php?lifepercent=" + percent); }
private bool BatteryIsLow() { PowerStatus p = SystemInformation.PowerStatus; if (p.PowerLineStatus == PowerLineStatus.Offline) { int batterylife = (int)(p.BatteryLifePercent * 100); if (batterylife < 18) // 18 Min. or less left on battery, pause movie { runOnce = true; return(true); } } else if (p.PowerLineStatus == PowerLineStatus.Online) { int batterylife = (int)(p.BatteryLifePercent * 100); if (batterylife == 100 && Fully_Charge == 2) // Skip it twice to ensure it is fully charged { if (PauseMovie()) // If watching a movie pause for 2.5 secs To alert me its ok to unplug { System.Threading.Thread.Sleep(2500); PauseMovie(); } Fully_Charge += 1; } else if (batterylife == 100) { Fully_Charge += 1; } } return(false); }
public ObjBattery(string loadSkin, PowerStatus ps) { //ウインドウファイルパスの取得 string windowPath = LpsPathControllerCus.getBodyDefinePath(loadSkin); //バッテリーステータスを batteryExists = setBatteryExists(ps); Console.WriteLine(ps.BatteryChargeStatus); //body.xmlの存在チェック if (LpsPathControllerCus.checkFileExist(windowPath)) { //2013/08/31 ver3.0.5 ウインドウリソースの互換性チェック compatibilityCheck(loadSkin); //読み込み結果の取得 loadWindowBitmap(loadSkin); //デフォルト設定 getBatteryImage((int)(ps.BatteryLifePercent * 100)); prvBatteryImage = nowBatteryImage; batteryStatusChange = false; } else { //リソース読み込み createDefault(); } }
public void PowerStatus_BatteryChargeStatus_Get_ReturnsExpected() { PowerStatus status = SystemInformation.PowerStatus; // try a valid combination // an edge-case can surface on laptops that are not permanently connected to power // e.g. a charing laptop in a high performance mode would be HIGH | CHARGING Assert.True(EnumIsDefined(status.BatteryChargeStatus)); // try an invalid (as of time of writing) combination Assert.False(EnumIsDefined((BatteryChargeStatus)67)); bool EnumIsDefined(BatteryChargeStatus value) { // BatteryChargeStatus.Unknown == 1111_1111, OR'ing anything with it won't change the result // and thus won't catch invalid combinations, so we need to exclude if from further consideration if (value == BatteryChargeStatus.Unknown) { return(true); } var values = Enum.GetValues(typeof(BatteryChargeStatus)) .OfType <BatteryChargeStatus>() .Where(v => v != BatteryChargeStatus.Unknown) .Aggregate((e1, e2) => (e1 | e2)); return((values & value) == value); } }
// Información de la batería. public void InfoBateria() { PowerStatus status = SystemInformation.PowerStatus; // Obtiene el estado actual de carga de la batería. Alto, Cargando y bajo. this.rtbInfo.Text = status.BatteryChargeStatus.ToString(); // Obtiene el estado actual de energía del sistema. switch (status.PowerLineStatus) { case (PowerLineStatus.Online): this.rtbInfo.Text += "\nComputadora conectada"; break; case (PowerLineStatus.Offline): this.rtbInfo.Text += "\nComputadora no conectada"; break; default: this.rtbInfo.Text += "\nNo hay información al respecto"; break; } // Obtiene la cantidad aproximada de carga de batería completa restante. this.rtbInfo.Text += "\n" + status.BatteryLifePercent.ToString("P0"); // Obtiene el número aproximado de segundos de batería restante. // this.rtbInfo.Text += "\n" + status.BatteryLifeRemaining.ToString(); }
private void timer_Tick(object sender, EventArgs e) { PowerStatus powerStatus = SystemInformation.PowerStatus; batteryPercentage = $"{(powerStatus.BatteryLifePercent * 100)}"; using (Bitmap bitmap = new Bitmap(DrawText(batteryPercentage, new Font(iconFont, iconFontSize), Color.White, Color.Transparent))) { IntPtr intPtr = bitmap.GetHicon(); try { using (Icon icon = Icon.FromHandle(intPtr)) { notifyIcon.Icon = icon; // Offline means the laptop is not connected to a power source if (powerStatus.PowerLineStatus == PowerLineStatus.Offline) { var ts = TimeSpan.FromSeconds(powerStatus.BatteryLifeRemaining); // if you don't want the leading zeros, you can replace the format by '{0}:{1}' notifyIcon.Text = string.Format("{0:00}:{1:00} remaining", ts.Hours, ts.Minutes); } else { notifyIcon.Text = "Charging"; } } } finally { DestroyIcon(intPtr); } } }
private void timer_Tick(object sender, EventArgs e) { PowerStatus powerStatus = SystemInformation.PowerStatus; batteryPercentage = (powerStatus.BatteryLifePercent * 100).ToString(); //using (Bitmap bitmap = new Bitmap(DrawText(batteryPercentage, new Font(iconFont, iconFontSize), Color.White, Color.Black))) if (!(iconFont is Font)) { iconFont = new Font(iconFontName, iconFontSize); } using (Bitmap bitmap = new Bitmap(DrawText(batteryPercentage, iconFont, iconForeColor, iconBackColor))) { IntPtr intPtr = bitmap.GetHicon(); try { using (Icon icon = Icon.FromHandle(intPtr)) { notifyIcon.Icon = icon; notifyIcon.Text = batteryPercentage + "%"; } } finally { DestroyIcon(intPtr); } } }
static async Task Main(string[] args) { PowerStatus powerStatus = SystemInformation.PowerStatus; float batteryLifePercent = powerStatus.BatteryLifePercent * 100; while (true) { batteryLifePercent = powerStatus.BatteryLifePercent * 100; Console.WriteLine("Battery life: " + batteryLifePercent + "%"); if (batteryLifePercent <= 20) { try { await client.GetAsync("http://192.168.1.100"); //payload //var content = new StringContent("greetings from c#", Encoding.UTF8, "application/json"); //await client.PostAsync("http://192.168.1.100", content); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } } System.Threading.Thread.Sleep(5000); // thread sync } }
void UpdateTimer_Tick(object sender, EventArgs e) { BatteryProgress.BackColor = Color.Blue; PowerStatus ps = SystemInformation.PowerStatus; BatteryProgress.Value = (int)(ps.BatteryLifePercent * 100); BatteryLabel.Text = BatteryProgress.Value.ToString(); switch (ps.BatteryChargeStatus) { case BatteryChargeStatus.Charging: BatteryProgress.Style = ProgressBarStyle.Marquee; break; case BatteryChargeStatus.Critical: BatteryProgress.Style = ProgressBarStyle.Blocks; BatteryProgress.ForeColor = Color.FromKnownColor(KnownColor.Red); break; case BatteryChargeStatus.High: BatteryProgress.Style = ProgressBarStyle.Blocks; BatteryProgress.ForeColor = Color.FromKnownColor(KnownColor.Green); break; case BatteryChargeStatus.Low: BatteryProgress.Style = ProgressBarStyle.Blocks; BatteryProgress.ForeColor = Color.FromKnownColor(KnownColor.Yellow); break; case BatteryChargeStatus.NoSystemBattery: break; } }
void changeicontje() { PowerStatus pwr = SystemInformation.PowerStatus; if (pwr.BatteryChargeStatus == BatteryChargeStatus.Charging) { this.Icon = Testproj.Properties.Resources.icons8_Charging_Battery; } else if (battery > 60) { this.Icon = Testproj.Properties.Resources.icons8_Full_Battery; } else if (battery > 36 && battery < 61) { this.Icon = Testproj.Properties.Resources.icons8_Battery_Level; } else if (battery > 11 && battery < 35) { this.Icon = Testproj.Properties.Resources.icons8_Low_Battery; } else if (battery < 11) { this.Icon = Testproj.Properties.Resources.icons8_Empty_Battery; } else { this.Icon = Testproj.Properties.Resources.icons8_No_Battery; } }
private void ShowPowerStatus() { try { PowerStatus status = SystemInformation.PowerStatus; batteryPercent = status.BatteryLifePercent * 100; textBoxChargeStatus.Text = status.BatteryChargeStatus.ToString(); if (status.BatteryFullLifetime == -1) { textBoxFullLifeTime.Text = "Unknown"; } else { textBoxFullLifeTime.Text = status.BatteryFullLifetime.ToString(); } textBoxCharge.Text = status.BatteryLifePercent.ToString("P0"); if (status.BatteryLifeRemaining == -1) { textBoxLifeRemaining.Text = "Unknown"; } else { textBoxLifeRemaining.Text = status.BatteryLifeRemaining.ToString(); } textBoxLineStatus.Text = status.PowerLineStatus.ToString(); } catch (Exception e) { Console.WriteLine(e.InnerException.Message.ToString()); } }
public MoreOptionsDialogResult(Socket socket, PowerStatus status, TimeSpan timeSpan, bool canceled) { Socket = socket; Status = status; TimeSpan = timeSpan; Canceled = canceled; }
private void timer1_Tick(object sender, EventArgs e) { PowerStatus powerStatus = SystemInformation.PowerStatus; if (powerStatus.PowerLineStatus == PowerLineStatus.Online) { label1.Text = "Laptop is on Charge"; label2.Visible = false; label3.Visible = false; //TextWriter tw = new StreamWriter("BatteryTimer.txt"); //// write lines of text to the file //tw.WriteLine("0"); //// close the strea //tw.Close(); label3.Text = "0"; } else { label1.Text = "Laptop is on Battery For"; label2.Visible = true; label3.Visible = true; incrementTime(); if (i == 60000) { min += 1; label3.Text = min.ToString(); notifyIcon1.BalloonTipText = min.ToString(); i = 0; } } }
//Percentage check Method public void Execute() { //Set this value to change maximum permited charge percent int maximumCharge = 95; //To get power related information of current state of laptop PowerStatus powerStatus = SystemInformation.PowerStatus; //Extracting only battery percentage information int BatteryPercentage = (int)(powerStatus.BatteryLifePercent * 100); //To check if laptop is running on battery bool isRunningOnBattery = SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Offline; //Checking if battery percentage has exceded 90% and if laptop is still plugged in if (BatteryPercentage >= maximumCharge && isRunningOnBattery == false) { SoundPlayer player = new SoundPlayer { SoundLocation = AppDomain.CurrentDomain.BaseDirectory + "\\NotificationTone.wav" }; player.Play(); string message = "We observed that your laptop has charged sufficiently,Please unplug the charger."; string title = "Overcharging Alert!"; MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result = MessageBox.Show(message, title, buttons, MessageBoxIcon.Warning); if (result == DialogResult.OK) { player.Stop(); } } }
public void SystemInformation_PowerStatus_Get_ReturnsExpected() { PowerStatus status = SystemInformation.PowerStatus; Assert.NotNull(status); Assert.Same(status, SystemInformation.PowerStatus); }
private void ShowBattery() { PowerStatus status = SystemInformation.PowerStatus; ToolTip tpbattery = new ToolTip(); Color batcolor = Color.ForestGreen; if (status.BatteryChargeStatus != BatteryChargeStatus.NoSystemBattery && status.BatteryChargeStatus != BatteryChargeStatus.Unknown) { float percent = status.BatteryLifePercent; lbl_battery_level.Text = percent.ToString("P0"); if (status.PowerLineStatus == PowerLineStatus.Online) { batcharging = 1; if (percent < 1.0f) { tpbattery.SetToolTip(pb_battery, percent.ToString("P0") + ", Plugged In, Charging"); lbl_battery_status.Text = "Charging"; lbl_battery_power_source.Text = "Plugged In"; } else { tpbattery.SetToolTip(pb_battery, percent.ToString("P0") + ", Plugged In, Battery Full"); lbl_battery_status.Text = "Battery Full"; lbl_battery_power_source.Text = "Plugged In"; } } else { batcharging = 0; if (percent <= 0.07f) { tpbattery.SetToolTip(pb_battery, percent.ToString("P0") + ", Battery Level Critical"); lbl_battery_status.Text = "Critically Low"; lbl_battery_power_source.Text = "On Battery"; batcolor = Color.DarkRed; } else if (percent <= 0.2f) { tpbattery.SetToolTip(pb_battery, percent.ToString("P0") + ", Battery Low, Plug In"); lbl_battery_status.Text = "Battery Low"; lbl_battery_power_source.Text = "On Battery"; batcolor = Color.DarkRed; } else { tpbattery.SetToolTip(pb_battery, percent.ToString("P0") + ", On Battery"); lbl_battery_status.Text = "Discharging"; lbl_battery_power_source.Text = "On Battery"; batcolor = Color.ForestGreen; } } pb_battery.Image = cls_battery.DrawBattery(percent, pb_battery.ClientSize.Width, pb_battery.ClientSize.Height, Color.Transparent, Color.White, Color.White, batteryuncharge, false); pb_battery_panel.Image = cls_battery.DrawBattery2(percent, pb_battery_panel.ClientSize.Width, pb_battery_panel.ClientSize.Height, Color.Transparent, Color.DarkGray, batcolor, Color.Transparent, false); } else { pb_battery.Image = Properties.Resources.No_Battery; tpbattery.SetToolTip(pb_battery, "Battery Not Detected"); } }
public BatteryStatus(ISpeechContext speechContext) : base(speechContext) { m_powerStatus = SystemInformation.PowerStatus; PopulatePowerStatusMap(); BatteryStatusCheckScheduler(); }
private void Form1_Shown(object sender, EventArgs e) { this.Visible = false; this.Hide(); while (true) { String batterystatus; PowerStatus pwr = SystemInformation.PowerStatus; batterystatus = SystemInformation.PowerStatus.BatteryChargeStatus.ToString(); String batterylife; batterylife = SystemInformation.PowerStatus.BatteryLifePercent.ToString(); double bt = double.Parse(batterylife); bt *= 100; if ((bt >= 90 && pwr.PowerLineStatus == PowerLineStatus.Online) || (bt <= 35 && pwr.PowerLineStatus == PowerLineStatus.Offline)) { showNotification(batterystatus, bt); MessageBox.Show($"Battery Status is {batterystatus}, and currently the battery is at {bt}%", "Zaki Battery Warning App", MessageBoxButtons.OK, MessageBoxIcon.Information); } //gets time in minutes sleepWithoutFreezingUI(2); // will sleep Approximately till that time limit } }
public void PowerStatus_BatteryLifePercent_Get_ReturnsExpected() { PowerStatus status = SystemInformation.PowerStatus; float value = status.BatteryLifePercent; Assert.True((value >= 0 && value <= 100) || value == 255); }
public override IBarWidgetPart[] GetParts() { PowerStatus pwr = SystemInformation.PowerStatus; float currentBatteryCharge = pwr.BatteryLifePercent; if (HasBatteryWarning) { if (currentBatteryCharge <= LowChargeThreshold) { return(Parts(Part(currentBatteryCharge.ToString("#0%"), LowChargeColor, fontname: FontName))); } else if (currentBatteryCharge <= MedChargeThreshold) { return(Parts(Part(currentBatteryCharge.ToString("#0%"), MedChargeColor, fontname: FontName))); } else { return(Parts(Part(currentBatteryCharge.ToString("#0%"), HighChargeColor, fontname: FontName))); } } else { return(Parts(Part(currentBatteryCharge.ToString("#0%"), fontname: FontName))); } }
/// <summary> /// Initializes a new instance of the BatteryLife class. /// </summary> public BatteryLife() { brushPercentage = new SolidBrush(Color.LightSlateGray); penBorderColor = new Pen(Color.Black); brushStatusBarColor = new SolidBrush(SystemColors.Highlight); if (!onDesktop) { system_power_status_ex = new PowerStatus(); } #if !DESIGN UpdateBatteryLife(); #else // this.SetStyle(ControlStyles.ResizeRedraw, true); // this.UpdateStyles(); //system_power_status_ex.BatteryLifePercent = 75; #endif }
public static extern void RFStatus(int ComAddr, ref PowerStatus dest);
protected virtual void initObject() { //バッテリーオブジェクト ps = SystemInformation.PowerStatus; //設定ファイルの読み込み os = new ObjSetting(); //スキンファイルの読み込み ossList = new ObjSkinSettingList(); //対象スキンの取得 oss = ossList.loadTargetSkin(os.loadSkin); //ボディリストの初期化 obl = new ObjBodyList(os.loadSkin); //ボディを初期化しておく ob = obl.getLiplisBody(0, 0); //チャットファイルの読み込み olc = new ObjLiplisChat(os.loadSkin); //2014/05/29 ver4.0.0 タッチ定義の追加 olt = new ObjLiplisTouch(os.loadSkin); //ウインドウファイルの初期化 owf = new ObjWindowFile(os.loadSkin); //アイコンクラスの初期化 li = new LiplisIcon(this); //リプリスタスクバー ltb = new LiplisTaskBar(this); //ほうきオブジェクトの初期化 obr = new ObjBroom(); ///2014/04/20 Liplis4.0 総合エモーション追加 //総合エモーション sumEmotion = new MsgEmotion(); //アイコンクラスを連動登録 this.AddOwnedForm(li); }
private void APP_Load(object sender, EventArgs e) { //Traslada el padre IntPtr hprog = NativeMethods.FindWindowEx(FindShellWindow() , IntPtr.Zero, "SysListView32", "FolderView"); NativeMethods.SetWindowLong(this.Handle, GWL_HWNDPARENT, hprog); //Carga los botones LoadButtons(); //Carga el Timer _power = SystemInformation.PowerStatus; _timer = new System.Timers.Timer(); _timer.Enabled = false; //Carga de valores de registro RegistryManager.LoadConfig(this, "SOFTWARE\\PowerPlanChanger"); //Refresca el APP APP_Refresh(); }
private bool setBatteryExists(PowerStatus ps) { switch (ps.BatteryChargeStatus) { case BatteryChargeStatus.High: return true; case BatteryChargeStatus.Low: return true; case BatteryChargeStatus.Critical: return true; case BatteryChargeStatus.Charging: return true; case BatteryChargeStatus.NoSystemBattery: return false; case BatteryChargeStatus.Unknown: return true; default: return true; } }
public BatteryService() { _pStat = SystemInformation.PowerStatus; }
public Main() { InitializeComponent(); LoadCreditials(); if (Properties.Settings.Default.mode == "standard") { mode = Mode.Standard; } else if (Properties.Settings.Default.mode == "expert") { mode = Mode.Expert; } mutex = new Mutex(true, Application.ProductName, out is_single_instance); //Create Mutex if (!is_single_instance) //If second instance of application is running { this.Close(); //Close current application return; } this.Hide(); //Hide window cpu = new PerformanceCounter(); //Create CPU usage counter object ram = new PerformanceCounter(); //Create RAM usage counter object harddisk_read = new PerformanceCounter(); //Create harddisk read usage counter object harddisk_write = new PerformanceCounter(); //Create harddisk write usage couter object network_interface = new PerformanceCounterCategory("Network Interface"); //Create network interface network_instances = network_interface.GetInstanceNames(); //Get all instances from network interface network_download = new PerformanceCounter[network_instances.Length]; //Get number of all network instances (download) server_uptime = new PerformanceCounter(); for (int instance = 0; instance < network_download.Length; instance++) //For all network instances (download) { network_download[instance] = new PerformanceCounter(); //Add network instance (download) to an array } network_upload = new PerformanceCounter[network_instances.Length]; //Get number of all network instances (upload) for (int instance = 0; instance < network_upload.Length; instance++) //For all network instances (upload) { network_upload[instance] = new PerformanceCounter(); //Add network instance (upload) to an array } harddisk_read.CategoryName = "PhysicalDisk"; //Get Harddisk counter category harddisk_read.CounterName = "Disk Read Bytes/sec"; //Get Harddisk counter name harddisk_read.InstanceName = "_Total"; //Get Harddisk counter instance name if (login_showed == false) //If login dialog was not showed { //If values in registry is null or values are default if (server_petname == null || contact_email == null || secret_key == null || server_petname == "server_petname" || contact_email == "*****@*****.**" || secret_key == "secret_key") { Form login = new Settings(); //Create form Login login.ShowDialog(); //Show login } login_showed = true; //Set Login dialog was showed } if(login_showed==true) { timerSender.Start(); //Start timer update } hostname = Dns.GetHostName(); ip_host_entry = Dns.GetHostEntry(hostname); ip_addresses = ip_host_entry.AddressList; startToolStripMenuItemStartStop.Text = "Stop"; startToolStripMenuItemStartStop.Image = Properties.Resources.stop; sending = Sending.Run; updater = Process.GetProcessesByName("Cloudiff updater"); if (updater.Length != 0) { foreach (Process process in updater) { process.Kill(); } } if (Environment.Is64BitOperatingSystem) { operation_system_32_64bit = "64bit"; } else { operation_system_32_64bit = "32bit"; } cpu_cores = Environment.ProcessorCount; RegistryKey cpu_32_64bit_key = Registry.LocalMachine.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); if (cpu_32_64bit_key.GetValue("Identifier").ToString().IndexOf("64") > 0) { cpu_32_64bit = "64bit"; } else { cpu_32_64bit = "32bit"; } cpu_architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"); power = SystemInformation.PowerStatus; power_line_status = power.PowerLineStatus; }
internal static extern bool GetSystemPowerStatusEx2(ref PowerStatus pStatus, int dwLen, [MarshalAs(UnmanagedType.Bool)] bool fUpdate);
private static extern bool GetSystemPowerStatusEx(PowerStatus pStatus, bool fUpdate);
///<summary>User want to see system information</summary> private void ActionSysInfo() { PowerStatus uPS = new PowerStatus(); uPS.Update(); String sText; byte bChargeLevel = uPS.BatteryLifePercent; if (bChargeLevel == PowerStatus.BATTERY_FLAG_UNKNOWN_BYTE) sText = "Charge level: unknown"; else sText = "Charge level: " + bChargeLevel.ToString() + "%"; sText += "\r\nTime: " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"); LogSimpleLine(ActionID.ShowDialog, "Info; SystemInfo"); MessageBox.Show(sText, "System Info", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); }