コード例 #1
0
        public async void UploadMapAsync()
        {
            var CheckPoints = new List <RaceCheckpoint>();
            int LatLongTemp = 0;

            RaceMapBindingModel raceMap = new RaceMapBindingModel();

            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };
            HttpClient client = new HttpClient(clientHandler);

            foreach (Location variable in _locations)
            {
                RaceCheckpoint checkpoint = new RaceCheckpoint();
                checkpoint.Latitude      = variable.Position.Latitude;
                checkpoint.Longitude     = variable.Position.Longitude;
                checkpoint.NumberInOrder = LatLongTemp + 1;
                CheckPoints.Add(checkpoint);
                LatLongTemp += 1;
            }
            raceMap.Name            = MapName;
            raceMap.Description     = "TestOpis";
            raceMap.RaceCheckpoints = CheckPoints;
            System.Net.ServicePointManager.ServerCertificateValidationCallback = (message, cert, chain, errors) => { return(true); };
            var url         = "https://xamaracing.azurewebsites.net/v1/RaceMaps";
            var JSONcontent = JsonConvert.SerializeObject(raceMap);
            var data        = new StringContent(JSONcontent, Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Tokens.UserToken);
            var response = await client.PostAsync(url, data);

            string result = response.Content.ReadAsStringAsync().Result;
        }
コード例 #2
0
        public async void DownlaodMap(string id)
        {
            MapID = id;
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };
            HttpClient client = new HttpClient(clientHandler);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Tokens.UserToken);
            Uri FirstRaceMapsURI  = new Uri("https://xamaracing.azurewebsites.net/v1/RaceMaps/");
            Uri ConcatRaceMapsURI = new Uri(FirstRaceMapsURI, id);
            var content           = await client.GetStringAsync(ConcatRaceMapsURI);

            RaceMap = JsonConvert.DeserializeObject <RaceMapBindingModel>(content);


            foreach (var item in RaceMap.RaceCheckpoints)
            {
                Geocoder geoCoder        = new Geocoder();
                var      address         = "";
                var      PossibleAddress = await geoCoder.GetAddressesForPositionAsync(new Position(item.Latitude, item.Longitude));

                foreach (var a in PossibleAddress)
                {
                    address += a;
                }
                _locations.Add(new Location($"{item.NumberInOrder}", $"{address}", new Position(item.Latitude, item.Longitude)));
            }
        }