IEnumerator Login() { WWWForm form = new WWWForm(); form.AddField("email", email.text.TrimEnd('\u200b')); form.AddField("password", inputPassword.GetComponent <TMP_InputField>().text.TrimEnd('\u200b')); using (UnityWebRequest www = UnityWebRequest.Post("http://localhost:8000/api/login", form)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); //if incorrectPasswordthings loadingPanel.SetActive(false); inputUsername.GetComponent <Image>().sprite = wrongUsername; inputPassword.GetComponent <Image>().sprite = wrongPassword; incorrectText.SetActive(true); incorrectText.GetComponent <TextMeshProUGUI>().text = "El nombre de usuario y/o contraseña son incorrectos"; } else { Debug.Log("Form upload complete!"); Debug.Log(www.downloadHandler.text); rootObject stringToken = JsonUtility.FromJson <rootObject>(www.downloadHandler.text); Debug.Log(stringToken.success.token); Manager.GetInstance().userToken = "Bearer " + stringToken.success.token; userData.GetComponent <GetData>().getData(); } } }
IEnumerator getUserData() { WWWForm form = new WWWForm(); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("header-name", "header content"); using (UnityWebRequest www = UnityWebRequest.Post("http://localhost:8000/api/details", form)) { www.SetRequestHeader("Authorization", Manager.GetInstance().userToken); www.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded"); www.SetRequestHeader("Accept", "application/json"); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { //Debug.Log(www.downloadHandler.text); rootObject stringToken = JsonUtility.FromJson <rootObject>(www.downloadHandler.text); Manager.GetInstance().Username = stringToken.success.name; Manager.GetInstance().UserId = stringToken.success.id; Manager.GetInstance().UserAge = stringToken.success.age; Manager.GetInstance().UserEmail = stringToken.success.email; Manager.GetInstance().Email_verified_at = stringToken.success.email_verified_at; Manager.GetInstance().User_role_id = stringToken.success.role_id; if (stringToken.success.role_id != "1") { loadingPanel.SetActive(false); incorrectText.SetActive(true); incorrectText.GetComponent <TextMeshProUGUI>().text = "En este momento la aplicación solo está disponible para los pacientes"; } else { SceneManager.LoadScene("MainScreen"); } } } }
public string WorkItemsByIteration(string iterationPath, string AreaPath) { byte[] data = Convert.FromBase64String(iterationPath); string decodediterationPath = Encoding.UTF8.GetString(data); byte[] data1 = Convert.FromBase64String(AreaPath); string decodedAreaPath = Encoding.UTF8.GetString(data1); string wiqlUrl = deserializedURL.WIQLUrl; BasicAuthentication.client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); var query = new { query = "Select [System.Id],[System.Title] from WorkItems where ([System.AreaPath] = '" + decodedAreaPath + "' and [System.IterationPath] = '" + decodediterationPath + "' and ([System.WorkItemType] ='Feature' OR [System.WorkItemType] ='User Story' OR [System.WorkItemType] ='Bug'))" }; string serializedQuery = JsonConvert.SerializeObject(query); string json = BasicAuthentication.client.UploadString(wiqlUrl, "POST", serializedQuery).ToString(); var deserializedWorkItems = JsonConvert.DeserializeObject <RootObject>(json); var workItemId = deserializedWorkItems.workItems.Select(p => p.id).ToList(); var splitItemIds = workItemId.Select((x, i) => new { Index = i, Value = x }) .GroupBy(x => x.Index / 200) .Select(x => x.Select(v => v.Value).ToList()) .ToList(); foreach (var ids in splitItemIds) { string combindedWorkItemId = string.Join(",", ids.ToArray()); string workItemDetailsUrl = String.Format("{0}{1}", TFSUrl, "_apis/wit/workitems?ids=" + combindedWorkItemId + "&api-version=2.0"); var workItemDetails = BasicAuthentication.client.DownloadString(workItemDetailsUrl); rootObject lists = JsonConvert.DeserializeObject <rootObject>(workItemDetails); var groupByWorkItems = lists.value.Where(t => t.fields != null).GroupBy(t => t.fields.SystemWorkItemType); var featureData = groupByWorkItems.Where(t => t.Key == "Feature"). Select(g => new { TargetFP = g.Sum(a => a.fields.MicrosoftVSTSCommonBusinessValue), closedFP = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.MicrosoftVSTSCommonBusinessValue : 0), inProgressFP = g.Sum(a => a.fields.SystemState == "In Progress" ? a.fields.MicrosoftVSTSCommonBusinessValue : 0), newFP = g.Sum(a => a.fields.SystemState == "New" ? a.fields.MicrosoftVSTSCommonBusinessValue : 0), RemovedFP = g.Sum(a => a.fields.SystemState == "Removed" ? a.fields.MicrosoftVSTSCommonBusinessValue : 0) }).ToList(); var bugData = groupByWorkItems.Where(t => t.Key == "Bug").Select(g => new { BugRaised = g.Sum(a => 1), BugClosed = g.Sum(a => a.fields.SystemState == "Done" ? 1 : 0) }).ToList(); var userStoriesData = groupByWorkItems.Where(t => t.Key == "User Story"). Select(g => new { TargetUs = g.Sum(a => a.fields.MicrosoftVSTSSchedulingStoryPoints), closedUs = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.MicrosoftVSTSSchedulingStoryPoints : 0), resolvedUs = g.Sum(a => a.fields.SystemState == "Resolved" ? a.fields.MicrosoftVSTSSchedulingStoryPoints : 0), activeUs = g.Sum(a => a.fields.SystemState == "Active" ? a.fields.MicrosoftVSTSSchedulingStoryPoints : 0), newUs = g.Sum(a => a.fields.SystemState == "New" ? a.fields.MicrosoftVSTSSchedulingStoryPoints : 0) }).ToList(); if (featureData.Count > 0) { closedFeaturePoint += featureData[0].closedFP; inProgressFeaturePoint += featureData[0].inProgressFP; newFeaturePoint += featureData[0].newFP; removedFeaturePoint += featureData[0].RemovedFP; } if (bugData.Count > 0) { bugRaised += bugData[0].BugRaised; bugClosed += bugData[0].BugClosed; } if (userStoriesData.Count > 0) { closedStoryPoint += userStoriesData[0].closedUs; resolvedStoryPoint += userStoriesData[0].resolvedUs; newStoryPoint += userStoriesData[0].newUs; activeStoryPoint += userStoriesData[0].activeUs; } } Dictionary <string, int> ExpectedData = new Dictionary <string, int>(); ExpectedData.Add("inProgressFeaturePoint", inProgressFeaturePoint); ExpectedData.Add("ClosedFeaturePoint", closedFeaturePoint); ExpectedData.Add("newFeaturePoint", newFeaturePoint); ExpectedData.Add("removedFeaturePoint", removedFeaturePoint); ExpectedData.Add("resolvedStoryPoint", targetStoryPoint); ExpectedData.Add("ClosedStoryPoint", closedStoryPoint); ExpectedData.Add("newStoryPoint", newStoryPoint); ExpectedData.Add("activeStoryPoint", activeStoryPoint); ExpectedData.Add("BugRaised", bugRaised); ExpectedData.Add("BugClosed", bugClosed); var Expectedjson = JsonConvert.SerializeObject(ExpectedData); return(Expectedjson); }
public string post(string AreaPath) { Dictionary <string, Dictionary <string, string> > iterationdata = new Dictionary <string, Dictionary <string, string> >(); Dictionary <string, string> li; // AreaPath = HttpUtility.UrlDecode("ProjectOne%5CTeam%20Summer%5CIDW%20Ekonomiskt%20bist%C3%A5nd%20rapport"); // AreaPath = "ProjectOne\\Team Summer\\AreaPathOne"; string iterationName = ""; string iterationId = ""; // byte[] data = Convert.FromBase64String(AreaPath); //string decodedString = Encoding.UTF8.GetString(data); string uri = deserializedURL.WIQLUrl; BasicAuthentication.client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); var query = new { query = "Select [System.Id],[System.Title] from WorkItems where [System.AreaPath] = '" + AreaPath + "' and ([System.WorkItemType] ='Feature' OR [System.WorkItemType] ='User Story' OR [System.WorkItemType] ='Bug')" }; string serializedQuery = JsonConvert.SerializeObject(query); string json = BasicAuthentication.client.UploadString(uri, "POST", serializedQuery).ToString(); var deserializedWorkItems = JsonConvert.DeserializeObject <RootObject>(json); var workItemId = deserializedWorkItems.workItems.Select(p => p.id).ToList(); var splitItemIds = workItemId.Select((x, i) => new { Index = i, Value = x }) .GroupBy(x => x.Index / 200) .Select(x => x.Select(v => v.Value).ToList()) .ToList(); foreach (var ids in splitItemIds) { string combindedWorkItemId = string.Join(",", ids.ToArray()); string workItemDetailsUrl = String.Format("{0}{1}", TFSUrl, "_apis/wit/workitems?ids=" + combindedWorkItemId + "&$expand=all&api-version=2.0"); var workItemDetails = BasicAuthentication.client.DownloadString(workItemDetailsUrl); rootObject lists = JsonConvert.DeserializeObject <rootObject>(workItemDetails); var groupByItertaion = lists.value.Where(t => t.fields != null).GroupBy(t => t.fields.SystemIterationPath); var iterationPath = groupByItertaion.Select(t => new { path = t.Key }); // var iterationPathandId= groupByItertaion.Where(t => t.Key != null).Select(g => new { iterationPath = g.OrderBy(a => a.fields.SystemIterationPath), iterationId = g.OrderBy(a => a.fields.SystemIterationId) }).ToList(); foreach (var pa in iterationPath) { li = new Dictionary <string, string>(); iterationName = pa.path.ToString(); BasicAuthentication.client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); var newQuery = new { Path = iterationName }; string newserializedQuery = JsonConvert.SerializeObject(newQuery); string iterationUrl = deserializedURL.IterationUrl; string newIterationUrl = string.Format("{0}{1}", TFSUrl, iterationUrl); string newjson = BasicAuthentication.client.UploadString(newIterationUrl, "POST", newserializedQuery).ToString(); dynamic deserializediterationdata = JsonConvert.DeserializeObject <iterationDates>(newjson); DateTime startDate = Convert.ToDateTime(deserializediterationdata.attributes.startDate); DateTime finishDate = Convert.ToDateTime(deserializediterationdata.attributes.finishDate); startDate = startDate.Date; finishDate = finishDate.Date; li.Add("startDate", startDate.ToString("dd/MM/yyyy")); li.Add("finishDate", finishDate.ToString("dd/MM/yyyy")); li.Add("itertaionName", iterationName); // string iterationUrl = "http://desktop-498rai4:8080/tfs/DefaultCollection/ProjectOne/_apis/work/teamsettings/iterations/" + iterationId + "?api-version=2.0"; //string IterationByID = BasicAuthentication.client.DownloadString(iterationUrl); var iterationfeature = groupByItertaion.Where(t => t.Key == iterationName).Select(g => new { tfp = g.Sum(a => a.fields.MicrosoftVSTSCommonBusinessValue), closedFP = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.MicrosoftVSTSCommonBusinessValue : 0) }).ToList(); var eg = groupByItertaion.Where(t => t.Key == iterationName).Select(g => new { tfp = g.Sum(a => a.fields.MicrosoftVSTSCommonBusinessValue), closedFP = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.MicrosoftVSTSCommonBusinessValue : 0) }).ToList(); var iterationbugData = groupByItertaion.Where(t => t.Key == iterationName).Select(g => new { BugRaised = g.Sum(a => a.fields.SystemWorkItemType == "Bug" ? 1 : 0), BugClosed = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.SystemWorkItemType == "Bug" ?1 :0: 0) }).ToList(); var iterationuserStoriesData = groupByItertaion.Where(t => t.Key == iterationName).Select(g => new { TargetUs = g.Sum(a => a.fields.MicrosoftVSTSSchedulingStoryPoints), closedUs = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.MicrosoftVSTSSchedulingStoryPoints : 0) }).ToList(); if (iterationfeature.Count > 0) { li.Add("iterationtargetFeaturePoint", iterationfeature[0].tfp.ToString()); li.Add("iterationclosedFeaturePoint", iterationfeature[0].closedFP.ToString()); } if (iterationbugData.Count > 0) { li.Add("iterationbugRaised", iterationbugData[0].BugRaised.ToString()); li.Add("iterationbugClosed", iterationbugData[0].BugClosed.ToString()); } if (iterationuserStoriesData.Count > 0) { li.Add("iterationuserStoriesData", iterationuserStoriesData[0].TargetUs.ToString()); li.Add("iterationclosedStoryPoint", iterationuserStoriesData[0].closedUs.ToString()); } iterationdata.Add(iterationName, li); } var groupByWorkItems = lists.value.Where(t => t.fields != null).GroupBy(t => t.fields.SystemWorkItemType); var featureData = groupByWorkItems.Where(t => t.Key == "Feature").Select(g => new { TargetFP = g.Sum(a => a.fields.MicrosoftVSTSCommonBusinessValue), closedFP = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.MicrosoftVSTSCommonBusinessValue : 0) }).ToList(); var bugData = groupByWorkItems.Where(t => t.Key == "Bug").Select(g => new { BugRaised = g.Sum(a => 1), BugClosed = g.Sum(a => a.fields.SystemState == "Done" ? 1 : 0) }).ToList(); var userStoriesData = groupByWorkItems.Where(t => t.Key == "User Story").Select(g => new { TargetUs = g.Sum(a => a.fields.MicrosoftVSTSSchedulingStoryPoints), closedUs = g.Sum(a => a.fields.SystemState == "Done" ? a.fields.MicrosoftVSTSSchedulingStoryPoints : 0) }).ToList(); if (featureData.Count > 0) { targetFeaturePoint += featureData[0].TargetFP; closedFeaturePoint += featureData[0].closedFP; } if (bugData.Count > 0) { bugRaised += bugData[0].BugRaised; bugClosed += bugData[0].BugClosed; } if (userStoriesData.Count > 0) { targetStoryPoint += userStoriesData[0].TargetUs; closedStoryPoint += userStoriesData[0].closedUs; } } Dictionary <string, int> ExpectedData = new Dictionary <string, int>(); ExpectedData.Add("TargetFeaturePoint", targetFeaturePoint); ExpectedData.Add("ClosedFeaturePoint", closedFeaturePoint); ExpectedData.Add("TargetStoryPoint", targetStoryPoint); ExpectedData.Add("ClosedStoryPoint", closedStoryPoint); ExpectedData.Add("BugRaised", bugRaised); ExpectedData.Add("BugClosed", bugClosed); var newExpectedjson = JsonConvert.SerializeObject(iterationdata); var Expectedjson = JsonConvert.SerializeObject(ExpectedData); Expectedjson = "[" + Expectedjson + "," + newExpectedjson + "]"; return(Expectedjson); }
public List <string> findHotel(string city, float rating) { // trim leading and trailing whitespace city = city.Trim(); // api key for google services, connected to my creditcard, please be kind :( string api_key = "AIzaSyBdq_oSqZuIU52qxSRaC8gHAPBtEafDAWM"; // formatted url for downloading json data string url = string.Format("https://maps.googleapis.com/maps/api/geocode/json?components=locality:{0}&key={1}", city, api_key); // var declaration used to call second service string latAndlon; // results list that will be returned List <string> result = new List <string>(); using (WebClient client = new WebClient()) { //download data into string string json = client.DownloadString(url); // deserialize into zip object geoCodeObject city_coordinates = (new JavaScriptSerializer()).Deserialize <geoCodeObject>(json); // if zip received is valid if (city_coordinates.status == "OK") { // save lat and long returned from api call into local var latAndlon = city_coordinates.results[0].geometry.location.lat.ToString() + ',' + city_coordinates.results[0].geometry.location.lng.ToString(); // use latAndlon var containing coordinates to make second api call url = string.Format("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={0}&radius=16093&keyword=hotel&key={1}", latAndlon, api_key); // download results json = client.DownloadString(url); // save all json info into store object rootObject hotelSearch = (new JavaScriptSerializer()).Deserialize <rootObject>(json); // if store is found if (hotelSearch.status == "OK") { // find 5 hotels int count = 0; // itterates across the results found for (int i = 0; i < hotelSearch.results.Length; i++) { // check if rating is equivalent to user input if (hotelSearch.results[i].rating >= rating) { // add name, address, and rating to results result.Add(hotelSearch.results[i].name); result.Add(hotelSearch.results[i].vicinity); result.Add(Convert.ToString(hotelSearch.results[i].rating)); // increment counter count++; } // exit for loop once 5 hotels added to results list if (count == 5) { break; } } // if response valid, but no hotels that match given rating if (count == 0) { result.Add("Error: No hotels of given rating found"); return(result); } } // no stores were found else { result.Add(string.Format("Error: There were no hotels found in {0}", city)); return(result); } return(result); } // invalid zipcode else { result.Add(String.Format("Error: {0} was not found", city)); return(result); } } }