Progress OpenEdge Examples
Praktische voorbeelden met Progress 4GL en OpenEdge ABL.
1. Bepaal de geo coördinaten in OpenEdge via Google Maps
/* get geo code via google maps */
USING System.Net.*.
USING Progress.Json.ObjectModel.*.
def var cLong as char no-undo.
def var cLat as char no-undo.
def var cAdres as char no-undo init "europlaan 22+amsterdam+nl". /* RAI amsterdam */
run ip_getgeocode( input cAdres, output cLat, Output cLong ).
message cLat cLong view-as alert-box.
procedure ip_getgeocode:
def input parameter cAddress as char no-undo.
def output parameter dLat as dec no-undo.
def output parameter dLong as dec no-undo.
def var cDownload as longchar no-undo .
def var geoArray as JsonArray no-undo.
def var jsonMessage as JsonObject no-undo.
def var jsonlocation as jsonobject no-undo.
def var cUrl as char no-undo.
def var cTmp as char no-undo.
def var oWebClient as CLASS WebClient no-undo.
def var oJsonParser as ObjectModelParser no-undo.
oWebClient = new Webclient().
oJsonParser = new ObjectModelParser( ).
/*owebClient:Headers:Add("CharSet", "UTF-8"). */
owebClient:Headers:Add("Charset", "text/html; charset=UTF-8").
oWebclient:Headers:Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" ).
cUrl = 'http://maps.googleapis.com/maps/api/geocode/json?address='
+ replace( cAddress, ' ', '%20' ) + '&sensor=false'.
cDownload = oWebclient:DownloadString (cUrl) no-error.
if error-status:error
then run ip_loggooglemapserror( cUrl + ' ' + ERROR-STATUS:GET-MESSAGE(1) ).
else copy-lob from cDownload to file ( session:temp-directory + 'lastgeocode.json') no-convert no-error.
JsonMessage = CAST(oJsonParser:Parse(cDownload), JsonObject).
geoArray = jsonmessage:GETJSONARRAY("results").
if geoarray:Length >= 1
then do:
jsonMESSAGE = geoarray:GETJSONOBJECT(1).
if jsonMESSAGE:has( "geometry" )
then do:
if jsonMESSAGE:GetJsonObject( "geometry" ):has( "location" )
then do:
cTmp = session:numeric-format.
session:numeric-format = 'American'.
jsonlocation = jsonMESSAGE:GetJsonObject( "geometry" ):getJsonObject( "location" ).
dLat = jsonlocation:GetDecimal("lat") .
dLong = jsonlocation:GetDecimal("lng" ).
session:numeric-format = cTmp.
end.
end.
end.
delete object oWebClient.
delete object oJsonParser.
end.
2. Bepaal de landcode van een ipadres met openedge en ip-api.com
/* get country code via ip-api */
USING System.*.
USING System.Web.*.
USING System.Net.*.
USING Progress.Json.ObjectModel.*.
def var oWebClient as CLASS WebClient no-undo.
def var oJsonParser as ObjectModelParser NO-UNDO.
def var cDownload as longchar no-undo.
def var cIpAddress as char no-undo format "x(20)" init "64.233.191.255".
def var cCountry as char no-undo.
define variable jsonMessage AS JsonObject NO-UNDO.
oJsonParser = NEW ObjectModelParser( ).
oWebClient = new Webclient().
owebClient:Headers:Add("Charset", "text/html; charset=UTF-8").
oWebclient:Headers:Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" ).
cDownload = oWebclient:DownloadString ( 'http://ip-api.com/json/' + cIpAddress ) no-error.
JsonMessage = CAST(oJsonParser:Parse(cDownload), JsonObject) no-error.
if jsonMessage:has("countryCode")
then cCountry = JsonMessage:GETCHARACTER( "countryCode" ).
else cCountry = "??".
delete object oWebClient.
delete object JSONMESSAGE.
delete object oJsonParser.
message cCountry.
3. Het ophalen van een willekeurige url / bestand via openedge van internet
/* download file from internet */
Via WebClient van .NET kun je eenvoudig een bestand van internet naar je toe halen, zie onderstaand voorbeeld voor het naar je toehalen van de foreach mainpage
/* download file from internet */
USING System.Net.*.
def var oWebClient as CLASS WebClient no-undo.
def var cUrl as char no-undo.
def var cDownload as longchar no-undo.
oWebClient = new Webclient().
owebClient:Headers:Add("Charset", "text/html; charset=UTF-8").
oWebclient:Headers:Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" ).
cUrl = 'https://www.foreach.nl' . /* file to download */
cDownload = oWebclient:DownloadString (cUrl) no-error.
/* save as local file
copy-lob from cDownload to file ('c:/temp/mainpage.html') no-convert.
*/
message string(cDownload) view-as alert-box.
delete object owebclient.