示例#1
0
        public IActionResult GatewayEthernet(EthernetGatewayViewModel model)
        {
            //prevent start wizard if already passed
            if (!bool.Parse(configuration["FirstRun"]))
            {
                return(View("Error", ALREADY_PASSED_MESSAGE));
            }

            //redirect to first step if user came this url directly
            if (SystemController.dataBaseConfig == null)
            {
                return(RedirectToAction("Index"));
            }

            dynamic json = ReadConfig();

            json.Gateway.EthernetGateway.GatewayIP   = model.Ip;
            json.Gateway.EthernetGateway.GatewayPort = model.Port;
            json.Gateway.SerialGateway.Enable        = false;
            json.Gateway.EthernetGateway.Enable      = true;
            WriteConfig(json);
            configuration.Reload();

            SystemController.DisconnectGateway();
            SystemController.ReadConfig();
            SystemController.ConnectToGateway();

            return(RedirectToAction("UserProfile"));
        }
示例#2
0
        public IActionResult Gateway(string id)
        {
            //prevent start wizard if already passed
            if (!bool.Parse(configuration["FirstRun"]))
            {
                return(View("Error", ALREADY_PASSED_MESSAGE));
            }

            //redirect to first step if user came this url directly
            if (SystemController.dataBaseConfig == null)
            {
                return(RedirectToAction("Index"));
            }

            if (id == "None")
            {
                dynamic json = ReadConfig();
                json.Gateway.SerialGateway.Enable   = false;
                json.Gateway.EthernetGateway.Enable = false;
                WriteConfig(json);
                configuration.Reload();

                SystemController.DisconnectGateway();
                SystemController.ReadConfig();
                SystemController.ConnectToGateway();

                return(RedirectToAction("UserProfile"));
            }
            if (id == "Serial")
            {
                ViewBag.ports = SerialConnectionPort.GetAvailablePorts();

                return(View("GatewaySerial", new SerialGatewayViewModel
                {
                    PortName = configuration["Gateway:SerialGateway:SerialPortName"],
                    Boudrate = Int32.Parse(configuration["Gateway:SerialGateway:Boudrate"])
                }));
            }
            if (id == "Ethernet")
            {
                return(View("GatewayEthernet", new EthernetGatewayViewModel
                {
                    Ip = configuration["Gateway:EthernetGateway:GatewayIP"],
                    Port = Int32.Parse(configuration["Gateway:EthernetGateway:GatewayPort"])
                }));
            }

            return(View());
        }
示例#3
0
        public async Task <bool> ConnectEthernetGateway()
        {
            SystemController.DisconnectGateway();

            dynamic json = ReadConfig();

            json.Gateway.SerialGateway.Enable   = false;
            json.Gateway.EthernetGateway.Enable = true;
            WriteConfig(json);
            configuration.Reload();

            SystemController.gatewayConfig.SerialGateway.Enable   = false;
            SystemController.gatewayConfig.EthernetGateway.Enable = true;

            await Task.Run((() =>
            {
                SystemController.ConnectToGateway();
            }));

            return(true);
        }