예제 #1
0
        public List <WaypointItem> getWaypoints()
        {
            var               waypoints = new List <WaypointItem>();
            string            sql       = "SELECT cacheCode, body from userWaypointsV3;";
            SQLiteCommand     command   = new SQLiteCommand(sql, conn);
            SQLiteDataAdapter DB        = new SQLiteDataAdapter(command.CommandText, conn);
            DataSet           wptRows   = new DataSet();

            DB.Fill(wptRows);
            foreach (DataRowView row in wptRows.Tables[0].DefaultView)
            {
                var item = new WaypointItem();
                item.cacheCode = row["cacheCode"].ToString();
                var plist = decompressPlist(row["body"].ToString());
                foreach (var plistItem in plist["mRecordByAddress"] as PListDict)
                {
                    var waypointDict = plistItem.Value as PListDict;
                    if (waypointDict.ContainsKey("mLatitude"))
                    {
                        item.name       = (waypointDict["mName"] as PListString).Value;
                        item.lat        = (waypointDict["mLatitude"] as PListReal).Value;
                        item.lon        = (waypointDict["mLongitude"] as PListReal).Value;
                        item.IsSelected = false;
                        waypoints.Add(item);
                        break;
                    }
                }
            }
            return(waypoints);
        }
예제 #2
0
        public async Task <bool> AddWaypoint(WaypointItem waypoint)
        {
            using (HttpClient client = GetClient())
            {
                try
                {
                    String fullUrl = AddWaypointUrl;

                    var requestDict = new { AccessToken           = token,
                                            CacheCode             = waypoint.cacheCode,
                                            Latitude              = waypoint.lat,
                                            Longitude             = waypoint.lon,
                                            Description           = waypoint.name,
                                            IsCorrectedCoordinate = false,
                                            IsUserCompleted       = false };
                    var requestJSON = JObject.FromObject(requestDict);
                    // StringContent reqContent = new HttpContent()

                    StringContent reqContent = new StringContent(requestJSON.ToString(), Encoding.UTF8, "application/json");
                    // reqContent.Headers.Add("Authorization", "bearer " + "f0df18ab-d306-4f0f-b1da-502ce6a8f17e");
                    HttpResponseMessage responseMessage = await client.PostAsync(fullUrl, reqContent);

                    responseMessage.EnsureSuccessStatusCode();
                    string content = await responseMessage.Content.ReadAsStringAsync();

                    //content = content.Trim('"');
                    System.Console.WriteLine(content);
                    //JObject json = JObject.Parse(content);
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }