public CameraDeviceManager(string datafolder=null)
        {
            UseExperimentalDrivers = true;
            StartInNewThread = false;
            SelectedCameraDevice = new NotConnectedCameraDevice();
            ConnectedDevices = new AsyncObservableCollection<ICameraDevice>();
            _deviceEnumerator = new DeviceDescriptorEnumerator();
            LiveViewImage = new Dictionary<ICameraDevice, byte[]>();
            LastCapturedImage = new Dictionary<ICameraDevice, string>();
            WifiDeviceProviders = new List<IWifiDeviceProvider>();

            // prevent program crash in something wrong with wia
            try
            {
                WiaDeviceManager = new DeviceManager();
                WiaDeviceManager.RegisterEvent(Conts.wiaEventDeviceConnected, "*");
                WiaDeviceManager.RegisterEvent(Conts.wiaEventDeviceDisconnected, "*");
                WiaDeviceManager.OnEvent += DeviceManager_OnEvent;
            }
            catch (Exception exception)
            {
                Log.Error("Error initialize WIA", exception);
            }
            if (datafolder != null && Directory.Exists(datafolder))
            {
                try
                {
                    var files = Directory.GetFiles(datafolder, "*.xml");
                    foreach (var file in files)
                    {
                        var device = DeviceDescription.Load(file);
                        if (device != null)
                            _deviceDescriptions.Add(device);
                    }
                }
                catch (Exception)
                {
                    Log.Error("Error loading custom data");
                }
            }
        }
        public CameraDeviceManager()
        {
            UseExperimentalDrivers = true;
            SelectedCameraDevice = new NotConnectedCameraDevice();
            ConnectedDevices = new AsyncObservableCollection<ICameraDevice>();
            _deviceEnumerator = new DeviceDescriptorEnumerator();
            LiveViewImage = new Dictionary<ICameraDevice, byte[]>();

            // prevent program crash in something wrong with wia
            try
            {
                WiaDeviceManager = new DeviceManager();
                WiaDeviceManager.RegisterEvent(Conts.wiaEventDeviceConnected, "*");
                WiaDeviceManager.RegisterEvent(Conts.wiaEventDeviceDisconnected, "*");
                WiaDeviceManager.OnEvent += DeviceManager_OnEvent;
            }
            catch (Exception exception)
            {
                Log.Error("Error initialize WIA", exception);
            }
        }
 private void DisconnectCamera(string wiaId)
 {
     DeviceDescriptor descriptor = _deviceEnumerator.GetByWiaId(wiaId);
     if (descriptor != null)
     {
         descriptor.CameraDevice.PhotoCaptured -= cameraDevice_PhotoCaptured;
         descriptor.CameraDevice.CameraDisconnected -= cameraDevice_CameraDisconnected;
         ConnectedDevices.Remove(descriptor.CameraDevice);
         StaticHelper.Instance.SystemMessage = "Camera disconnected :" + descriptor.CameraDevice.DeviceName;
         Log.Debug("===========Camera disconnected==============");
         Log.Debug("Name :" + descriptor.CameraDevice.DeviceName);
         if (SelectedCameraDevice == descriptor.CameraDevice)
         {
             if (ConnectedDevices.Count > 0)
                 SelectedCameraDevice = ConnectedDevices[0];
             else
             {
                 SelectedCameraDevice = new NotConnectedCameraDevice();
             }
         }
         _deviceEnumerator.Remove(descriptor);
         descriptor.CameraDevice.Close();
         var wiaCameraDevice = descriptor.CameraDevice as WiaCameraDevice;
         if (wiaCameraDevice != null)
         {
             OnCameraDisconnected(wiaCameraDevice);
         }
         PortableDeviceCollection.Instance.RefreshDevices();
     }
 }
 public LiveViewViewModel()
 {
     CameraProperty = new CameraProperty();
     CameraDevice = new NotConnectedCameraDevice();
     InitCommands();
 }
 public LiveViewViewModel()
 {
     CameraProperty = new CameraProperty();
     CameraDevice = new NotConnectedCameraDevice();
     InitCommands();
     PreviewBitmapVisible = true;
 }