Пример #1
0
        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);
                }
            }
        }