Accessing asp or c# from VA Smalltalk

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Accessing asp or c# from VA Smalltalk

Postby PhotonDemon » Mon Aug 03, 2009 11:08 am

Hi All,

Is there a way of accessing asp or c# from VA Smalltalk?

What I really want to do is create a PDF file from within VA Smalltalk and Seaside. I am thinking that I can create the information as HTML by reusing many of my Seaside components. The HTML string can then be sent to a program like ABCpdf http://www.websupergoo.com/ that will convert it to a PDF file/string. ABCpdf is designed to be called from asp or c# in .net. Apparently if I could access asp or c# from VA Smalltalk, I could get ABCpdf to convert the HTML to PDF for me.

Any suggestions or ideas are greatly appreciated.

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: Accessing asp or c# from VA Smalltalk

Postby wembley » Mon Aug 03, 2009 11:16 am

Lou -

Have you looked at SpsPdfLib from VAStGoodies?
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
wembley
Moderator
 
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC

Re: Accessing asp or c# from VA Smalltalk

Postby marten » Mon Aug 03, 2009 9:59 pm

PhotonDemon wrote:Hi All,

Is there a way of accessing asp or c# from VA Smalltalk?

Lou


a) Write a C# wrapper around your C# library and make your wrapper COM aware ... then you might call it via OLE
b) Write a C# wrapper around your C# library, make it an executable and call it within an external thread ...
c) Write a C# wrapper around your C# library and call it via interprocess communication

Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Accessing asp or c# from VA Smalltalk

Postby PhotonDemon » Thu Aug 06, 2009 3:17 pm

Thank you John and Marten for your replies. I had not seen SpsPdfLib from VAStGoodies. It looks interesting but not quite what I would like.

It seems that ABCpdf can be accessed via OLE, so I think I could make an OLE warpper for it. Unfortunately, I know little about OLE or making a VA Smalltalk wrapper for OLE or about 'AddImageHTML' the ABCpdf function that I need to use.

I would greatly appreciated any examples.

Lou

P.S. The ABCpdf function, 'AddImageHTML' takes an HTML file or URL to HTML and makes a PDF file from it, including any cascading style sheets (CSS files) it references.
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: Accessing asp or c# from VA Smalltalk

Postby marten » Thu Aug 06, 2009 10:06 pm

It seems to be pretty straight forward. Load all "OLE" features into your image and the let it create the source code for that OLE component.

While the "OLE Class Generator" is open, select "other", select "ABCpdf7.Doc" from that list of available OLE components and create an "Object wrapper".

If you have done this you will have fast success with code like below. The code generates the first page of this forum software and produces a 52 KByte large pdf file ...

Code: Select all
exampleInstantiations
   "ABCpdf7Doc exampleInstantiations"
   
   | anInstance |
   
   anInstance := self new.
   
   anInstance
      createObject ;
      addImageUrl: 'http://www.instantiations.com/forum/viewforum.php?f=12'
      paged: true
      width: 600
      disableCache: true.
      
   anInstance
      save: 'e:\test.pdf'


I do not know, how good/bad the software is you have mentioned. I also do not know what difficulties you might expect here. The initial transformation seems to use IExporer to render the page. Another option seems to be an own build-in renderer.
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Accessing asp or c# from VA Smalltalk

Postby PhotonDemon » Fri Aug 07, 2009 7:40 am

Hey Marten,

Thank you very, very much. I was able to create the OLE wrapper and test it with the help of your sample code. I even changed the URL to point to my Seaside app and convert the first page to a PDF file. This isn't what I ultimately need to do but it is very impressive to see the results.

I have some other stuff to work on first but then I will create a subclass of Seaside's WAPresenter or WAComponent to create the HTML as a string. I will then hopefully be able to send the HTML string to the ABCpdf OLE wrapper and get the PDF result back as a string. I can then attach that PDF string to an email as an attachment.

So far I am very pleased with the results, so again, thank you very much :D

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: Accessing asp or c# from VA Smalltalk

Postby marten » Fri Aug 07, 2009 11:39 pm

The API function you mentioned in your first posting actually should do what you want. When using OLE solution do intensive testing and have a careful look about memory issues (increasing memory consumption).
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Accessing asp or c# from VA Smalltalk

Postby PhotonDemon » Wed Aug 12, 2009 2:54 pm

Hi Marten,

I'm sorry to bother you once again. The OleWrapped object you help with above has a method called #getData that should return the resultant PDF file as a string or at least a means of getting to the string data or byte array. It, #getData returns an #OSVariantarg, I expect this is an OS pointer of some type but I can't quite seem to figure out how to get to the string data. If you could find the time to give me one more example, I would greatly appreciate it.

Thanks, Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: Accessing asp or c# from VA Smalltalk

Postby marten » Wed Aug 12, 2009 10:17 pm

PhotonDemon wrote:Hi Marten,

I'm sorry to bother you once again. The OleWrapped object you help with above has a method called #getData that should return the resultant PDF file as a string or at least a means of getting to the string data or byte array. It, #getData returns an #OSVariantarg, I expect this is an OS pointer of some type but I can't quite seem to figure out how to get to the string data. If you could find the time to give me one more example, I would greatly appreciate it.

Thanks, Lou


I installed the stuff again and yes: the object returned is actually of type OSVariantarg. The subtype within this OSVariantarg is (Array | UI8) ( -> vt = 8209 -> 8192 | 17), which is an array of unsigned byte-wide numbers - or in a Smalltalk world: a ByteArray.

Now - how to get the content of the ByteArray:

1) From the OLE object you should retrieve the OLE object to hold an array (instance of OSSafearray):

anInstance getData parray

2) now ask the Safearray for its content:

anInstance getData parray asMSKByteArray

To get this work add the following two methods to OSSafearray:

Code: Select all
numberOfElements
   "^<Integer | AbtError> This method returns the number of elements in the structure. If an error occurs
      this method return an instance of AbtError
   "

   | numberOfElements numberOfDimensions  lowerBound upperBound errorFlag |
   
   numberOfElements := 0.
   errorFlag := false.
   lowerBound := OSInt32 calloc.
   upperBound :=  OSInt32 calloc.
   
   1 to: self safeArrayGetDim  do: [ :eachDimensionIndex |
      errorFlag := errorFlag | ((self   safeArrayGetLBound: eachDimensionIndex asParameter plLbound: lowerBound asParameter) ~= SOk).
      errorFlag := errorFlag | ((self   safeArrayGetUBound: eachDimensionIndex asParameter plUbound: upperBound asParameter) ~= SOk).
      errorFlag ifFalse:[ numberOfElements := numberOfElements + ((upperBound at: 0) - (lowerBound at:0) ) + 1 ]
   ].

   lowerBound free.
   upperBound free.

   ^errorFlag ifTrue:[ AbtError errorText: 'Error while retrieving number of elements in savearray' ] ifFalse:[ numberOfElements ].


Code: Select all
asMSKByteArray
   "^ <ByteArray> | <AbtError> Returns a byte array. The receiver is assumed to be a 1-dimensional array of
         unsigned byte values: VtUI8
        "
   
   | temp byteArray safeArrayCopy arrayAddress numberOfElements |
   
   (numberOfElements := self numberOfElements) isAbtError ifTrue:[ ^numberOfElements ].
   
   " Create a copy of the OSSafearray using the API in the OSSafearray instance. 'temp' will contain it"
   temp := ByteArray new: 4.
   self safeArrayCopy: temp.

   " Create a new instance of OSSafearray based on the address of the copy from the previous steps "
   safeArrayCopy := self class address: (temp uint32At: 0 ).
   
   " Get the data area (array contents) out of the safe array using the API in OSSafearray instance "

   temp := ByteArray new: 4.
   safeArrayCopy safeArrayAccessData: temp.
   
   " Statement below gets the address of the data array. For strings, this is an array of addresses "
   arrayAddress := temp uint32At: 0.   

   "for UI8 this seems to be a pointer to the memory, where the content is ..."
   byteArray := (OSPtr address: arrayAddress) memcpyFrom: 0 to: (numberOfElements - 1).

        "  this seems to be needed ??
           safeArrayCopy  safeArrayUnaccessData
        "

        ^byteArray


Especially in the last method I'm not sure, if there is a memory leak: safeArrayCopy - but that would need additional Google searches to find out ...

After all you will get a ByteArray with the PDF content ...

Just a warning: I'm not an expert in the OLE stuff and perhaps it can be done much more elegant or better or perhaps even correct (:-)) ... I just want to show a way how it could be done ....


Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Accessing asp or c# from VA Smalltalk

Postby PhotonDemon » Thu Aug 13, 2009 7:01 am

Hey Marten,

Thank you very much for the reply. I had gotten to the point of using #parray to get a #Safearray but couldn't get any farther than that.

I have to work on something else for a day or two and then will get back to this and will report on the results.

Thanks again, Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: Accessing asp or c# from VA Smalltalk

Postby PhotonDemon » Wed Aug 19, 2009 7:17 am

I am pleased to report that Marten's examples have allowed me to use ABCpdf via OLE. Thank you very much Marten.

To recap, I create a file of HTML using Seaside #Presenters and #Components (I haven't finished making this exactly the way it is needed but the basics are there) and point the OLE wrapper of ABCpdf at the file. A file is used because that allows the use of absolute links to CSS files that aid in the formatting of the HTML image and therefor the resultant PDF file. I get the PDF data from the OLE wrapper as a string and attach it to an email (generated via Totally Objects Socket Set). The ABCpdf OLE wrapper could have saved the PDF data as a file but I don't need the file, so I just used the string.

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest