Example #1
0
        void UpdateDeviceList()
        {
            try
            {
                if (IsDeveloperMode)
                {
                    CameraList = new List <string>(new string[] { "10.1 TPC(vid_064e&pid_998d)", "PC Camera(vid_058f&pid_3841)" });
                }
                else
                {
                    CameraList = HotTabCamera.GetListCamera();
                }
                // 將抓到的Camera做升序排列
                // [WAY 1] LINQ
                // IEnumerable<string> sortAscendingQuery = from camera in CameraList
                //                                          orderby camera //"ascending" is default
                //                                          select camera;
                // CameraList = sortAscendingQuery.ToList();

                // [WAY 2] List<T>.Sort 方法()
                // CameraList.Sort();

                // 常見的三種Camera的升序排列結果:
                // 10.1 TPC(vid_064e & pid_998d)
                // IZONE UVC 5M Camera(vid_2081 & pid_270d)
                // PC Camera(vid_058f&pid_3841)

                comboBoxCameraDevices.Items.Clear();

                if (CameraList.Count > 0) // if (m_devicename != null)
                {
                    for (int i = 0; i < CameraList.Count; i++)
                    {
                        // DAP7會出現一個未知的VDP Source()裝置, 選擇後按下Snap會crash
                        // ID82會出現一個未知的Virtual Viscomsoft Screen Capture
                        if (!CameraList[i].Contains("VDP") && !CameraList[i].Contains("Virtual"))
                        {
                            iCameraAmount++;
                            comboBoxCameraDevices.Items.Add(CameraList[i]);
                            if (IsDebugMode)
                            {
                                Trace.WriteLine("Index : " + i + " , Camara Name : " + CameraList[i]);
                            }
                        }
                    }

                    // comboBoxCameraDevices.Sorted = true;

                    if (IsDebugMode)
                    {
                        Trace.WriteLine("Total Camara : " + CameraList.Count + "(" + CameraAmount + ")");
                    }
                    if (CameraAmount.Equals(CameraList.Count))
                    {
                        comboBoxCameraDevices.SelectedIndex = TestCamera;
                        comboBoxCameraDevices.Enabled       = false;
                    }
                    else
                    {
                        MessageBox.Show("Front Camera or Rear Camera is blocked.\r\nPlease check module or config file.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        checkTestStatus("Front Camera or Rear Camera is blocked.");
                    }
                }
                else
                {
                    iCameraAmount = 0;
                    if (comboBoxCameraDevices.InvokeRequired)
                    {
                        comboBoxCameraDevices.Invoke(new Action(() => { comboBoxCameraDevices.Items.Add("Device Not Found"); }));
                    }
                    else
                    {
                        comboBoxCameraDevices.Items.Add("Device Not Found");
                    }
                    comboBoxCameraDevices.SelectedIndex = 0;
                    comboBoxCameraDevices.Enabled       = false;
                }
            }
            catch (Exception ex)
            {
                ExceptionEvent(ex);
            }
        }