/// <summary>
        /// Send signal to the browser to current real time elevator movement
        /// </summary>
        /// <param name="elevator"></param>
        private void SendSignalToElevator(Domain.Entities.Elevator elevator)
        {
            var context     = GlobalHost.ConnectionManager.GetHubContext <ElevatorHub>();
            var elevatorStr = JsonConvert.SerializeObject(elevator);

            context.Clients.All.addMessage(elevatorStr);
        }
 /// <summary>
 /// Stop elevator in the destination
 /// </summary>
 /// <param name="elevator"></param>
 /// <param name="floor"></param>
 private void StayIdle(Domain.Entities.Elevator elevator, Floor floor)
 {
     elevator.Direction   = Direction.Idle;
     elevator.TotalPeople = 0;
     _elevatorRepository.Update(elevator);
     SendSignalToElevator(elevator);
 }
 /// <summary>
 /// Private method that will descend elevator to the destination
 /// </summary>
 /// <param name="elevator"></param>
 /// <param name="floor"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 private void Descend(Domain.Entities.Elevator elevator, Floor floor, Int16 from, Int16 to)
 {
     elevator.Direction = Direction.Down;
     for (var i = from - 1; i >= to; i--)
     {
         elevator.CurrentFloor = (short)i;
         _elevatorRepository.Update(elevator);
         SendSignalToElevator(elevator);
         Wait();
     }
 }
示例#4
0
        /// <summary>
        /// Update current Elevator to db
        /// </summary>
        /// <param name="elevator"></param>
        /// <returns></returns>
        public bool Update(Domain.Entities.Elevator elevator)
        {
            using (var context = new ElevatorContext())
            {
                context.Elevators.Attach(elevator);

                var entry = context.Entry(elevator);
                entry.State = EntityState.Modified;
                context.SaveChanges();

                return(true);
            }
        }
 /// <summary>
 /// Private method to move elevator to the requested floor
 /// </summary>
 /// <param name="elevator"></param>
 /// <param name="floor"></param>
 private void GoToCurrentFloor(Domain.Entities.Elevator elevator, Floor floor)
 {
     if (elevator.CurrentFloor < floor.CurrentFloor)
     {
         //if elevator is down, then go up to destination floor
         Ascend(elevator, floor, elevator.CurrentFloor, floor.CurrentFloor);
     }
     else
     {
         //if elevator is up, then go down to destination floor
         Descend(elevator, floor, elevator.CurrentFloor, floor.CurrentFloor);
     }
 }
示例#6
0
        /// <summary>
        /// Update current Elevator to db
        /// </summary>
        /// <param name="elevator"></param>
        /// <returns></returns>
        public bool Update(Domain.Entities.Elevator elevator)
        {
            using (var context = new ElevatorContext())
            {
                context.Elevators.Attach(elevator);

                var entry = context.Entry(elevator);
                entry.State = EntityState.Modified;
                context.SaveChanges();

                //log call
                _loggingService.Info("Elevator.Infrastructure.Data.Repositories: ElevatorRepository.Update");
                return(true);
            }
        }
 /// <summary>
 /// Pick People from the floor
 /// </summary>
 /// <param name="elevator"></param>
 /// <param name="floor"></param>
 private void PickPeople(Domain.Entities.Elevator elevator, Floor floor)
 {
     elevator.TotalPeople += floor.TotalPeople;
     _elevatorRepository.Update(elevator);
 }