Esempio n. 1
0
 void LoginOnClick()
 {
     foreach (InputField e in required)
     {
         function.RequiredInputOnEndEdit(e);
     }
     if (function.InputFieldRequired(required))
     {
         HTTPRequest request = new HTTPRequest(new Uri(data.IP + "/login?account=" + username.text + "&password="******"true")
             {
                 HTTPRequest request_getUser = new HTTPRequest(new Uri(data.IP + "/getUserByAccount?account=" + username.text), HTTPMethods.Get, (req_user, res_user) =>
                 {
                     JsonData json = JsonMapper.ToObject(res_user.DataAsText);
                     Debug.Log((string)json["authorities"][0]["authority"]);
                     if ((string)json["authorities"][0]["authority"] == "ROLE_ADMIN")
                     {
                         SceneManager.LoadScene("admin");
                     }
                     else
                     {
                         Debug.Log(res_user.DataAsText);
                         data.m_user.setId((long)json["id"]);
                         data.m_user.setUsername((string)json["username"]);
                         data.m_user.setNickname((string)json["nickname"]);
                         data.m_user.setPassword((string)json["password"]);
                         data.m_user.setFirstname((string)json["firstname"]);
                         data.m_user.setLastname((string)json["lastname"]);
                         data.m_user.setPhone((string)json["phone"]);
                         data.m_user.setGender((bool)json["gender"]);
                         data.m_user.setEmail((string)json["email"]);
                         if ((bool)json["enabled"] == true)
                         {
                             HTTPRequest request_getGarden = new HTTPRequest(new Uri(data.IP + "/getGardenByUserId?userId=" + data.m_user.getId()), HTTPMethods.Get, (req_garden, res_garden) =>
                             {
                                 Debug.Log(res_garden.DataAsText);
                                 JArray array = JArray.Parse(res_garden.DataAsText);
                                 foreach (var e in array)
                                 {
                                     m_garden newGarden = new m_garden();
                                     newGarden.setId((long)e["id"]);
                                     newGarden.setName((string)e["name"]);
                                     newGarden.setLength((int)e["length"]);
                                     newGarden.setWidth((int)e["width"]);
                                     newGarden.setIdealTemperature((float)e["idealTemperature"]);
                                     newGarden.setIdealHumidity((float)e["idealWetness"]);
                                     Debug.Log(newGarden.getName());
                                     data.m_user.addGardens(newGarden);
                                 }
                                 SceneManager.LoadScene("garden");
                             }).Send();
                         }
                     }
                 }).Send();
             }
         }).Send();
     }
 }
Esempio n. 2
0
 void OnEnable()
 {
     selected         = function.FindSelected();
     garden_name.text = selected.getName();
     length.text      = selected.getLength().ToString();
     width.text       = selected.getWidth().ToString();
     temperature.text = selected.getIdealTemperature().ToString();
     humidity.text    = selected.getIdealHumidity().ToString();
 }
Esempio n. 3
0
 public static void FreshGarden(m_garden garden)
 {
     Debug.Log(garden.getName());
     GameObject.Find("Canvas/map").GetComponent <Dropdown>().value = 0;
     GameObject.Find("HeatCanvas").transform.Find("painting/Scroll View/map/background/HeatMapT").gameObject.SetActive(false);
     GameObject.Find("HeatCanvas").transform.Find("painting/Scroll View/map/background/HeatMapH").gameObject.SetActive(false);
     MapBG.clearAll();
     garden.cleanSensor();
     garden.cleanController();
     GetSensors(garden);
     GetControllers(garden);
     GetGardenInfo(garden);
     return;
 }
Esempio n. 4
0
    void SaveOnClick()
    {
        foreach (InputField e in required)
        {
            function.RequiredInputOnEndEdit(e);
        }
        foreach (Text e in warning)
        {
            if (e.IsActive())
            {
                return;
            }
        }
        if (function.InputFieldRequired(required))
        {
            if (garden_name.text != selected.getName() || temperature.text != selected.getIdealTemperature().ToString() || humidity.text != selected.getIdealHumidity().ToString() || length.text != selected.getLength().ToString() || width.text != selected.getWidth().ToString())
            {
                HTTPRequest request = new HTTPRequest(new Uri(data.IP + "/updateGarden"), HTTPMethods.Post, (req, res) =>
                {
                    switch (req.State)
                    {
                    case HTTPRequestStates.Finished:
                        Debug.Log(res.DataAsText);
                        function.FreshGarden(selected);
                        break;

                    default:
                        Debug.Log("Error!Status code:" + res.StatusCode);
                        break;
                    }
                });
                request.AddHeader("Content-Type", "application/json");

                JsonData newGarden = new JsonData();
                newGarden["id"]               = selected.getId().ToString();
                newGarden["userId"]           = data.m_user.getId().ToString();
                newGarden["width"]            = width.text;
                newGarden["length"]           = length.text;
                newGarden["name"]             = garden_name.text;
                newGarden["idealTemperature"] = temperature.text;
                newGarden["idealWetness"]     = humidity.text;
                request.RawData               = System.Text.Encoding.UTF8.GetBytes(newGarden.ToJson());

                request.Send();
            }
            GameObject.Find("Canvas/cover").SetActive(false);
            GameObject.Find("Canvas/garden_info").SetActive(false);
        }
    }
Esempio n. 5
0
 public static void FreshGardens(m_garden garden)
 {
     data.m_user.clearGardens();
     HTTPRequest request_getGarden = new HTTPRequest(new Uri(data.IP + "/getGardenByUserId?userId=" + data.m_user.getId()), HTTPMethods.Get, (req_garden, res_garden) => {
         Debug.Log(res_garden.DataAsText);
         JArray array = JArray.Parse(res_garden.DataAsText);
         foreach (var e in array)
         {
             m_garden newGarden = new m_garden();
             newGarden.setId((long)e["id"]);
             newGarden.setName((string)e["name"]);
             newGarden.setLength((int)e["length"]);
             newGarden.setWidth((int)e["width"]);
             newGarden.setIdealTemperature((float)e["idealTemperature"]);
             newGarden.setIdealHumidity((float)e["idealWetness"]);
             Debug.Log(newGarden.getName());
             data.m_user.addGardens(newGarden);
         }
         FreshGarden(garden);
     }).Send();
 }