Пример #1
0
        /// <summary>
        /// Button click that initiates a search for diffrent locations.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            ListBoxItems.Clear();
            XmlManager.LocationSheetList locationSheetList = new XmlManager.LocationSheetList();

            //Make sure to not block UI
            await Task.Run(() =>
            {
                try
                {
                    locationSheetList = WebServiceAPIContext.ReceiveLocationList(_SearchLocation, _ConnectionString);
                }
                catch (Exception ex)
                {
                    ShowErrorMessageBox(ex.Message);
                }
                if (locationSheetList.Error && locationSheetList.ExMsg != String.Empty)
                {
                    ShowErrorMessageBox(locationSheetList.ExMsg);
                }
            });

            if (locationSheetList.LocationSheets != null)
            {
                foreach (var x in locationSheetList.LocationSheets)
                {
                    Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(x.Name));

                    ListBoxItems.Add(x);
                }
            }
        }
Пример #2
0
        public IHttpActionResult GetDestinationName(string id)
        {
            XmlManager.LocationSheetList locationSheetList = new XmlManager.LocationSheetList();

            try
            {
                locationSheetList = ResRobot.ResRobot.GetLocations(id);
            }
            catch (Exception ex)
            {
                locationSheetList.Error = true;
                locationSheetList.ExMsg = ex.Message;
            }

            return(Ok(locationSheetList));
        }
Пример #3
0
        /// <summary>
        /// GETs information from WebService API about locations that matches input parameter.
        /// </summary>
        /// <param name="id">String to search for.</param>
        /// <param name="connectionString">WebService API URL.</param>
        /// <returns>A LocationSheetList with locations that matches the id parameter.</returns>
        public static XmlManager.LocationSheetList ReceiveLocationList(string id, string connectionString)
        {
            XmlManager.LocationSheetList xmlSheet = new XmlManager.LocationSheetList();
            xmlSheet.LocationSheets = new List <XmlManager.LocationSheet>();

            WebClient webClient = new WebClient();

            //Need to set encoding to UTF8, else the special characters in some city names will look weird.
            webClient.Encoding = Encoding.UTF8;

            string data = webClient.DownloadString(connectionString + "/api/destination/" + id);


            xmlSheet = JsonConvert.DeserializeObject <XmlManager.LocationSheetList>(data);

            return(xmlSheet);
        }
Пример #4
0
        /// <summary>
        /// Searches for city names and returns LocationSheetList with results. Default is 10 returned results.
        /// </summary>
        /// <param name="name">Search string</param>
        /// <param name="amount">Amount of results to return</param>
        /// <returns></returns>
        public static XmlManager.LocationSheetList GetLocations(String name, int amount = 10)
        {
            XmlReader Reader = XmlReader.Create
                                   ("https://api.resrobot.se/v2/location.name?key=0e8eb279-dd0e-4b30-8f5d-ca0e244f9b6b&maxNo=" + amount + "&input=" + name + "?");

            XmlSerializer seri = new XmlSerializer(typeof(XmlLocationsClass.LocationList));

            XmlLocationsClass.LocationList locationList = (XmlLocationsClass.LocationList)seri.Deserialize(Reader);


            XmlManager.LocationSheetList locationSheetList = new XmlManager.LocationSheetList();
            locationSheetList.LocationSheets = new List <XmlManager.LocationSheet>();

            foreach (XmlLocationsClass.StopLocation stopLocation in locationList.StopLocation)
            {
                locationSheetList.LocationSheets.Add(XmlManager.XmlManager.MakeLocationSheet(stopLocation.Id, stopLocation.Name, stopLocation.Lon, stopLocation.Lat));
            }

            return(locationSheetList);
        }