Example #1
0
        // GET: api/Action
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "value1", "value2" };
        //}

        // GET: api/Action/5
        //public string Get(int actionId)
        //{
        //    return "value" + actionId.ToString();
        //}

        // POST: api/Action
        public IHttpActionResult Post([FromBody] MicrowaveAction value)
        {
            if (value == null)
            {
                return(BadRequest("Item cannot be null"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var mw = new Microwave();
            var en = (MicrowaveActions)Enum.Parse(typeof(MicrowaveActions), value.ActionName);

            switch (en)
            {
            case MicrowaveActions.OpenTheDoor:
                mw.OpenTheDoor();
                break;

            case MicrowaveActions.PressTheButton:
                mw.PressTheButton();
                break;

            case MicrowaveActions.CloseTheDoor:
                mw.CloseTheDoor();
                break;

            default:
                break;
            }

            //switch (value.ActionName)
            //{
            //    case "OpenTheDoor":
            //        mw.OpenTheDoor();
            //        break;
            //    case "PressTheButton":
            //        mw.PressTheButton();
            //        break;
            //    case "CloseTheDoor":
            //        mw.CloseTheDoor();
            //        break;
            //    default:
            //        break;
            //}

            return(Ok(mw));
        }
Example #2
0
        static void Main(string[] args)
        {
            var lg = new ConsoleLogger();
            var mw = new Microwave(lg);
            var sb = new StringBuilder();

            while (true)
            {
                if (mw is IStateReporter)
                {
                    mw.ReportTheState();
                }

                sb.AppendLine("Possible actions: ");
                sb.AppendLine("1. Open the door");
                sb.AppendLine("2. Close the door");
                sb.AppendLine("3. Press the button");
                sb.AppendLine("Choose one and press the key!");
                sb.AppendLine();

                lg.WriteToLog(sb.ToString());
                sb.Clear();

                switch (System.Console.ReadKey().KeyChar)
                {
                case '1':
                    mw.OpenTheDoor();
                    break;

                case '2':
                    mw.CloseTheDoor();
                    break;

                case '3':
                    mw.PressTheButton();
                    break;

                default:
                    break;
                }
            }
        }