Exemplo n.º 1
0
        async void NewServerIp(System.Object sender, System.EventArgs e)
        {
            string newIP = IpAddress.Text != null ? IpAddress.Text : IpAddress.Placeholder;

            AppConfiguration.REGISTRATION_SERVER_URL = new UriBuilder("http", newIP, 8000);
            AppConfiguration.LOCATION_SERVER_URL     = new UriBuilder("http", newIP, 8000);
            await LocationsAggregator.RetrieveId(true);

            DisplayAlert("o_O", "---> " + newIP + " <---", "OK");
        }
Exemplo n.º 2
0
        public static async Task <LocationsAggregator> GetInstance()
        {
            if (Instance == null)
            {
                string id = await RetrieveId();

                Instance = new LocationsAggregator(id);
            }

            return(Instance);
        }
Exemplo n.º 3
0
        private async Task <bool> SendSymptoms(Symptoms symptoms)
        {
            Report report = new Report(symptoms);

            report.id = await LocationsAggregator.RetrieveId();

            if (report.id == null)
            {
                return(false);
            }

            string data    = JsonConvert.SerializeObject(report);
            bool   success = await NetworkLayer.SendDataToServer(data);

            return(success);
        }
Exemplo n.º 4
0
        private static async Task <ServerResponse> IssueRequest(string action, Uri uri, bool addId = false)
        {
            HttpClient client  = new HttpClient();
            Request    request = new Request(action);

            if (addId)
            {
                request.id = await LocationsAggregator.RetrieveId();
            }
            string requestString = JsonConvert.SerializeObject(request);

            Debug.WriteLine(requestString, "[IssueRequest]");

            try {
                HttpResponseMessage response = await client.PostAsync(uri, new StringContent(requestString));

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine("Success", "[IssueRequest]");
                    string rawResult = await response.Content.ReadAsStringAsync();

                    try {
                        return(JsonConvert.DeserializeObject <ServerResponse>(rawResult));
                    }
                    catch (JsonSerializationException e) {
                        Debug.WriteLine("Exception: " + e.Message, "[IssueRequest]");
                    }
                    return(new ServerResponse());
                }
                else
                {
                    Debug.WriteLine("FAILED: " + response.ReasonPhrase, "[IssueRequest]");
                }
            }
            catch (Exception e) {
                Debug.WriteLine("Exception: " + e.Message, "[IssueRequest]");
            }

            return(new ServerResponse());
        }