Esempio n. 1
0
        // ---------------------------------------------
        // DOOR OPEN

        // door openning animation

        private void OpenDoor_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker doorWorker = (BackgroundWorker)sender;

            // get parameter
            double targetFloorY = (double)e.Argument;


            // calculate time delay to 1 pixel paint
            // result will be a little slower
            int delayMilliseconds = (int)(_doorsOpeningTime / DOOR_WIDTH * 1000 * 0.97);

            //MessageBox.Show(delayMilliseconds.ToString());

            for (double x = DOOR_WIDTH; x >= 0; x--)
            {
                doorWorker.ReportProgress(0, x);                  // animate door openning

                System.Threading.Thread.Sleep(delayMilliseconds); // time delay
            }

            _doorState = DoorStateEnum.DOORS_OPENED; // set door state = opened

            e.Result = targetFloorY;
        }
Esempio n. 2
0
 public void DoorChangedEventHandledCorrectly(DoorStateEnum doorStateIn, string expectedS)
 {
     _door.DoorChangedEvent += Raise.EventWith(new DoorEventArg {
         DoorState = doorStateIn
     });
     _display.Received(1).DisplayString(expectedS);
 }
Esempio n. 3
0
        // ---------------------------------------------
        // DOOR CLOSE

        // door closing animation
        private void CloseDoor_DoWork(object sender, DoWorkEventArgs e)
        {
            _liftProcessing = true;

            BackgroundWorker doorWorker = (BackgroundWorker)sender;

            // get parameter
            /// double targetFloorY = (double)e.Argument;
            double targetFloorY = _liftCallsList[0].floorPositionY;

            // calculate time delay to 1 pixel paint
            // result will be a little slower
            int delayMilliseconds = (int)(_doorsClosingTime / DOOR_WIDTH * 1000 * 0.96d);

            //MessageBox.Show(delayMilliseconds.ToString());

            for (double x = 0; x <= DOOR_WIDTH; x++)
            {
                doorWorker.ReportProgress(0, x);                  // animate door closing

                System.Threading.Thread.Sleep(delayMilliseconds); // time delay
            }

            _doorState = DoorStateEnum.DOORS_CLOSED;// set door state = closed

            // set data to "CloseDoor_RunWorkerCompleted" method
            /// e.Result = targetFloorY;
            e.Result = _liftCallsList[0].floorPositionY;
        }
 private void OnDoorStateChange(DoorStateEnum DoorStateIn)
 {
     DoorChangedEvent?.Invoke(this, new DoorEventArg()
     {
         DoorState = DoorStateIn
     });
 }
Esempio n. 5
0
 private void DoorStateChangedHandler(DoorStateEnum doorstate)
 {
     if (doorstate == DoorStateEnum.Open)
     {
         _display.DisplayString("Tilslut telefon");
     }
     else
     {
         _display.DisplayString("Indlæs RFID");
     }
 }
Esempio n. 6
0
        private void Init()
        {
            // set schema canvas height
            showLift.Height = _floorsTotal * FLOOR_HEIGHT;

            //TranslateTransformY = _floorsTotal * FLOOR_HEIGHT;
            //OnPropertyChanged("TranslateTransformY");
            //TranslateTransform translateTransform = new TranslateTransform(0, 300);
            //ScaleTransform scaleTransform = new ScaleTransform(0, -1);

            //this.showLift.RenderTransform = scaleTransform;
            //this.showLift.RenderTransform = translateTransform;

            // ObservableCollection<FloorCallItem> FloorCallButtonsList


            // --------------------------------------------------
            // create floor buttons
            for (int i = _floorsTotal - 1; i >= 0; i--)
            {
                // create element
                FloorCallItem floorCallItem = new FloorCallItem
                {
                    floorNumber = i + 1
                };


                if (i == (_floorsTotal - 1)) // top floor
                {
                    floorCallItem.buttonUpVisibility = System.Windows.Visibility.Hidden;
                }
                else if (i == 0) // first floor
                {
                    floorCallItem.buttonDownVisibility = System.Windows.Visibility.Hidden;
                }
                else // other floors
                {
                    floorCallItem.buttonUpVisibility   = System.Windows.Visibility.Visible;
                    floorCallItem.buttonDownVisibility = System.Windows.Visibility.Visible;
                }

                FloorCallButtonsList.Add(floorCallItem);
            }


            // --------------------------------------------------
            // create inner lift control panel

            for (int i = (_floorsTotal - 1); i >= 0; i--)
            {
                // create element
                LiftInnerCallItem liftInnerCallItem = new LiftInnerCallItem
                {
                    targetFloor = i + 1
                };

                LiftControlButtonsList.Add(liftInnerCallItem);
            }


            // --------------------------------------------------

            // set default lift state
            /// _liftState = LiftStateEnum.STOPPED;
            _liftState = LiftStateEnum.MOVE_UP; // TEST !!

            _doorState = DoorStateEnum.DOORS_OPENED;

            /// _liftPositionY = (_floorsTotal) * FLOOR_HEIGHT - LIFT_HEIGHT - 1; // lift on the 1 floor
            /// _liftPositionY = (_floorsTotal - 2 + 1) * FLOOR_HEIGHT - LIFT_HEIGHT - 1; // lift on the 2 floor

            CurrentLiftFloor = 2;                                                                           // lift on the FIRST floor !!

            _currentLiftPositionY = (_floorsTotal - CurrentLiftFloor + 1) * FLOOR_HEIGHT - LIFT_HEIGHT - 1; // lift on the 1 floor !!

            // (_floorsTotal - CurrentLiftFloor + 1) = (_currentLiftPositionY + LIFT_HEIGHT + 1) / FLOOR_HEIGHT
            // CurrentLiftFloor = _floorsTotal + 1 - (_currentLiftPositionY + LIFT_HEIGHT + 1) / FLOOR_HEIGHT

            //MessageBox.Show("_liftPositionY = " + _liftPositionY.ToString()); // 1919


            // ---------------------------------------------
            // LIFT backgroundWorker


            _backgroundWorkerLift = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };

            // Lift backgroundWorker events
            //For the performing operation in the background
            _backgroundWorkerLift.DoWork += Lift_DoWork;

            //For the display of operation progress to UI
            _backgroundWorkerLift.ProgressChanged += Lift_ProgressChanged;

            //After the completation of operation
            _backgroundWorkerLift.RunWorkerCompleted += Lift_RunWorkerCompleted;
            // DOOR CLOSE backgroundWorker

            _backgroundWorkerCloseDoor = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = false
            };


            // ---------------------------------------------
            // DOOR CLOSE backgroundWorker

            //For the performing operation in the background
            _backgroundWorkerCloseDoor.DoWork += CloseDoor_DoWork;

            //For the display of operation progress to UI
            _backgroundWorkerCloseDoor.ProgressChanged += CloseDoor_ProgressChanged;

            //After the completation of operation
            _backgroundWorkerCloseDoor.RunWorkerCompleted += CloseDoor_RunWorkerCompleted;


            // ---------------------------------------------
            // DOOR OPEN backgroundWorker

            _backgroundWorkerOpenDoor = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = false
            };

            //For the performing operation in the background
            _backgroundWorkerOpenDoor.DoWork += OpenDoor_DoWork;

            //For the display of operation progress to UI
            _backgroundWorkerOpenDoor.ProgressChanged += OpenDoor_ProgressChanged;

            //After the completation of operation
            _backgroundWorkerOpenDoor.RunWorkerCompleted += OpenDoor_RunWorkerCompleted;


            // ---------------------------------------------
            // DOOR OPENED WAIT backgroundWorker

            _backgroundWorkerDoorWaitOpened = new BackgroundWorker
            {
                WorkerReportsProgress      = false,
                WorkerSupportsCancellation = true
            };

            //For the performing operation in the background
            _backgroundWorkerDoorWaitOpened.DoWork += DoorWaitOpened_DoWork;

            //For the display of operation progress to UI
            /// _backgroundWorkerDoorWaitOpened.ProgressChanged += DoorWaitOpened_ProgressChanged;

            //After the completation of operation
            _backgroundWorkerDoorWaitOpened.RunWorkerCompleted += DoorWaitOpened_RunWorkerCompleted;


            // ---------------------------------------------
            // PAINT LIFT SCHEMA


            for (int i = _floorsTotal; i > 0; i--)
            {
                // --------------------------------------------------
                // create floor horizontal line
                Line floorLine = new Line()
                {
                    Stroke          = System.Windows.Media.Brushes.Black,
                    StrokeThickness = _floorLineStrokeThickness,
                    X1 = 0,
                    Y1 = i * FLOOR_HEIGHT - _floorLineStrokeThickness,
                    X2 = 300,
                    Y2 = i * FLOOR_HEIGHT - _floorLineStrokeThickness,
                    HorizontalAlignment = HorizontalAlignment.Center
                };

                /// myLine.VerticalAlignment = VerticalAlignment.Center;

                // add to parent control
                this.showLift.Children.Add(floorLine);


                // --------------------------------------------------
                // create TextBlock for display floor number
                TextBlock floorNumberTextBlock = new TextBlock
                {
                    Text     = (_floorsTotal - i + 1).ToString() + " этаж",
                    Width    = 100,
                    Height   = 50,
                    FontSize = 20
                               //BorderThickness = new Thickness(1),
                               //BorderBrush = new SolidColorBrush(Color.FromRgb(5, 5, 5)),
                               //Margin = new Thickness(20, 20, 0, 0)
                };

                // add to parent control
                this.showLift.Children.Add(floorNumberTextBlock);

                // set TextBlock position
                Canvas.SetLeft(floorNumberTextBlock, 100);                                // X-position
                Canvas.SetTop(floorNumberTextBlock, i * FLOOR_HEIGHT - FLOOR_HEIGHT / 2); // Y-position
            }


            //TranslateTransform translateTransform = new TranslateTransform(0, 300);
            //ScaleTransform scaleTransform = new ScaleTransform(0, -1);

            //this.showLift.RenderTransform = scaleTransform;
            //this.showLift.RenderTransform = translateTransform;


            // --------------------------------------------------
            // paint LIFT

            _liftRect = new Rectangle
            {
                Stroke          = Brushes.Blue,
                StrokeThickness = 1,
                Width           = LIFT_WIDTH,
                Height          = LIFT_HEIGHT,
                Fill            = new SolidColorBrush(Colors.White)
            };

            // set lift position
            Canvas.SetLeft(_liftRect, 20);                   // X
            Canvas.SetTop(_liftRect, _currentLiftPositionY); // Y

            // add to parent control
            this.showLift.Children.Add(_liftRect);


            // --------------------------------------------------
            // paint lift's DOOR

            _leftDoorRect = new Rectangle
            {
                Stroke          = Brushes.Blue,
                StrokeThickness = 2,
                Fill            = new SolidColorBrush(Colors.Blue),
                Width           = 0, // LIFT_WIDTH
                Height          = LIFT_HEIGHT
            };

            // set door position
            Canvas.SetLeft(_leftDoorRect, 20);
            Canvas.SetTop(_leftDoorRect, _currentLiftPositionY);

            // add to parent control
            this.showLift.Children.Add(_leftDoorRect);

            // scroll ListView to bottom
            floorListView.SelectedItem = floorListView.Items[floorListView.Items.Count - 1];
            floorListView.ScrollIntoView(floorListView.SelectedItem);

            floorsScrollViewer.ScrollToBottom();
        }
 public void DoorStateIsStoredInArg(DoorStateEnum state)
 {
     _uut.SimulateDoorChange(state);
     Assert.That(state, Is.EqualTo(_reciecedDoorArg.DoorState));
 }
 public void SimulateDoorChange(DoorStateEnum DoorState)
 {
     OnDoorStateChange(DoorState);
 }