// checks if doors are locked
        private bool doorsAreLocked()
        {
            // door manager object is empty ..
            if (_doorManager == null)
            {
                return(true);
            }

            return(_doorManager.LockAllDoors());
        }
Beispiel #2
0
        public bool SetCurrentState(string state)
        {
            string lowerState = state.ToLower();

            if (lowerState != "open" && lowerState != "closed" && lowerState != "fire alarm" && lowerState != "fire drill" && lowerState != "out of hours")
            {
                return(false);
            }

            if (currentState == "open" && lowerState == "closed" || currentState == "closed" && lowerState == "open")
            {
                return(false);
            }

            if (currentState == "fire drill" || currentState == "fire alarm" && lowerState != GetPreviousState())
            {
                return(false);
            }

            if (lowerState == "open")
            {
                doorManager.OpenAllDoors();
                if (doorManager.OpenAllDoors() == false)
                {
                    currentState = currentState;
                }
            }
            if (lowerState == "closed")
            {
                doorManager.LockAllDoors();
                lightManager.SetAllLights(false);
            }
            if (lowerState == "fire alarm")
            {
                fireAlarm.SetAlarm(true);
                doorManager.OpenAllDoors();
                lightManager.SetAllLights(true);

                try
                {
                    webService.LogFireAlarm("fire alarm");
                }
                catch (ArgumentException e)
                {
                    emailService.SendEmail("*****@*****.**", "failed to log alarm", e.Message);
                }
            }
            SetPreviousState(currentState);
            currentState = lowerState;
            return(true);
        }
Beispiel #3
0
        public bool SetCurrentState(string state)
        {
            state = state.ToLower();
            // set the new currentState

            if (state == currentState)
            {
                return(true);
            }
            else
            {
                // to check if the string input is a valid state
                if (state == "closed" || state == "out of hours" || state == "open" || state == "fire drill" || state == "fire alarm")
                {
                    // when in fire alarm or fire drill state
                    if (state == "fire alarm" || state == "fire drill")
                    {
                        previousState = currentState;
                        currentState  = state;
                        fireAlarmManager.SetAlarm(true);
                        doorManager.OpenAllDoors();
                        lightManager.SetAllLights(true);
                        try
                        {
                            webservice.LogFireAlarm("fire alarm");
                        }
                        catch (Exception exception)
                        {
                            emailService.SendMail("*****@*****.**", "failed to log alarm", exception.Message);
                        }
                        return(true);
                    }
                    // After the fire alarm and fire drill state
                    else if (currentState == "fire alarm" || currentState == "fire drill")
                    {
                        //the current state should reset to the previous state
                        currentState = previousState;
                        return(true);
                    }
                    else
                    {
                        // when in open state all doors should open using door manager
                        if (state == "open")
                        {
                            bool wasAbleToOpen = doorManager.OpenAllDoors();
                            if (wasAbleToOpen)
                            {
                                currentState = state;
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        // when in close state all doors should close using door manager
                        else if (state == "closed")
                        {
                            bool wasAbleToClose = doorManager.LockAllDoors();
                            if (wasAbleToClose)
                            {
                                currentState = state;
                                lightManager.SetAllLights(false);
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
        }