Please Help me convert .NET from C# to RDML.

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Welcome
Posts: 16
Joined: Mon May 08, 2017 3:15 pm

Please Help me convert .NET from C# to RDML.

Post by Welcome » Thu Jun 01, 2017 12:43 pm

Dear Eeveryone.
i need you help to convert .net c# code to RDML.
thank you..

c# .net code.

var url = String.Format("http://maps.google.com/maps/api/geocode ... address={0}", address);

string result = String.Empty;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
using (var response = request.GetResponse())
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
//Json格式: 請參考http://code.google.com/intl/zh-TW/apis/maps/documentation/geocoding/
result = sr.ReadToEnd();
}

jyoung
Posts: 667
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Please Help me convert .NET from C# to RDML.

Post by jyoung » Thu Jun 01, 2017 11:47 pm

It looks like you are trying to get the geocode from Google Maps.

The concept is similar to how it is done in .NET. Format the request, execute it and handle the response.

The first thing you need to do is format the Request. If you are on a web component, you can use #PRIM_WEB.HttpRequest. If you are on a server component, you are going to have to use Integrator.

Assuming you are on a web component, define the request as such

Code: Select all

define_com class(#PRIM_WEB.HttpRequest) name(#Request)
Then you can format the address and url and execute it

Code: Select all

mthroutine name(Load)
define_map for(*INPUT) class(#STD_STRNG) name(#caption)
define_map for(*INPUT) class(#STD_STRNG) name(#line1)
define_map for(*INPUT) class(#STD_STRNG) name(#city)
define_map for(*INPUT) class(#STD_STRNG) name(#state)
define_map for(*INPUT) class(#STD_STRNG) name(#postCode)
define_map for(*INPUT) class(#STD_STRNG) name(#country)

#AddressCaption := #caption

#Address := ("&1,&2,&3,&4,&5").Substitute( #line1 #city #state #postCode #country )
#Address := #Address.ReplaceAll( " " "+" )

if (#Address = *BLANKS)
return
endif

#SYS_APPLN.TraceMessageText( "Executing GeoCode" )
#Request.Url := "https://maps.googleapis.com/maps/api/geocode/json?address=" + #Address + "&key=" + #ApiKey

#Request.ExecuteAsync

endroutine
Then when you handle the request, you need to parse out the JSON response (ignore the widget timer, the important bit is the UpdateMap call)

Code: Select all

evtroutine handling(#Request.Completed)
#SYS_APPLN.TraceMessageText( "GeoCode Completed" )

if ((#Request.Response *IsNot *NULL) *And (#Request.Response.StatusCode = 200))
#Json := #Request.Response.Content

if (#WidgetInitialized)
#COM_OWNER.UpdateMap( #Json.RootItem<"results">.ItemAt<1> )
else
#SYS_APPLN.TraceMessageText( "Widget not initialized. Starting Timer" )
#WidgetTimer.Start
endif
else
#SYS_APPLN.TraceMessageText( "NULL Response from GeoCoding API" )
endif
endroutine
Then you can do what you need to with the data (a #PRIM_WEB.JSONElement). Here I am updating the GoogleMapWidget with the response data.

Code: Select all

mthroutine name(UpdateMap) access(*PRIVATE)
define_map for(*INPUT) class(#PRIM_WEB.JsonElement) name(#data) pass(*BY_REFERENCE)

define_com class(#PRIM_WEB.JsonElement) name(#location) reference(*DYNAMIC)

#SYS_APPLN.TraceMessageText( "Updating Map" )

if (#data *IsNot *NULL)

#location <= #data<"geometry">.Item<"location">

#wk_Longitude := #location<"lng">.AsNumber
#wk_Latitude := #location<"lat">.AsNumber

#SYS_APPLN.TraceMessageText( ("Latitude: &1 Longitude:&2").Substitute( #wk_Latitude.AsString #wk_Longitude.AsString ) )

#GoogleMapWidget.AddMarker caption(#AddressCaption) longitude(#wk_Longitude) latitude(#wk_Latitude) data(#Address)
#GoogleMapWidget.Center latitude(#wk_Latitude) longitude(#wk_Longitude)

signal event(MapUpdated)
else
#SYS_APPLN.TraceMessageText( "Map data is null" )
signal event(MissingData)
endif

endroutine
Hope this helps,
Joe

Welcome
Posts: 16
Joined: Mon May 08, 2017 3:15 pm

Re: Please Help me convert .NET from C# to RDML.

Post by Welcome » Mon Jun 05, 2017 12:33 pm

Thank you for your reply..
but now ,i want to coding Visual Lansa Windows form.
How can i doing?

Thank you..

jyoung
Posts: 667
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Please Help me convert .NET from C# to RDML.

Post by jyoung » Mon Jun 05, 2017 11:37 pm

Unfortunately PRIM_WEB.HttpRequest is only available on web components.

If you are trying to do this on a Server or Windows client, then you may be able to use Integrator's HttpService. http://docs.lansa.com/14/EN/lansa093/in ... 7_0115.htm

I don't work with Windows Forms so I don't know if you can use Integrator like that but it may be worth a try.

Welcome
Posts: 16
Joined: Mon May 08, 2017 3:15 pm

Re: Please Help me convert .NET from C# to RDML.

Post by Welcome » Wed Jun 07, 2017 11:06 am

Thanks so much...
nice day to you.

tsupartono

Re: Please Help me convert .NET from C# to RDML.

Post by tsupartono » Thu Jun 08, 2017 8:03 am

You may also want to wait for the next EPC (scheduled to come out in a few days).
This EPC lets you easily consume web services natively from your RDMLX code.

Welcome
Posts: 16
Joined: Mon May 08, 2017 3:15 pm

Re: Please Help me convert .NET from C# to RDML.

Post by Welcome » Thu Jun 08, 2017 4:45 pm

*
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(487) Clientwidth(784) Height(526) Left(565) Top(170) Visualstyle(#VS_NORM) Width(800) Windowstate(Maximized)

Define_Com Class(#ZSYS.System.Uri) Name(#uri) Reference(*DYNAMIC)
Define_Com Class(#zsys.System.Net.WebRequest) Name(#request) Reference(*DYNAMIC)
Define_Com Class(#zsys.System.Net.WebResponse) Name(#response) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.XDocument) Name(#Doc) Reference(*DYNAMIC)
* Define_Com Class(#zsys.System.Xml.XmlDocument) Name(#Doc) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.XElement) Name(#locationElement) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.XElement) Name(#lat) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.XElement) Name(#lng) Reference(*DYNAMIC)

Define_Com Class(#LINQ.System.XML.Linq.Xname) Name(#GeocodeResponse) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.Xname) Name(#result) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.Xname) Name(#geometry) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.Xname) Name(#location) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.Xname) Name(#zlat) Reference(*DYNAMIC)
Define_Com Class(#LINQ.System.XML.Linq.Xname) Name(#zlng) Reference(*DYNAMIC)

Define_Com Class(#VSAADDR.Visual) Name(#VSAADDR) Displayposition(1) Left(76) Parent(#COM_OWNER) Tabposition(1) Top(73) Height(24)
Define_Com Class(#VSALGTD.Visual) Name(#VSALGTD) Displayposition(2) Left(73) Parent(#COM_OWNER) Tabposition(2) Top(135)
Define_Com Class(#VSALTTD.Visual) Name(#VSALTTD) Displayposition(3) Left(72) Parent(#COM_OWNER) Tabposition(3) Top(175)
Define_Com Class(#PRIM_PHBN) Name(#Button1) Displayposition(4) Left(203) Parent(#COM_OWNER) Tabposition(4) Top(296) Width(158) Caption('GET')

Define Field(#address) Type(*string) Length(256)


*
*
Define Field(#requestUri) Type(*string) Length(1024)
Define Field(#latitude) Type(*string) Length(50)
Define Field(#longitude) Type(*string) Length(50)

Evtroutine Handling(#com_owner.Initialize)
Set Com(#com_owner) Caption(*component_desc)
Endroutine

Subroutine Name(SUBGET)
#address := #VSAADDR.AsNativeString
#requestUri := "http://maps.googleapis.com/maps/api/geo ... nsor=false"
#requestUri := #requestUri.Substitute( #uri.EscapeUriString( #address ) )
#request <= #request.Create( #requestUri )
#response <= #request.GetResponse()

#Doc <= #Doc.Load#2( #response.GetResponseStream() )
#GeocodeResponse <= #GeocodeResponse.Get( 'GeocodeResponse' )
#result <= #result.Get( 'result' )
#geometry <= #geometry.get( 'geometry' )
#location <= #location.get( 'location' )
#zlat <= #zlat.get( 'lat' )
#zlng <= #zlng.get( 'lng' )

#lat <= #Doc.Element( #GeocodeResponse ).Element( #result ).Element( #geometry ).Element( #location ).Element( #zlat )
#lng <= #Doc.Element( #GeocodeResponse ).Element( #result ).Element( #geometry ).Element( #location ).Element( #zlng )

#VSALTTD := #lat.ToString.ReplaceAll( '<lat>' '' ).ReplaceAll( '</lat>' '' ).AsNumber
#VSALGTD := #lng.ToString.ReplaceAll( '<lng>' '' ).ReplaceAll( '</lng>' '' ).AsNumber
#Doc <= *null
Endroutine

Evtroutine Handling(#Button1.Click)
Execute Subroutine(SUBGET)
Endroutine
End_Com

Post Reply