Example #1
0
        public async Task <List <Card> > QueryJobPosting(int fromNumber, string keywords, int size)
        {
            var client = new HttpClient();

            HttpResponseMessage response = null;
            RootDSLObject       dsl      = new RootDSLObject();

            try
            {
                dsl.from               = fromNumber;
                dsl.size               = size;
                dsl.query              = new Query();
                dsl.query.@bool        = new Bool();
                [email protected]   = new List <Must>();
                [email protected] = new List <Filter>();
                [email protected](new Must
                {
                    match = new
                    {
                        Answer = keywords
                    }
                });

                [email protected](new Must
                {
                    match = new
                    {
                        Question = keywords
                    }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            var json = JsonConvert.SerializeObject(dsl);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            response = await client.PostAsync(baseUrl + "_search", data);

            var result = response.Content.ReadAsStringAsync().Result;

            try
            {
                RootResponseObject list = JsonConvert
                                          .DeserializeObject <RootResponseObject>(result);
                List <Card> listsCards = new List <Card>();
                foreach (var item in list.hits.hits)
                {
                    listsCards.Add(item._source);
                }
                return(listsCards);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                return(new List <Card>());
            }
        }
Example #2
0
        /// <summary>
        /// Makes a REST call using the serialized RootObject and returns the json results into the RootObject
        /// </summary>
        /// <param name="rootRequestObject">The object to serialize and send in the REST call</param>
        /// <param name="token">The token to use in the REST call to ArcGIS</param>
        /// <returns>The object to deserialize after making the REST call</returns>
        public static RootResponseObject GeocodeABatchOfAddresses(RootRequestObject rootRequestObject, string token)
        {
            string jsonAddressRequest = "addresses=" + JsonConvert.SerializeObject(rootRequestObject);

            string endPoint = String.Format(
                ConfigurationManager.AppSettings["arcGISBaseAddress"].ToString(CultureInfo.InvariantCulture) +
                "/arcgis/rest/services/Geocode/USA/GeocodeServer/geocodeAddresses",
                token);
            var client = new RestfulGeocoder.HttpUtils.HttpUtils(endPoint, HttpVerb.Post, jsonAddressRequest);

            client.ContentType = "application/x-www-form-urlencoded";
            var json = client.MakeRequest(String.Format("?sourceCountry=USA&token={0}&f=json", token));

            RootResponseObject rootResponseObject = JsonConvert.DeserializeObject <RootResponseObject>(json);

            if (rootResponseObject.locations == null)
            {
                GeoCodeAddresses.Log.Debug(String.Format("rootResponseObject.locations is null"));
            }
            else
            {
                GeoCodeAddresses.Log.Debug(String.Format("GeocodeABatchOfAddresses: rootResponseObject.locations.Count = {0}",
                                                         rootResponseObject.locations.Count));
            }

            return(rootResponseObject);
        }
Example #3
0
        /// <summary>
        /// Geocodes all addresses in Dimension.Location table
        /// </summary>
        public static void GeocodeAllAddresses()
        {
            GeoDatabaser       geoDatabaser = new GeoDatabaser();
            RootResponseObject root         = new RootResponseObject();
            List <Location>    locations    = new List <Location>();

            root.locations = locations;
            int locationCount = 0;

            // Get a new token every x batches based on appConfig key.
            // Token expires every 60 minutes according to ArcGIS Server settings
            geoCodeAddresses.GetToken(BatchesProcessed);

            RootRequestObject  rootRequestObject  = new RootRequestObject();
            RootResponseObject rootResponseObject = new RootResponseObject();

            rootRequestObject = geoDatabaser.GetBatchOfNonGeocodedAddressesFromDatabase(rootRequestObject);

            if (rootRequestObject.records.Count != 0)
            {
                rootResponseObject = RestServices.GeocodeABatchOfAddresses(rootRequestObject, Token);

                if (rootResponseObject.locations != null)
                {
                    Log.Info(
                        String.Format("rootResponseObject.locations.count = {0}",
                                      rootResponseObject.locations.Count));
                    AddressesProcessed += rootResponseObject.locations.Count;
                    foreach (Location location in rootResponseObject.locations)
                    {
                        Log.Debug(String.Format("Location Info: x: {0} y: {1} score: {2} address: {3}",
                                                location.location.x, location.location.y, location.score, location.address));
                        if (!(location.location.x > 0 || location.location.x < 0) &&
                            !(location.location.y > 0 || location.location.y < 0))
                        {
                            location.location.x = null;
                            location.location.y = null;
                        }
                        root.locations.Add(new Location());
                        locations[locationCount] = location;
                        locationCount++;
                    }
                    geoDatabaser.InsertBatchOfGeocodedAddressesToDatabase(root);
                    root.locations.Clear();
                }
                else
                {
                    Log.Debug(
                        String.Format("rootResponseObject is null"));
                }
            }
        }
Example #4
0
        /// <summary>
        /// Performs a bulk insert into the database with the current batch of addresses
        /// </summary>
        /// <param name="rootResponseObject">The C# objectified response from ArcGIS</param>
        public void InsertBatchOfGeocodedAddressesToDatabase(RootResponseObject rootResponseObject)
        {
            GeoCodeAddresses.Log.Debug(String.Format("Insert batch of geocoded addresses to database: \n" +
                                                     "rootResponseObject.Count = {0}",
                                                     rootResponseObject.locations.Count));
            DataTable geoCodedDataTableLocations =
                Utility.Utility.ConvertRootResponseToDataTable <RootResponseObject>(rootResponseObject);

            GeoCodeAddresses.Log.Debug(String.Format("Convert Root Response to DataTable: \n" +
                                                     "geoCodedDataTableLocations.Rows.Count = {0}\n" +
                                                     "geoCodedDataTableLocations.Columns.Count = {1}",
                                                     geoCodedDataTableLocations.Rows.Count, geoCodedDataTableLocations.Columns.Count));
            var columnMappings = new List <string>
            {
                "EID,EID", "PointX,PointX", "PointY,PointY",
                "score,score",
                "address,address", "Loc_name,Loc_name", "Status,Status", "Match_Addr,Match_Addr", "Addr_Type,Addr_Type",
                "PlaceName,PlaceName", "Place_addr,Place_addr", "Rank,Rank", "AddBldg,AddBldg", "AddNum,AddNum",
                "AddNumFrom,AddNumFrom", "AddNumTo,AddNumTo", "Side,Side", "StPreDir,StPreDir", "StPreType,StPreType",
                "StName,StName", "StType,StType", "StDir,StDir", "StAddr,StAddr", "Nbrhd,Nbrhd", "City,City",
                "Subregion,Subregion", "Region,Region", "Postal,Postal", "PostalExt,PostalExt", "Country,Country",
                "LangCode,LangCode", "Distance,Distance", "X,X", "Y,Y", "DisplayX,DisplayX", "DisplayY,DisplayY",
                "Xmin,Xmin", "Xmax,Xmax", "Ymin,Ymin", "Ymax,Ymax"
            };

            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                var bulkCopy = new SqlBulkCopy(connection)
                {
                    DestinationTableName =
                        ConfigurationManager.AppSettings["destinationTableName"].ToString(CultureInfo.InvariantCulture)
                };
                BatchBulkCopy(geoCodedDataTableLocations, bulkCopy.DestinationTableName,
                              GeoCodeAddresses.Form.GetNumAddressesPerBatch(), columnMappings);
            }
        }
Example #5
0
        public async Task <List <Card> > QueryJobPosting(int fromNumber, string keywords, int size, CardType?cardType)
        {
            var    client = new HttpClient();
            string result = "";
            HttpResponseMessage response = null;

            if (string.IsNullOrEmpty(keywords.Replace(" ", "")))
            {
                string finalQueryString = baseUrl + "_search?" + "q=Type:" + (int)cardType + "&from=" + fromNumber + "&size=" + size;
                response = await client.GetAsync(finalQueryString);

                result = response.Content.ReadAsStringAsync().Result;
            }
            else
            {
                RootDSLObject dsl = new RootDSLObject();
                try
                {
                    dsl.from               = fromNumber;
                    dsl.size               = size;
                    dsl.query              = new Query();
                    dsl.query.@bool        = new Bool();
                    [email protected]   = new List <Must>();
                    [email protected] = new List <Filter>();
                    [email protected](new Must
                    {
                        match = new
                        {
                            Answer = keywords
                        }
                    });

                    [email protected](new Must
                    {
                        match = new
                        {
                            Question = keywords
                        }
                    });
                    [email protected](new Filter
                    {
                        term = new
                        {
                            Type = cardType
                        }
                    });
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                var json = JsonConvert.SerializeObject(dsl);
                var data = new StringContent(json, Encoding.UTF8, "application/json");
                response = await client.PostAsync(baseUrl + "_search", data);

                result = response.Content.ReadAsStringAsync().Result;
            }



            try
            {
                RootResponseObject list = JsonConvert
                                          .DeserializeObject <RootResponseObject>(result);
                List <Card> listsCards = new List <Card>();
                foreach (var item in list.hits.hits)
                {
                    listsCards.Add(item._source);
                }
                return(listsCards);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                return(new List <Card>());
            }
        }
Example #6
0
        /// <summary>
        /// Converts the RootResponse object from the REST call into a DataTable
        /// </summary>
        /// <typeparam name="T">The type of object to convert</typeparam>
        /// <param name="rootResponseObject">The object to convert</param>
        /// <returns>The DataTable</returns>
        public static DataTable ConvertRootResponseToDataTable <T>(RootResponseObject rootResponseObject)
        {
            DataTable responseTable = new DataTable();

            responseTable.Columns.Add("EID");
            responseTable.Columns.Add("PointX");
            responseTable.Columns.Add("PointY");
            responseTable.Columns.Add("score");
            responseTable.Columns.Add("address");
            responseTable.Columns.Add("Loc_name");
            responseTable.Columns.Add("Status");
            responseTable.Columns.Add("Match_Addr");
            responseTable.Columns.Add("Addr_Type");
            responseTable.Columns.Add("PlaceName");
            responseTable.Columns.Add("Place_addr");
            responseTable.Columns.Add("Rank");
            responseTable.Columns.Add("AddBldg");
            responseTable.Columns.Add("AddNum");
            responseTable.Columns.Add("AddNumFrom");
            responseTable.Columns.Add("AddNumTo");
            responseTable.Columns.Add("Side");
            responseTable.Columns.Add("StPreDir");
            responseTable.Columns.Add("StPreType");
            responseTable.Columns.Add("StName");
            responseTable.Columns.Add("StType");
            responseTable.Columns.Add("StDir");
            responseTable.Columns.Add("StAddr");
            responseTable.Columns.Add("Nbrhd");
            responseTable.Columns.Add("City");
            responseTable.Columns.Add("Subregion");
            responseTable.Columns.Add("Region");
            responseTable.Columns.Add("Postal");
            responseTable.Columns.Add("PostalExt");
            responseTable.Columns.Add("Country");
            responseTable.Columns.Add("LangCode");
            responseTable.Columns.Add("Distance");
            responseTable.Columns.Add("X");
            responseTable.Columns.Add("Y");
            responseTable.Columns.Add("DisplayX");
            responseTable.Columns.Add("DisplayY");
            responseTable.Columns.Add("Xmin");
            responseTable.Columns.Add("Xmax");
            responseTable.Columns.Add("Ymin");
            responseTable.Columns.Add("Ymax");

            foreach (Location location in rootResponseObject.locations)
            {
                if ((location.location.x > 0 || location.location.x < 0) && (location.location.y > 0 || location.location.y < 0))
                {
                    responseTable.Rows.Add(new object[]
                    {
                        location.attributes.ResultID,
                        location.location.x,
                        location.location.y,
                        location.score,
                        location.address,
                        location.attributes.Loc_name,
                        location.attributes.Status,
                        location.attributes.Match_addr,
                        location.attributes.Addr_type,
                        location.attributes.PlaceName,
                        location.attributes.Place_addr,
                        location.attributes.Rank,
                        location.attributes.AddBldg,
                        location.attributes.AddNum,
                        location.attributes.AddNumFrom,
                        location.attributes.AddNumTo,
                        location.attributes.Side,
                        location.attributes.StPreDir,
                        location.attributes.StPreType,
                        location.attributes.StName,
                        location.attributes.StType,
                        location.attributes.StDir,
                        location.attributes.StAddr,
                        location.attributes.Nbrhd,
                        location.attributes.City,
                        location.attributes.Subregion,
                        location.attributes.Region,
                        location.attributes.Postal,
                        location.attributes.PostalExt,
                        location.attributes.Country,
                        location.attributes.LangCode,
                        location.attributes.Distance,
                        location.attributes.X,
                        location.attributes.Y,
                        location.attributes.DisplayX,
                        location.attributes.DisplayY,
                        location.attributes.Xmin,
                        location.attributes.Xmax,
                        location.attributes.Ymin,
                        location.attributes.Ymax
                    });
                }
            }

            return(responseTable);
        }