Пример #1
0
        public static List <PnPDevice> GetPNPDevices()
        {
            List <PnPDevice> result = new List <PnPDevice>();

            ManagementObjectCollection col;

            using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity"))
            {
                col = searcher.Get();
            }

            foreach (var i in col)
            {
                try
                {
                    PnPDevice dev = new PnPDevice()
                    {
                        Name        = (string)i.GetPropertyValue("Description"),
                        PNPDeviceID = (string)i.GetPropertyValue("PNPDeviceID")
                    };

                    result.Add(dev);
                }
                catch (Exception) { }
            }

            col.Dispose();

            return(result);
        }
Пример #2
0
        public bool Equals(PnPDevice x)
        {
            if (x == null)
            {
                return(false);
            }

            return(x.PNPDeviceID == PNPDeviceID);
        }
Пример #3
0
        /// <summary>
        ///     DsHidMini device connected.
        /// </summary>
        /// <param name="obj">The device path.</param>
        private void ListenerOnDeviceArrived(string obj)
        {
            _vm.Devices.Clear();

            var instance = 0;

            while (Devcon.Find(DsHidMiniDriver.DeviceInterfaceGuid, out var path, out var instanceId, instance++))
            {
                _vm.Devices.Add(new DeviceViewModel(PnPDevice.GetDeviceByInstanceId(instanceId)));
            }
        }
Пример #4
0
        private void OnTick(object s)
        {
            try
            {
                if (!busy)
                {
                    busy = true;

                    curTick = PNP.GetPNPDevices();

                    List <PnPDevice> diffs = curTick.Where((i) =>
                    {
                        return(!(lastTick.Contains(i)));
                    }).ToList();

                    foreach (var i in diffs)
                    {
                        if (!newDevices.Contains(i))
                        {
                            newDevices.Add(i);
                        }
                    }

                    this.Dispatcher.Invoke(() =>
                    {
                        PnPDevice selected = sDevices.SelectedItem as PnPDevice;

                        sDevices.ItemsSource = null;
                        sDevices.ItemsSource = newDevices;
                        sDevices.Items.Refresh();

                        if (selected != null)
                        {
                            if (sDevices.Items.Contains(selected))
                            {
                                sDevices.SelectedItem = selected;
                            }
                        }
                    });

                    busy = false;
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to successfully scan for devices", ex);
                tTimer.Dispose();
            }
        }
Пример #5
0
        public WizardDone(PnPDevice device)
        {
            InitializeComponent();

            AirPodsUI.Core.Settings settings = new AirPodsUI.Core.Settings();

            if (settings.AllowIDEditing)
            {
                sID.IsReadOnly = false;
                sID.IsEnabled  = true;
            }

            sID.Text   = device.PNPDeviceID;
            sName.Text = device.Name;
        }
Пример #6
0
        static List <PnPDevice> GetPnPDevices()
        {
            List <PnPDevice> l = new List <PnPDevice>();

            foreach (ManagementObject mo in new ManagementObjectSearcher("Select * from Win32_PnPEntity").Get())
            {
                PnPDevice dev = new PnPDevice();

                dev.Availability            = mo["Availability"] == null ? 0 : (int)(uint)mo["Availability"];
                dev.Caption                 = (string)mo["Caption"];
                dev.ClassGuid               = (string)mo["ClassGuid"];
                dev.CompatibleID            = mo["CompatibleID"] == null ? null : new List <string>((string[])mo["CompatibleID"]);
                dev.ConfigManagerErrorCode  = (int)(uint)mo["ConfigManagerErrorCode"];
                dev.ConfigManagerUserConfig = (bool)mo["ConfigManagerUserConfig"];
                dev.CreationClassName       = (string)mo["CreationClassName"];
                dev.Description             = (string)mo["Description"];
                dev.ErrorCleared            = mo["ErrorCleared"] == null ? (bool?)null : (bool)mo["ErrorCleared"];
                dev.ErrorDescription        = (string)mo["ErrorDescription"];
                dev.HardwareID              = mo["HardwareID"] == null ? null : new List <string>((string[])mo["HardwareID"]);
                dev.InstallDate             = mo["InstallDate"] == null ? (DateTime?)null : ManagementDateTimeConverter.ToDateTime(Convert.ToString(mo["InstallDate"]));
                dev.LastErrorCode           = mo["LastErrorCode"] == null ? (int?)null : (int)mo["LastErrorCode"];
                dev.Manufacturer            = (string)mo["Manufacturer"];
                dev.Name        = (string)mo["Name"];
                dev.PNPDeviceID = (string)mo["PNPDeviceID"];
                dev.Service     = (string)mo["Service"];
                dev.Status      = (string)mo["Status"];
                dev.StatusInfo  = mo["StatusInfo"] == null ? (int?)null : (int)mo["StatusInfo"];
                try //Windows 7 compatibility
                {
                    dev.PNPClass = (string)mo["PNPClass"];
                }
                catch
                {
                    dev.PNPClass = "";
                }
                try
                {
                    dev.Present = (bool)mo["Present"];
                }
                catch
                {
                    dev.Present = true;
                }
                l.Add(dev);
            }

            return(l);
        }
Пример #7
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            PnPDevice dev = obj as PnPDevice;

            if (dev == null)
            {
                return(false);
            }

            return(Equals(dev));
        }
Пример #8
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            var instance = 0;

            while (Devcon.Find(DsHidMiniDriver.DeviceInterfaceGuid, out var path, out var instanceId, instance++))
            {
                _vm.Devices.Add(new DeviceViewModel(PnPDevice.GetDeviceByInstanceId(instanceId)));
            }

            _listener.DeviceArrived += ListenerOnDeviceArrived;
            _listener.DeviceRemoved += ListenerOnDeviceRemoved;

            _listener.StartListen(this);
        }
Пример #9
0
        public static List<PnPDevice> Get_PnPDevices(ManagementScope scope)
        {
            List<PnPDevice> result = new List<PnPDevice>();

            ObjectQuery wmiquery = new ObjectQuery("SELECT * FROM Win32_PnPEntity");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, wmiquery);
            ManagementObjectCollection coll = searcher.Get();
            foreach (ManagementObject queryObj in coll)
            {
                var cp = new PnPDevice();
                if (queryObj["ClassGuid"] != null) cp.ClassGUID = queryObj["ClassGuid"].ToString().Trim(' ');
                if (queryObj["Manufacturer"] != null) cp.Manufacturer = queryObj["Manufacturer"].ToString().Trim(' ');
                if (queryObj["PnPDeviceID"] != null) cp.PnPDeviceID = queryObj["PnPDeviceID"].ToString().Trim(' ');
                if (queryObj["Name"] != null) cp.Name = queryObj["Name"].ToString().Trim(' ');
                if (queryObj["ConfigManagerErrorCode"] != null) cp.ErrorCode = queryObj["ConfigManagerErrorCode"].ToString().Trim(' ');
                result.Add(cp);
            }

            return result;
        }
Пример #10
0
        public RESTStatus ListDevicesData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (string.IsNullOrWhiteSpace(id) == true)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.NotFound);
            }

            lock (ni.sqllock)
            {
                if (Computers.MachineExists(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            LstDevData           = new PnPDeviceList();
            LstDevData.List      = new List <PnPDevice>();
            LstDevData.MachineID = id;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM DevicesConfig WHERE MachineID=@mid", new SQLParam("@mid", id));
                while (dr.Read())
                {
                    PnPDevice n = new PnPDevice();
                    n.Availability            = Convert.ToInt32(dr["Availability"]);
                    n.Caption                 = Convert.ToString(dr["Caption"]);
                    n.ClassGuid               = Convert.ToString(dr["ClassGuid"]);
                    n.ConfigManagerErrorCode  = Convert.ToInt32(dr["ConfigManagerErrorCode"]);
                    n.ConfigManagerUserConfig = Convert.ToBoolean(dr["ConfigManagerUserConfig"]);
                    n.CreationClassName       = Convert.ToString(dr["CreationClassName"]);
                    n.Description             = Convert.ToString(dr["Description"]);
                    n.ErrorCleared            = dr["ErrorCleared"] is DBNull ? (bool?)null : Convert.ToBoolean(dr["ErrorCleared"]);
                    n.ErrorDescription        = Convert.ToString(dr["ErrorDescription"]);
                    n.Index         = Convert.ToInt32(dr["Index"]);
                    n.InstallDate   = dr["InstallDate"] is DBNull ? (DateTime?)null : SQLLib.GetDTUTC(dr["InstallDate"]);
                    n.LastErrorCode = dr["LastErrorCode"] is DBNull ? (int?)null : Convert.ToInt32(dr["LastErrorCode"]);
                    n.Manufacturer  = Convert.ToString(dr["Manufacturer"]);
                    n.Name          = Convert.ToString(dr["Name"]);
                    n.PNPClass      = Convert.ToString(dr["PNPClass"]);
                    n.PNPDeviceID   = Convert.ToString(dr["PNPDeviceID"]);
                    n.Present       = Convert.ToBoolean(dr["Present"]);
                    n.Service       = Convert.ToString(dr["Service"]);
                    n.Status        = Convert.ToString(dr["Status"]);
                    n.StatusInfo    = dr["StatusInfo"] is DBNull ? (int?)null : Convert.ToInt32(dr["StatusInfo"]);
                    n.HardwareID    = JsonConvert.DeserializeObject <List <string> >(Convert.ToString(dr["HardwareID"]));
                    n.CompatibleID  = JsonConvert.DeserializeObject <List <string> >(Convert.ToString(dr["CompatibleID"]));
                    LstDevData.List.Add(n);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Пример #11
0
        public DeviceViewModel(PnPDevice device)
        {
            _device = device;

            _batteryQuery = new Timer(UpdateBatteryStatus, null, 10000, 10000);
        }