Exemple #1
0
        public override CollectedData OnAcquire()
        {
            DictionaryData d = null;

            OnAcquireDelegate(
                dict =>
            {
                d = new DictionaryData(Context);

                string battery_status_str             = dict["BatteryStatus"].ToString();
                int battery_status                    = int.Parse(battery_status_str);
                EUPSBatteryStatus eups_battery_status = (EUPSBatteryStatus)battery_status;

                d.Data["BatteryStatusInt"]         = battery_status_str;
                d.Data["BatteryStatus"]            = eups_battery_status.GetDescription();
                d.Data["EstimatedChargeRemaining"] = dict["EstimatedChargeRemaining"].ToString();

                // https://superuser.com/questions/618589/win32-battery-estimatedruntime
                string estimated_run_time_str = dict["EstimatedRunTime"].ToString();
                if (estimated_run_time_str == "71582788")
                {
                    estimated_run_time_str = "Charging";
                }
                d.Data["EstimatedRunTime"] = estimated_run_time_str;

                d.Data["Name"]   = dict["Name"].ToString();
                d.Data["Status"] = dict["Status"].ToString();
            });

            return(new CollectedData(Context, d != null, d));
        }
Exemple #2
0
        public void HandleBatteryStatusesProperly()
        {
            EUPSBatteryStatus battery_status = EUPSBatteryStatus.Charging;
            UPSStatus         ups_status     = new UPSStatus();

            EStatusType status = ups_status.GetStatus(battery_status);

            Assert.Equal(EStatusType.UPSNotProvidingPower, status);

            battery_status = EUPSBatteryStatus.Other;
            status         = ups_status.GetStatus(battery_status);
            Assert.Equal(EStatusType.UPSProvidingPower, status);
        }
Exemple #3
0
        public void Interpret(Data d, SQLiteConnection conn)
        {
            if (d.Type != ECollectorType.UPS)
            {
                return;
            }

            if (d is DictionaryData)
            {
                long device_id = GetDeviceID(d, conn);
                if (device_id < 0)
                {
                    return;
                }

                DictionaryData dict = d as DictionaryData;

                int?battery_status = null;
                if (dict.Data.ContainsKey("BatteryStatusInt"))
                {
                    string battery_status_str = dict.Data["BatteryStatusInt"];
                    if (int.TryParse(battery_status_str, out int i))
                    {
                        battery_status = i;
                    }
                }
                else if (dict.Data.ContainsKey("BatteryStatus"))
                {
                    string status       = dict.Data["BatteryStatus"];
                    string other_status = EUPSBatteryStatus.Other.GetDescription();
                    battery_status = (string.Compare(status, other_status, true) == 0) ? (int)EUPSBatteryStatus.Other : (int)EUPSBatteryStatus.Undefined;
                }

                if (battery_status.HasValue)
                {
                    EUPSBatteryStatus status     = (EUPSBatteryStatus)battery_status.Value;
                    UPSStatus         ups_status = new UPSStatus();

                    SetDeviceStatus(device_id, ups_status.GetStatus(status), UPSStatus.Types, status.GetDescription(), conn);
                }
            }
            else
            {
                throw new Exception("UPSInterpreter: data type is wrong");
            }
        }