public DecidePenaltyWindow(PenaltyContainer penalty, DriverContainer driver)
        {
            InitializeComponent();

            _model = new DecidePenaltyViewModel(penalty, driver);
            this.DataContext = _model;
        }
        public DecidePenaltyViewModel(PenaltyContainer penalty, DriverContainer driver)
        {
            _penalty = penalty;
            _driver = driver;

            _possibleResults = PenaltyResult.AllResults();

            _resetResult = penalty.Penalty.Result;

            if (string.IsNullOrWhiteSpace(penalty.Penalty.Result.PenaltyMessage))
            {
                penalty.Penalty.Result.PenaltyMessage = penalty.Penalty.Reason;
            }

            this.Penalty.Penalty.Result.DriverId = driver.Driver.Id;
            this.Penalty.UpdateDrivers();
        }
        public void AddDriver(DriverContainer driver, PenaltyContainer parentPenalty = null)
        {
            Penalty penalty;
            if (parentPenalty == null)
            {
                penalty = Penalty.Create();
                penalty.Camera = CameraControl.GetCurrentCameraSessionTime();
                penalty.Lap = driver.Driver.Live.Lap.ToString();
                SyncManager.Instance.State.Penalties.Add(penalty);

                // Create incident event
                var @event = new ReplayEvent();
                @event.Type = ReplayEvent.EventTypes.Incident;
                @event.AdminId = SyncManager.Instance.UserId;
                @event.Camera = penalty.Camera;
                //_mainModel.ReplayBarModel.AddEvent(@event);
            }
            else
            {
                penalty = parentPenalty.Penalty;
            }

            penalty.StartInvestigation(driver.Driver.Id, SyncManager.Instance.User);

            if (parentPenalty == null)
            {
                SyncManager.Instance.SendStateUpdate(SyncCommandHelper.AddPenalty(penalty));
                EditPenalty(penalty);
            }
            else
            {
                SyncManager.Instance.SendPenaltyUpdate(penalty);
            }

            this.UpdatePenalties();
        }
        public void DecidePenaltyResult(PenaltyContainer penalty)
        {
            this.SelectedPenalty = null;

            // If already locked then ignore
            if (penalty.Penalty.IsLocked) return;

            // Lock this penalty
            penalty.Penalty.LockUser = SyncManager.Instance.User;
            SyncManager.Instance.SendPenaltyUpdate(penalty.Penalty);

            // Get offending driver
            DriverContainer driver = null;

            if (penalty.Drivers.Count == 1)
            {
                driver = penalty.Drivers[0];
            }
            else if (penalty.Drivers.Count > 1)
            {
                // Select driver from list
                var selectDriverWindow = new SelectUserWindow(penalty.Drivers);
                if (App.Instance.MainModel.ShowDialog(selectDriverWindow).GetValueOrDefault())
                {
                    driver = selectDriverWindow.SelectedDriver;
                }
            }

            if (driver != null)
            {
                var wasUnderInvestigation = penalty.Penalty.IsUnderInvestigation;

                // Decide result window
                var dialog = new DecidePenaltyWindow(penalty, driver);
                App.Instance.MainModel.ShowDialog(dialog);

                if (wasUnderInvestigation && !penalty.Penalty.IsUnderInvestigation && this.Penalties.Contains(penalty))
                {
                    // No longer under investigation
                    this.Penalties.Remove(penalty);
                    this.DecidedPenalties.Add(penalty);
                }
                else if (!wasUnderInvestigation && penalty.Penalty.IsUnderInvestigation && this.DecidedPenalties.Contains(penalty))
                {
                    // Under investigation again
                    this.DecidedPenalties.Remove(penalty);
                    this.Penalties.Add(penalty);
                }
            }

            // Unlock again
            penalty.Penalty.LockUser = null;
            SyncManager.Instance.SendPenaltyUpdate(penalty.Penalty);
        }
        private void UpdatePenalties()
        {
            // Store selected penalty id
            _selectedId = this.SelectedPenalty == null ? null : this.SelectedPenalty.Penalty.Id;

            this.ClearPenalties();

            foreach (var penalty in SyncManager.Instance.State.Penalties.ToList())
            {
                var container = new PenaltyContainer(penalty);
                container.UpdateDrivers();

                container.Penalty.PropertyChanged += OnPenaltyChanged;

                if (penalty.IsUnderInvestigation)
                {
                    this.Penalties.Add(container);
                }
                else
                {
                    this.DecidedPenalties.Add(container);
                }
            }

            // Find selected penalty again
            var selected = this.Penalties.FirstOrDefault(p => p.Penalty.Id == _selectedId);
            this.SelectedPenalty = selected;
        }
 public DroppedDriverEventArgs(DriverContainer driver, PenaltyContainer penalty)
 {
     this.Driver = driver;
     this.Penalty = penalty;
 }
 protected virtual void OnDroppedDriver(DriverContainer driver, PenaltyContainer penalty)
 {
     if (DroppedDriver != null)
     {
         DroppedDriver(this, new DroppedDriverEventArgs(driver, penalty));
     }
 }
        private void DropTarget_PreviewDragOver(object sender, DragEventArgs e)
        {
            object draggedItem = e.Data.GetData(this.format.Name);

            targetPenalty = DecideDropTarget(e);
            if (draggedItem != null)
            {
                ShowDraggedAdorner(e.GetPosition(this.topWindow));
            }
            e.Handled = true;
        }