コード例 #1
0
        public async Task <SendObjectResult> PostSendObjectResultAsync(string uri, string time, string userid, string longitude, string latitude)
        {
            SendObjectBody objectBody = new SendObjectBody {
                dateTime = time, userId = userid, longitude = longitude, latitude = latitude
            };
            SendObjectResult objectResult = new SendObjectResult();

            try
            {
                var postcontent = JsonConvert.SerializeObject(objectBody);
                HttpResponseMessage response = await _client.PostAsync(uri, new StringContent(postcontent));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    objectResult = JsonConvert.DeserializeObject <SendObjectResult>(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }

            return(objectResult);
        }
コード例 #2
0
 public ArrivalDeparturePage(string userid, string datetime, SendObjectResult result)
 {
     InitializeComponent();
     arrivalDepartureobj = new ArrivalDeparture {
         userid = userid, userName = result.userName, userSurname = result.userSurname, dateTime = datetime, workingPlaceId = result.workingPlaceId, workingPlaceName = result.workingPlaceName
     };
     _restService = new RestService();
 }
コード例 #3
0
        public async void OnRegisterButtonClicked(object sender, EventArgs e)
        {
            String myDate = DateTime.Now.ToString(CultureInfo.InvariantCulture);

            //((App)App.Current).MainPage = new NavigationPage(busyPopUp);
            //await Navigation.PushAsync(busyPopUp);
            await PopupNavigation.Instance.PushAsync(new BusyPopUp("Nustatomos koordinatės"));

            try
            {
                //var location = await Geolocation.GetLastKnownLocationAsync();
                var request  = new GeolocationRequest(GeolocationAccuracy.Best);
                var location = await Geolocation.GetLocationAsync(request);

                if (location != null)
                {
                    Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
                    var latitude            = location.Latitude.ToString("0.0000", CultureInfo.InvariantCulture);
                    var longitude           = location.Longitude.ToString("0.0000", CultureInfo.InvariantCulture);
                    SendObjectResult result = await _restService.PostSendObjectResultAsync(Constants.StatybuDemoEndpoint, myDate, Preferences.Get("user_id", ""), longitude, latitude);

                    if (_restService.ResultIsOk(result.errorID))
                    {
                        await PopupNavigation.Instance.PopAsync();

                        await Navigation.PushAsync(new ArrivalDeparturePage(Preferences.Get("user_id", ""), myDate, result));
                    }
                    else
                    {
                        await DisplayAlert("Įspėjimas", "Sistemoje objektas nerastas. Klaidos pranešimas:\n" + result.errorDesc, "OK");

                        await PopupNavigation.Instance.PopAsync();

                        //((App)App.Current).MainPage = new NavigationPage(new SendObjectBodyPage());
                        //// Application.Current.MainPage = new SendObjectBodyPage();
                        //await Navigation.PopToRootAsync();
                    }
                }
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await DisplayAlert("Įspėjimas", "GPS nepalaikymo telefone klaida / Handle not supported on device exception", "OK");

                await PopupNavigation.Instance.PopAsync();

                // Handle not supported on device exception
            }
            catch (FeatureNotEnabledException fneEx)
            {
                await DisplayAlert("Įspėjimas", "GPS neįjungimo telefone klaida / Handle not enabled on device exception", "OK");

                await PopupNavigation.Instance.PopAsync();

                // Handle not enabled on device exception
            }
            catch (PermissionException pEx)
            {
                await DisplayAlert("Įspėjimas", "Neįjungtos GPS teisės / Handle permission exception", "OK");

                await PopupNavigation.Instance.PopAsync();

                // Handle permission exception
            }
            catch (Exception ex)
            {
                await DisplayAlert("Įspėjimas", "GPS koordinatės negautos, nustatykite leidimą naudoti GPS ir įsijunkite GPS / Unable to get location", "OK");

                PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync <Location>();

                PermissionStatus status = await CrossPermissions.Current.RequestPermissionAsync <CalendarPermission>();

                await PopupNavigation.Instance.PopAsync();

                // Unable to get location
            }
        }