コード例 #1
0
        //Request configuration from server
        public async static Task requestConfig()
        {
            HavissIoTCommandBuilder commandBuilder = new HavissIoTCommandBuilder();

            //Add user (and password) if available
            if (password.Length > 0 && username.Length > 0)
            {
                commandBuilder.addUser(username, password);
            }
            else if(username.Length > 0)
            {
                commandBuilder.addUser(username);
            }
            //Add request for server configuration
            commandBuilder.getConfig();
            if (SharedVariables.client.isConnected())
            {
                //Store response in string
                string response = await SharedVariables.client.request(commandBuilder.getJsonString());
                //Parses response to an jsonobject
                try
                {
                    JObject jsonObject = JObject.Parse(response);
                    brokerAddress = (string) jsonObject.GetValue("brokerAddress");
                    brokerPort = (int)jsonObject.GetValue("brokerPort");
                    mqttQOS = (int)jsonObject.GetValue("qos");
                }
                catch (Exception ex)
                {
                    //TODO Handle exception
                    Debug.WriteLine(ex.Message);
                }
            }
                        
        }
コード例 #2
0
 public async Task refreshSensors()
 {
     if (SharedVariables.client.isConnected())
     {
         HavissIoTCommandBuilder commandBuilder = new HavissIoTCommandBuilder();
         if (Config.username.Length > 0)
         {
             if (Config.password.Length > 0)
             {
                 commandBuilder.addUser(Config.username, Config.password);
             }
             else
             {
                 commandBuilder.addUser(Config.username);
             }
         }
         commandBuilder.listSensors();
         String response = await SharedVariables.client.request(commandBuilder.getJsonString());
         JObject jsonObject = null;
         JArray jsonArray = null;
         try
         {
             jsonObject = JObject.Parse(response);
             jsonArray = jsonObject.GetValue("r") as JArray;
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex.Message);
             jsonObject = null;
             jsonArray = null;
         }
         if (jsonArray != null)
         {
             foreach (JObject s in jsonArray)
             {
                 try
                 {
                     string sensorName = (string)s.GetValue("name");
                     string sensorTopic = (string)s.GetValue("topic");
                     string sensorType = (string)s.GetValue("type");
                     bool toStore = (bool)s.GetValue("toStore");
                     IoTSensor sensor = new IoTSensor(sensorName, sensorTopic, sensorType, toStore);
                     SharedVariables.sensorHandler.addSensor(sensor);
                 }
                 catch (Exception ex)
                 {
                     Debug.WriteLine(ex.Message);
                 }
             }
         }
     }
 }
コード例 #3
0
 private async void refreshUsers() {
     HavissIoTCommandBuilder commandBuilder =new HavissIoTCommandBuilder();
     commandBuilder.getUsers();
     if (Config.username.Length > 0)
     {
         if (Config.password.Length > 0)
         {
             commandBuilder.addUser(Config.username, Config.password);
         }
         else
         {
             commandBuilder.addUser(Config.username);
         }
     }
     string response = await SharedVariables.client.request(commandBuilder.getJsonString());
     JObject jsonObject = null;
     JArray jsonArray = null;
     try
     {
         jsonObject = JObject.Parse(response);
         jsonArray = (JArray)jsonObject.GetValue("r");
     }
     catch (Exception ex)
     {
         MessageDialog message = new MessageDialog(ex.Message, "Request parse error");
         return;
     }
     List<string> usernames = new List<string>();
     SharedVariables.userHandler.clearUsers();
     foreach (JObject j in jsonArray)
     {
         try
         {
             string username = (string)j.GetValue("name");
             bool OP = (bool)j.GetValue("isOP");
             bool isProtected = (bool)j.GetValue("isProtected");
             bool isPasswordProtected = (bool)j.GetValue("isPasswordProtected");
             User user = new User(username, OP, isProtected, isPasswordProtected);
             SharedVariables.userHandler.addUser(user);
             usernames.Add(username);
         }
         catch (Exception ex)
         {
             MessageDialog message = new MessageDialog(ex.Message, "Request parse error");
             return;
         }
     }
     available_users.ItemsSource = usernames;
 }
コード例 #4
0
 //If exit button is pressed
 private void exit_button_Click(object sender, RoutedEventArgs e)
 {
     HavissIoTCommandBuilder commandBuilder = new HavissIoTCommandBuilder();
     if (Config.password.Length > 0)
     {
         commandBuilder.addUser(Config.username, Config.password);
     }
     else
     {
         commandBuilder.addUser(Config.username);
     }
     commandBuilder.serverExit();
     SharedVariables.client.write(commandBuilder.getJsonString());
 }