/// <summary>
        /// This event handler method calls
        /// the ProcessLocation method of the ProcessorClass class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SearchLocationButton_Click(object sender, EventArgs e)
        {
            //ProcessorClass.ProcessSearchLocation();
            try
            {
                String results = NoOfDaysDropDownList.SelectedValue.ToString();
                String Format  = "JSON";

                /*Set input parameters for the API*/
                LocationSearchInput input = new LocationSearchInput();
                input.query          = SearchTextBox.Text;
                input.num_of_results = results;
                input.format         = Format;

                /* Call the SearchLocation method and pass in the input parameters*/
                API_Implementation api            = new API_Implementation();
                LocationSearch     locationSearch = api.SearchLocation(input);

                /*Display Results*/
                DisplayResultsTextBox.Text  = "\r\n Area Name: " + locationSearch.search_API.result[0].areaName[0].value;
                DisplayResultsTextBox.Text += "\r\n Country: " + locationSearch.search_API.result[0].country[0].value;
                DisplayResultsTextBox.Text += "\r\n Latitude: " + locationSearch.search_API.result[0].latitude;
                DisplayResultsTextBox.Text += "\r\n Longitude: " + locationSearch.search_API.result[0].longitude;
                DisplayResultsTextBox.Text += "\r\n Population: " + locationSearch.search_API.result[0].population;
                DisplayResultsTextBox.Text += "\r\n Region: " + locationSearch.search_API.result[0].region[0].value;
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
            }
        }
Example #2
0
        /// <summary>
        /// Creates an instance of <see cref="LocationsViewModel"/>
        /// </summary>
        public LocationsViewModel(Compendium compendium, LocationSearchService locationSearchService, LocationSearchInput locationSearchInput,
                                  StringService stringService, DialogService dialogService, XMLImporter xmlImporter, DocumentService documentService, DataManager dataManager)
        {
            _compendium            = compendium;
            _locationSearchService = locationSearchService;
            _locationSearchInput   = locationSearchInput;
            _stringService         = stringService;
            _dialogService         = dialogService;
            _xmlImporter           = xmlImporter;
            _documentService       = documentService;
            _dataManager           = dataManager;

            _selectLocationCommand     = new RelayCommand(obj => true, obj => SelectLocation(obj as ListItemViewModel <LocationModel>));
            _editLocationCommand       = new RelayCommand(obj => true, obj => EditLocation(obj as LocationViewModel));
            _exportLocationCommand     = new RelayCommand(obj => true, obj => ExportLocation(obj as LocationViewModel));
            _cancelEditLocationCommand = new RelayCommand(obj => true, obj => CancelEditLocation());
            _saveEditLocationCommand   = new RelayCommand(obj => HasUnsavedChanges, obj => SaveEditLocation());
            _resetFiltersCommand       = new RelayCommand(obj => true, obj => InitializeSearch());
            _addCommand            = new RelayCommand(obj => true, obj => Add());
            _copyCommand           = new RelayCommand(obj => _selectedLocation != null, obj => Copy());
            _deleteCommand         = new RelayCommand(obj => _selectedLocation != null, obj => Delete());
            _importCommand         = new RelayCommand(obj => true, obj => Import());
            _selectNextCommand     = new RelayCommand(obj => true, obj => SelectNext());
            _selectPreviousCommand = new RelayCommand(obj => true, obj => SelectPrevious());

            Search();
        }
Example #3
0
    public LocationSearch SearchLocation(LocationSearchInput input)
    {
        // create URL based on input paramters
        string apiURL = ApiBaseURL + "search.ashx?q=" + input.query + "&format=" + input.format + "&timezone=" + input.timezone + "&popular=" + input.popular + "&num_of_results=" + input.num_of_results + "&callback=" + input.callback + "&key=" + PremiumAPIKey;

        // get the web response
        string result = RequestHandler.Process(apiURL);

        // serialize the json output and parse in the helper class
        LocationSearch locationSearch = (LocationSearch) new JavaScriptSerializer().Deserialize(result, typeof(LocationSearch));

        return(locationSearch);
    }
Example #4
0
    protected void btnLocationSearchPremium_Click(object sender, EventArgs e)
    {
        // set input parameters for the API
        LocationSearchInput input = new LocationSearchInput();

        input.query          = txtLocation.Text;
        input.num_of_results = "2";
        input.format         = "JSON";

        if (!string.IsNullOrEmpty(input.query))
        {
            // call the location Search method with input parameters
            PremiumAPI     api            = new PremiumAPI();
            LocationSearch locationSearch = api.SearchLocation(input);

            // printing a few values to show how to get the output
            if (locationSearch.search_API != null && locationSearch.search_API.result != null)
            {
                txtOutput.Text = "";
                for (int i = 0; i < locationSearch.search_API.result.Count; i++)
                {
                    txtOutput.Text += "\r\n Area Name: " + locationSearch.search_API.result[i].areaName[0].value;
                    txtOutput.Text += "\r\n Country: " + locationSearch.search_API.result[i].country[0].value;
                    txtOutput.Text += "\r\n Latitude: " + locationSearch.search_API.result[i].latitude;
                    txtOutput.Text += "\r\n Longitude: " + locationSearch.search_API.result[i].longitude;
                    txtOutput.Text += "\r\n Population: " + locationSearch.search_API.result[i].population;
                    txtOutput.Text += "\r\n Region: " + locationSearch.search_API.result[i].region[0].value;
                    txtOutput.Text += "\r\n --------------------------";
                }
            }
            else
            {
                txtOutput.Text = "\r\n Something went wrong. Please make sure you entered city name!";
            }
        }
        else
        {
            txtOutput.Text = "\r\n Please enter location.";
        }
    }
Example #5
0
        public void Test_SearchLocationMethod()
        {
            LocationSearchInput input = new LocationSearchInput();

            Assert.IsNull(input.query);
        }
Example #6
0
 /// <summary>
 /// True if the search input applies to the model
 /// </summary>
 public bool SearchInputApplies(LocationSearchInput searchInput, LocationModel locationModel)
 {
     return(HasSearchText(locationModel, searchInput.SearchText) &&
            HasTag(locationModel, searchInput.Tag.Key));
 }
Example #7
0
 /// <summary>
 /// Searches the compendium for locations matching the search input
 /// </summary>
 public List <LocationModel> Search(LocationSearchInput searchInput)
 {
     return(Sort(_compendium.Locations.Where(x => SearchInputApplies(searchInput, x)), searchInput.SortOption.Key));
 }