public ActionResult Demo(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Redirect("home"));
            }

            var s = new Models.DeviceStatus();

            for (int i = 0; i < 4; i++)
            {
                s.Add("LED" + i, 0);
            }

            _selected = new DEV {
                Id = id, Status = s
            };
            _selected.Changed += (d, v) => {
                Publish(v);
            };
            MqttController.Connected += br => {
                Subcribe();
            };
            Engine.CreateThread(MqttController.Connect);

            return(View(_selected));
        }
示例#2
0
        public void Run()
        {
            Console.WriteLine("\nEnter the command: ");
            string command = Console.ReadLine();

            if (Validation.Validation.Validations(command))
            {
                Console.WriteLine($"Command {command} is valid.");

                if (command.ToLower() == "add")
                {
                    Console.WriteLine("\nRole: ");
                    string role = Console.ReadLine();

                    bool roleVal = Validation.Validation.ValidationRole(role);
                    if (roleVal == false)
                    {
                        string enterRoleAgain;
                        do
                        {
                            Console.WriteLine("Role is invalid.");
                            Console.WriteLine("Enter a role again. ");
                            enterRoleAgain = Console.ReadLine();
                        } while (enterRoleAgain != "dev" && enterRoleAgain != "ceo" && enterRoleAgain != "pm" && enterRoleAgain != "dsnr" && enterRoleAgain != "st");
                        if (enterRoleAgain == "dev")
                        {
                            DEV dev = new DEV();
                            dev.Role = enterRoleAgain;
                            _devService.Add(dev);
                        }
                        else if (enterRoleAgain == "ceo")
                        {
                            CEO ceo = new CEO();
                            ceo.Role = enterRoleAgain;
                            _ceoService.Add(ceo);
                        }
                        else if (enterRoleAgain == "pm")
                        {
                            PM pm = new PM();
                            pm.Role = enterRoleAgain;
                            _pmService.Add(pm);
                        }
                        else if (enterRoleAgain == "dsnr")
                        {
                            DSNR dsnr = new DSNR();
                            dsnr.Role = enterRoleAgain;
                            _dsnrService.Add(dsnr);
                        }
                        else if (enterRoleAgain == "st")
                        {
                            ST st = new ST();
                            st.Role = enterRoleAgain;
                            _stService.Add(st);
                        }
                    }

                    if (roleVal == true)
                    {
                        Console.WriteLine("Role is valid.");

                        bool roleExists = Validation.Validation.IsRoleExists();
                        if (role.ToLower() == "ceo")
                        {
                            if (roleExists == false)
                            {
                                CEO ceo = new CEO();
                                {
                                    ceo.Role = role;
                                }
                                _ceoService.Add(ceo);
                            }
                            else if (roleExists == true)
                            {
                                Console.WriteLine("Ceo already exists, there can only be one!");
                            }
                        }
                        else if (role.ToLower() == "pm")
                        {
                            if (roleExists == false)
                            {
                                PM pm = new PM();

                                pm.Role = role;

                                _pmService.Add(pm);
                            }
                            else if (roleExists == true)
                            {
                                Console.WriteLine("PM already exists, there can only be one!");
                            }
                        }
                        else if (role.ToLower() == "dev")
                        {
                            Console.WriteLine("\nUsername: "******"Developer with that username already exists. Please enter a new one!");

                                string enterUsernameAgain = Console.ReadLine();

                                DEV dev = new DEV();

                                dev.Role     = role;
                                dev.UserName = enterUsernameAgain;
                                _devService.Add(dev);
                            }
                        }
                        else if (role.ToLower() == "dsnr")
                        {
                            Console.WriteLine("\nUsername: "******"Designer with that username already exists. Please enter a new one!");

                                string enterUsernameAgain = Console.ReadLine();

                                DSNR dsnr = new DSNR();
                                dsnr.Role     = role;
                                dsnr.UserName = enterUsernameAgain;
                                _dsnrService.Add(dsnr);
                            }
                        }
                        else if (role.ToLower() == "st")
                        {
                            Console.WriteLine("Username: "******"Software tester with that username already exists. Please enter a new one!");

                                string enterUsernameAgain = Console.ReadLine();

                                ST st = new ST();

                                st.Role     = role;
                                st.UserName = enterUsernameAgain;

                                _stService.Add(st);
                            }
                        }
                    }
                }
                else if (command.ToLower() == "update")
                {
                    Console.WriteLine("\nRole: ");
                    string role = Console.ReadLine();

                    bool roleVal = Validation.Validation.ValidationRole(role);
                    if (roleVal == false)
                    {
                        string enterRoleAgain;
                        do
                        {
                            Console.WriteLine("Role is invalid.");
                            Console.WriteLine("Enter a role again. ");
                            enterRoleAgain = Console.ReadLine();
                        } while (enterRoleAgain != "dev" && enterRoleAgain != "ceo" && enterRoleAgain != "pm" && enterRoleAgain != "dsnr" && enterRoleAgain != "st");
                        if (enterRoleAgain == "ceo")
                        {
                            CEO ceo = new CEO();
                            ceo.Role = enterRoleAgain;
                            _ceoService.Add(ceo);
                        }
                        if (enterRoleAgain == "dev")
                        {
                            DEV dev = new DEV();
                            dev.Role = enterRoleAgain;
                            _devService.Add(dev);
                        }
                    }

                    if (roleVal == true)
                    {
                        Console.WriteLine("Role is valid.");

                        bool roleExists = Validation.Validation.IsRoleExists();
                        if (role.ToLower() == "ceo")
                        {
                            if (roleExists == false)
                            {
                                CEO ceo = new CEO();
                                {
                                    ceo.Role = role;
                                }
                                _ceoService.Add(ceo);
                            }
                            else if (roleExists == true)
                            {
                                Console.WriteLine("Ceo already exists, there can only be one!");
                            }
                        }
                        if (role.ToLower() == "dev")
                        {
                            DEV dev = new DEV();

                            dev.Role = role;

                            _devService.Update(dev);
                        }
                    }
                }
                else if (command.ToLower() == "display")
                {
                    _ceoService.DisplayAll();
                }
                else if (command.ToLower() == "list")
                {
                    _pmService.DisplayRole();
                    _devService.DisplayRole();
                    _dsnrService.DisplayRole();
                    _stService.DisplayRole();
                }
                else if (command.ToLower() == "remove")
                {
                    _ceoService.Remove();
                }
                else if (command.ToLower() == "help")
                {
                    _ceoService.Help();
                }
                else if (command.ToLower() == "ceolist")
                {
                    _ceoService.DisplayRole();
                }
                else if (command.ToLower() == "devlist")
                {
                    _devService.DisplayRole();
                }
                else if (command.ToLower() == "pmlist")
                {
                    _pmService.DisplayRole();
                }
                else if (command.ToLower() == "dsnrlist")
                {
                    _dsnrService.DisplayRole();
                }
                else if (command.ToLower() == "stlist")
                {
                    _stService.DisplayRole();
                }
            }
            else
            {
                Console.WriteLine("Incorrect command! Try again.");
            }
        }