1. Andrew Davis
  2. PowerBuilder
  3. Monday, 13 April 2020 14:12 PM UTC

Hi there

Is there any more information available on using the .net importer tool, any example work throughs or anything like that= showing from start to finish importing and using would be awesome

Has anyone successfully used it and got an example maybe ?

thanks in advance

Andrew

 

Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Monday, 13 April 2020 15:04 PM UTC
  2. PowerBuilder
  3. # 1

This Answers here might be useful as well as reading through the product documentation: https://community.appeon.com/index.php/qna/q-a/accessing-net-nested-class

Comment
  1. Armeen Mazda @Appeon
  2. Monday, 13 April 2020 17:41 PM UTC
Not yet. When it is available it will be posted to our GitHub account: https://github.com/Appeon

It should be done soon... maybe a week or so. Please check back.
  1. Helpful
  1. Andrew Davis
  2. Sunday, 5 July 2020 12:41 PM UTC
Armeen, I hope you are well, is the test application available to download yet ? or any more examples please
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Monday, 6 July 2020 16:15 PM UTC
  1. Helpful
There are no comments made yet.
Bruce Armstrong Accepted Answer Pending Moderation
  1. Tuesday, 14 April 2020 03:16 AM UTC
  2. PowerBuilder
  3. # 2

I'm working on one ( a sample that is ).  My favorite topic, sending SMTP email.  I find that you can't directly import most .Net mail libraries.  Instead, I wrote a wrapper class and then imported that.  Microsoft has deprecated their own SmtpClient class in favor of an open source package (MailKit), so I used that.

C# Code looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;

namespace AssemblyDemo
{
    public class MailClient
    {

        public string userEmail
        { private get; set; }
        
        public string password
        { private get; set; }
        
        public string userName
        { private get; set; }
        
        public string subject
        { private get; set; }
        
        public string body
        { private get; set; }

        private MailRecipient to;

        public int setRecipient( string name, string address )
        {
            to = new MailRecipient();
            this.to.name = name;
            this.to.address = address;
            return 1;
        }

        public int sendMail()
        {
            var message = new MimeMessage();            
            message.From.Add(new MailboxAddress(userName, userEmail));
            message.To.Add(new MailboxAddress(to.name, to.address));
            message.Subject = subject;
            message.Body = new TextPart("plain") { Text = body };
            using (var client = new SmtpClient())
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                client.Connect("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
                client.Authenticate(userEmail,password);
                client.Send(message);
                client.Disconnect(true);
            }
            return 1;
        }
    }

    public class MailRecipient
    {
        public string address
        { get; set; }
        
        public string name
        { get; set; }
        
    }
    
    
}

I run the .Net Importer on that and get a nvo_mailclient class.  I chose the options in the Advanced section to encapsulate each DotNetAssemblyClass in a DotNetObject and to incorporate try catch error handling in the DotNetObject.

I declare the nvo_mailclient as an instance variable on the window, because I want to reference it in the error handling:

nvo_mailclient mailclient 

In the open event of the window, I instantiate the nvo and then call the of_seterrorhandler to point to the window:

mailclient = create nvo_mailclient
mailclient.of_seterrorhandler( this, 'assemblyerror' )

In the close event I destroy the instance variable (not shown).  In the custom 'assemblyerror' event, I display any exceptions raised by the assembly to the user.

MessageBox ( "Error", mailclient.is_errortext )

I have a datawindow on the window that has tentry columns for the user email, user name, recipient email, recipient name, user password, mail subject and mail body.  Then I have a function that reads the values and interacts with the assembly through the nvo:

mailclient.of_set_body( dw_1.getItemString ( 1, "messagebody"))
mailclient.of_set_password( dw_1.getItemString( 1, "password"))
mailclient.of_set_subject( dw_1.getItemString ( 1, "subject" ))
mailclient.of_set_useremail( dw_1.getItemString ( 1, "fromaddress"))
mailclient.of_set_username( dw_1.getItemString( 1, "fromname" ))
mailclient.of_setrecipient( dw_1.getItemString( 1, "toname"), dw_1.getItemString( 1, "toaddress" ))
SetPointer ( HourGlass! )
mailclient.of_sendmail( )

This particular example was designed to use Google mail, hence the username/password authentication and SSl.

In order to use this in a deployed application you would need to distribute the wrapper assembly and all the assemblies that it references.  That would include MailKit.dll, MimeKit.dll, System.Text.Encoding.Codepages.dll and BouncyCastle.Crypto.dll.

What's nice about this approach is that all you need to do is deploy them all in the directory that your application is in. No more dealing with the GAC, REGASM, registry entries, manifest files, etc.  You also don't have to deal with the late binding issues involved with COM Callable Wrappers.


Comment
  1. Andrew Davis
  2. Thursday, 16 April 2020 15:35 PM UTC
Bruce



Many thanks as always, do you have this in a pbl you could make available ?
  1. Helpful
  1. Andrew Davis
  2. Wednesday, 22 April 2020 08:13 AM UTC
thanks so much - i will try it out
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.