private void onAirPreviewCartButton_Click(object sender, RoutedEventArgs e)
 {
     _context = (ManagerContext)DataContext;
     if (_context.PreviewCart.Slides.Count > 0)
     {
         _context.ActiveCart = _context.PreviewCart;
         _context.ReloadPreview();
     }
     else
     {
         // TODO Error
     }
 }
        private void PreviewListBox_KeyDown(object sender, KeyEventArgs e)
        {
            // Remove the last selected Slide from the active Cart
            if (e.Key == Key.Delete)
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Render,
                (SendOrPostCallback)delegate
                {
                    _context = (ManagerContext)DataContext;
                    if (_lastSelectedManagerImageRef != null)
                    {
                        if (_context.PreviewCart.Slides.Contains(_lastSelectedManagerImageRef) && _context.PreviewCart.Slides.Count > 1)
                        {
                            _context.PreviewCart.Slides.Remove(_lastSelectedManagerImageRef);
                            _context.ReloadPreview();
                        }
                    }

                }, null);
            }
        }
        private void editorAddButton_Click(object sender, RoutedEventArgs e)
        {
            // Add the image to the current Active Cart
            Dispatcher.BeginInvoke(DispatcherPriority.Render,
               (SendOrPostCallback)delegate
               {
               _context = (ManagerContext)DataContext;
               _context.PreviewCart.Slides.Add(_context.EditorImage.Clone());
               _context.ReloadPreview();

               }, null);
        }
 private void editorAddButtonAndMain_Click(object sender, RoutedEventArgs e)
 {
     // Add the image to the current Active Cart and set it active
     Dispatcher.BeginInvoke(DispatcherPriority.Render,
        (SendOrPostCallback)delegate
        {
        if (_context.EditorImage != null)
        {
            _context = (ManagerContext)DataContext;
            var newImg = _context.EditorImage.Clone();
            _context.PreviewCart.Slides.Add(newImg);
            _context.ReloadPreview();
            _lastAutomationChange = DateTime.Now;
            _context.SwitchToSlide(newImg);
        }
        }, null);
 }
        private void CartListBox_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2 && e.LeftButton == MouseButtonState.Pressed)
            {
                // Selected other Slide to be pushed !
                Dispatcher.BeginInvoke(DispatcherPriority.Render,
                (SendOrPostCallback)delegate
                {
                    _context = (ManagerContext)DataContext;
                    if (_lastSelectedCart != null)
                    {
                        _context.PreviewCart = _lastSelectedCart;
                        _context.ReloadPreview();
                    }

                }, null);

                e.Handled = true;
            }
        }
 private void cancelPreviewCartButton_Click(object sender, RoutedEventArgs e)
 {
     _context = (ManagerContext)DataContext;
     _context.PreviewCart = _context.ActiveCart;
     _context.ReloadPreview();
 }
        private void AutoProcessing()
        {
            while (_running)
            {
                lock (_synLock)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Render,
                    (SendOrPostCallback)delegate
                    {
                        _context = (ManagerContext)DataContext;

                        // Automation Mode and Slide change
                        if (_context.InAutomationMode)
                        {
                            if (_lastAutomationChange.AddSeconds(_context.AutomationInterval) < DateTime.Now)
                            {
                                // Switch to next slide if in Automation
                                _context.SwitchToNextSlide();
                                _lastAutomationChange = DateTime.Now;
                                _context.AutomationProgress = 1.0;
                            }

                            // Update internal values progresses
                            var millisToNextChange = Math.Max(0, _lastAutomationChange.AddSeconds(_context.AutomationInterval).Subtract(DateTime.Now).TotalMilliseconds);
                            _context.AutomationProgress = (0.0 + millisToNextChange) / (_context.AutomationInterval * 1000);

                            if (_context.IsInOverrideCart)
                            {
                                _context.OverrideProgress = (0.0 + millisToNextChange +
                                                             1000 * _context.OverrideSlideCountDown * _context.AutomationInterval) /
                                                            (_context.OverrideRotationCount *
                                                             _context.ActiveCart.Slides.Count *
                                                             _context.AutomationInterval * 1000);
                            }
                        }
                        else
                        {
                            _context.AutomationProgress = 0.0;
                        }

                        // Override Mode and Back to INITIAL Cart
                        if (_context.IsInOverrideCart && _context.OverrideSlideCountDown == 0)
                        {
                            var initCart = _context.Carts.FirstOrDefault(x => x.Name == "INITIAL");
                            if (initCart != null)
                            {
                                _context.ActiveCart = initCart;
                                _context.IsInOverrideCart = false;
                                _context.ReloadPreview();
                            }
                            _context.OverrideProgress = 0.0;
                        }

                        DataContext = _context;
                    }, null);

                    Monitor.Wait(_synLock, 100);
                }
            }
        }