Example #1
0
 private void StartLiveViewThread()
 {
     try
     {
         _totalframes = 0;
         _framestart  = DateTime.Now;
         bool retry    = false;
         int  retryNum = 0;
         Log.Debug("LiveView: Liveview started");
         do
         {
             try
             {
                 LiveViewManager.StartLiveView(SelectedPortableDevice);
             }
             catch (DeviceException deviceException)
             {
                 Dispatcher.Invoke(new Action(delegate { grid_wait.Visibility = Visibility.Visible; }));
                 if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY ||
                     deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy)
                 {
                     Thread.Sleep(200);
                     if (!IsVisible)
                     {
                         break;
                     }
                     Log.Debug("Retry live view :" + deviceException.ErrorCode.ToString("X"));
                     retry = true;
                     retryNum++;
                 }
                 else
                 {
                     throw;
                 }
             }
         } while (retry && retryNum < 35);
         if (IsVisible)
         {
             _timer.Start();
             oper_in_progress = false;
             _retries         = 0;
             Log.Debug("LiveView: Liveview start done");
         }
     }
     catch (Exception exception)
     {
         Log.Error("Unable to start liveview !", exception);
         StaticHelper.Instance.SystemMessage = "Unable to start liveview ! " + exception.Message;
         //MessageBox.Show("Unable to start liveview !");
         //ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.LiveViewWnd_Hide);
     }
     Dispatcher.BeginInvoke(new Action(delegate { grid_wait.Visibility = Visibility.Hidden; }));
     Dispatcher.BeginInvoke(new Action(delegate { image1.Visibility = Visibility.Visible; }));
 }
Example #2
0
 private void StartLiveViewThread()
 {
     try
     {
         bool retry    = false;
         int  retryNum = 0;
         Log.Debug("LiveView: Liveview started");
         do
         {
             try
             {
                 LiveViewManager.StartLiveView(CameraDevice);
             }
             catch (DeviceException deviceException)
             {
                 if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY ||
                     deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy)
                 {
                     Thread.Sleep(200);
                     if (!IsVisible)
                     {
                         break;
                     }
                     Log.Debug("Retry live view :" + deviceException.ErrorCode.ToString("X"));
                     retry = true;
                     retryNum++;
                 }
                 else
                 {
                     throw;
                 }
             }
         } while (retry && retryNum < 35);
         if (IsVisible)
         {
             _oper_in_progress = false;
             _liveviewtimer.Start();
             Log.Debug("LiveView: Liveview start done");
         }
     }
     catch (Exception exception)
     {
         Log.Error("Unable to start liveview !", exception);
         StaticHelper.Instance.SystemMessage = "Unable to start liveview ! " + exception.Message;
         //MessageBox.Show("Unable to start liveview !");
         //ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.LiveViewWnd_Hide);
     }
 }
Example #3
0
 private void StopLiveViewThread()
 {
     try
     {
         _totalframes = 0;
         _framestart  = DateTime.Now;
         bool retry    = false;
         int  retryNum = 0;
         Log.Debug("LiveView: Liveview stopping");
         do
         {
             try
             {
                 LiveViewManager.StopLiveView(SelectedPortableDevice);
             }
             catch (DeviceException deviceException)
             {
                 Dispatcher.Invoke(new Action(delegate { grid_wait.Visibility = Visibility.Visible; }));
                 if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY ||
                     deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy)
                 {
                     Thread.Sleep(500);
                     Log.Debug("Retry live view stop:" + deviceException.ErrorCode.ToString("X"));
                     retry = true;
                     retryNum++;
                 }
                 else
                 {
                     throw;
                 }
             }
         } while (retry && retryNum < 35);
     }
     catch (Exception exception)
     {
         Log.Error("Unable to stop liveview !", exception);
         StaticHelper.Instance.SystemMessage = "Unable to stop liveview ! " + exception.Message;
     }
     Dispatcher.Invoke(new Action(delegate { grid_wait.Visibility = Visibility.Hidden; }));
     Dispatcher.Invoke(new Action(delegate { image1.Visibility = Visibility.Hidden; }));
 }
Example #4
0
 void _liveviewtimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (_oper_in_progress)
     {
         return;
     }
     _oper_in_progress = true;
     try
     {
         if (!Freeze)
         {
             LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice);
         }
         Dispatcher.Invoke(new Action(DisplayLiveView));
     }
     catch (Exception exception)
     {
         Log.Debug("Error get live view data *Astro ", exception);
     }
     _oper_in_progress = false;
 }
Example #5
0
 private void StopLiveViewThread()
 {
     try
     {
         bool retry    = false;
         int  retryNum = 0;
         Log.Debug("LiveView: Liveview stopping");
         do
         {
             try
             {
                 LiveViewManager.StopLiveView(CameraDevice);
             }
             catch (DeviceException deviceException)
             {
                 if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY ||
                     deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy)
                 {
                     Thread.Sleep(500);
                     Log.Debug("Retry live view stop:" + deviceException.ErrorCode.ToString("X"));
                     retry = true;
                     retryNum++;
                 }
                 else
                 {
                     throw;
                 }
             }
         } while (retry && retryNum < 35);
     }
     catch (Exception exception)
     {
         Log.Error("Unable to stop liveview !", exception);
         StaticHelper.Instance.SystemMessage = "Unable to stop liveview ! " + exception.Message;
     }
 }
Example #6
0
        private void GetLiveImage()
        {
            if (oper_in_progress)
            {
                return;
            }
            oper_in_progress = true;
            _totalframes++;
            try
            {
                LiveViewData = LiveViewManager.GetLiveViewImage(SelectedPortableDevice);
            }
            catch (Exception)
            {
                _retries++;
                oper_in_progress = false;
                return;
            }

            if (LiveViewData == null || LiveViewData.ImageData == null)
            {
                _retries++;
                oper_in_progress = false;
                return;
            }

            Dispatcher.Invoke(new Action(delegate
            {
                try
                {
                    WriteableBitmap preview;
                    if (LiveViewData != null && LiveViewData.ImageData != null)
                    {
                        MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                                                               LiveViewData.ImagePosition,
                                                               LiveViewData.ImageData.Length -
                                                               LiveViewData.ImagePosition);

                        using (var bmp = new Bitmap(stream))
                        {
                            preview =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(bmp));

                            Bitmap newbmp = bmp;

                            WriteableBitmap writeableBitmap;

                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(newbmp));

                            //DrawGrid(writeableBitmap);
                            writeableBitmap.Freeze();
                            image1.BeginInit();
                            image1.Source = writeableBitmap;
                            image1.EndInit();
                        }
                        stream.Close();
                    }
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                    _retries++;
                    oper_in_progress = false;
                }
            }));
            _retries         = 0;
            oper_in_progress = false;
        }