void OpenFile()
 {
     locations.Clear();
     if (list.SelectedRows.Count != 0)
     {
         foreach (int sel in list.SelectedRows)
         {
             var res = lastResult.results [sel];
             if (res.File == null)
             {
                 continue;
             }
             var loc = new OpenLocation(res.File, res.Row, res.Column);
             if (loc.Line == -1)
             {
                 int i = matchEntry.Query.LastIndexOf(':');
                 if (i != -1)
                 {
                     if (!int.TryParse(matchEntry.Query.Substring(i + 1), out loc.Line))
                     {
                         loc.Line = -1;
                     }
                 }
             }
             locations.Add(loc);
         }
         Respond(ResponseType.Ok);
     }
     else
     {
         Respond(ResponseType.Cancel);
     }
 }
示例#2
0
        public async static Task <BasicGeoposition> GetLocationCoordinates(string location)
        {
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return(new BasicGeoposition());
            }
            string           query = string.Format("q={0}&format=json", location);
            string           responseJson;
            BasicGeoposition geoposition = new BasicGeoposition();

            try
            {
                WebRequest webRequest = WebRequest.Create(locationApi + query);
                webRequest.Method      = "GET";
                webRequest.ContentType = "application/x-www-form-urlencoded";

                using (WebResponse webResponse = await webRequest.GetResponseAsync())
                    using (StreamReader dataReader = new StreamReader(webResponse.GetResponseStream()))
                    {
                        responseJson = await dataReader.ReadToEndAsync();
                    }

                JObject        searchResult  = JObject.Parse(string.Format("{{'searchResult':{0}}}", responseJson));
                IList <JToken> locationsJson = searchResult["searchResult"].Children().ToList();
                OpenLocation   foundLocation = JsonConvert.DeserializeObject <OpenLocation>(locationsJson?[0].ToString());
                geoposition = new BasicGeoposition()
                {
                    Latitude = Convert.ToDouble(foundLocation?.Lat), Longitude = Convert.ToDouble(foundLocation?.Lon)
                };
            }
            catch (WebException webEx)
            {
                var dialog = new MessageDialog(webEx.Message);
                await dialog.ShowAsync();
            }
            catch (JsonException jsonEx)
            {
                var dialog = new MessageDialog(jsonEx.Message);
                await dialog.ShowAsync();
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog(ex.Message);
                await dialog.ShowAsync();
            }

            return(geoposition);
        }