Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, May 18, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix .NET Extensions
Forum to discuss the use of .NET Extensions in SalesLogix version 7 and higher. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix .NET Extensions | New ThreadView:  Search:  
 Author  Thread: Implementing a Statis Class .Net Extension in SalesLogix
Jeff Weight
Posts: 219
 
Implementing a Statis Class .Net Extension in SalesLogixYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jun 07 2:09 PM
We are trying to implement a .Net DLL that was in use in other parts of the company for a little while. To implement the features of this DLL in SalesLogix, we implemented a webservice that can call the functions in the DLL. We are now finding limitations to that approach, and we need to just implement the darn DLL. So, I got all excited that I would get to play with .Net Extensions, and I loaded the DLL and released it (while reading Ryan's article on this website, of course). I then went into the VBScript on the form, and tried to run it. I immediately got an error about not finding the constructor, so I asked the developer of this DLL what he thought was going on. He told me it was a static class without a constructor.

So, can I still use this DLL? Or do I need to create a wrapper DLL to implement it? I also tried looking into just using CreateObject or GetObject in VBScript, but I'm not getting far on that either, and I have no idea if it will work. Out of these options, I would prefer to do the wrapper DLL last, but I guess I'll have to see if that is my only option. And if I need to build a wrapper dll, does it need to inherit from the BaseRunnable class? I don't need it to be "SalesLogix Aware."
Any ideas? Thank you for your help.
[Reply][Quote]
Jeff Weight
Posts: 219
 
Re: Implementing a Statis Class .Net Extension in SalesLogixYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jun 07 4:24 PM
Ok, so I am trying out a wrapper class/dll to solve my little problem. I went through Ryan's article again, but something isn't working.

Here is my .Net code:
Imports Sage.SalesLogix.NetExtensions
Imports EMI.DAL.Shared
Imports System.Windows.Forms

Public Class CCSecurity
Inherits Sage.SalesLogix.NetExtensions.BaseRunnable

Public Overrides Function Run(ByVal Args() As Object) As Object
MessageBox.Show("I'm In!", ".NET MessageBox")
Return Nothing
End Function

Public Function DALEncrypt(ByVal strValue As String) As String
Return Util.Encrypt(strValue)
End Function

Public Function DALDecrypt(ByVal strValue As String) As String
Return Util.Decrypt(strValue)
End Function
End Class

Here is my call in SalesLogix:
Dim objShared
Set objShared = Application.Managed.Create("SLXCCSecurity", "SLXCCSecurity.CCSecurity")
Application.Managed.Run objShared, Empty
txtCard.Text = objShared.DALDecrypt(txtDBCard.Text)
Application.Managed.Destroy objShared

I am getting the error: Object required: '[string: "de90c804dff74dd08f60"]'

Anyone know what I am doing wrong? If I remove the "y" on the classname and make it CCSecurit, then it gives me an error saying the class name isn't found - so I know I'm getting in there at least a little bit...
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Implementing a Statis Class .Net Extension in SalesLogixYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 19 Jun 07 7:04 AM
Did you include the assembly that includes your util class and any of its dependencies. AFAIK you will need to provide all non .net 2.0 framework assemblies as well to ensure proper typeloading. Just a thought.

Mark
[Reply][Quote]
Jeff Weight
Posts: 219
 
Re: Implementing a Statis Class .Net Extension in SalesLogixYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 19 Jun 07 10:38 AM
Thank you for responding, Mark! I appreciate your assistance. I took a look at what you mentioned, and there were other dlls surrounding the one dependent one that I had, so I moved all of them over to try them out - unfortunately, that didn't help me at all.

However, I did figure it out! I'm still pretty excited to get it working. Apparently I didn't read Ryan's article well enough... I had the following line:
Set objShared = Application.Managed.Create("SLXCCSecurity", "SLXCCSecurity.CCSecurity")
I should have removed the "Set" at the beginning - old habits, I guess. Once I removed that "Set," the code ran through - and then stopped at
txtCard.Text = objShared.DALDecrypt(txtDBCard.Text)
It told me that an object was required on objShared - which is due to not using the "Set" syntax. I felt at a loss again, but this time I was able to circumvent it. Here's the new code for the DLL:

Imports Sage.SalesLogix.NetExtensions
Imports EMI.DAL.Shared
Imports System.Windows.Forms

Public Class CCSecurity
Inherits Sage.SalesLogix.NetExtensions.BaseRunnable

Public Overrides Function Run(ByVal Args() As Object) As Object
Dim strNewValue As String = ""
Select Case Args(0)
Case "Decrypt"
strNewValue = DALDecrypt(Args(1))
Case "Encrypt"
strNewValue = DALEncrypt(Args(1))
End Select
Return strNewValue
End Function

Private Function DALEncrypt(ByVal strValue As String) As String
Return Util.Encrypt(strValue)
End Function

Private Function DALDecrypt(ByVal strValue As String) As String
Return Util.Decrypt(strValue)
End Function
End Class

Here's my SalesLogix code:
Dim objShared, argArray
argArray = Array("Decrypt", txtDBCard.Text)
objShared = Application.Managed.Create("SLXCCSecurity", "SLXCCSecurity.CCSecurity")
txtCard.Text = Application.Managed.Run(objShared, argArray)
Application.Managed.Destroy objShared

I basically just passed the arguments to the Run function in the DLL and passed back the decrypted text.

And it worked!!! I was so happy.

However, I am concerned about the workaround I just did. Is it possible to call methods from classes when implementing a .Net extension in this manner? Both methods were Public when I tried it out - I just set them as Private when I realized it wouldn't work and moved to my current solution.

Thanks again,
Jeff
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Implementing a Statis Class .Net Extension in SalesLogixYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Oct 07 8:37 AM
Sorry for getting back so late, I did not realize that there was a question attached.

Your solution is fine and actually provides less work on the SLX side. Since the Run method has to be invoked to get the .net instance that you would be working on there would be more work for you to complete. Invoke run, get .net instance object, invoke method. Basically you created a Facade (Pattern) around your .net functionality simplifying the request in to one call. In this case it does not really make sense to get a .net object and then call a method on it as well when all you are really doing is marshalling strings back and forth.

Mark
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Implementing a Statis Class .Net Extension in SalesLogixYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Oct 07 8:46 AM
Jeff,

I was just reviewing the code again and for those that have not jumped into the .net extension pool I wanted to highlight a few things.

1. objShared is actually a guid, for our purposes a string that uniquely identifies the .next extension in an internal hashtable
2. The Application.Managed.Create will return this guid only if the specific plugin is found and also the type is correctly resolved, you should not use the set keyword as a string is being passed back
3. Testing the objShared guid using IsEmpty will guard against invalid guid and let you know if it could not find the .net extension
4. Calling the Application.Managed.Run objShared can return a .net object and set should be used here if it is expected.
5. Since objShared is actually a string it is impossible to call your .net methods off of it. Hence the problems that were occurring.

Code should look like

dim guid, instance
guid = Application.Managed.Create("SLCCSecurity", "SLXCCSecurity.CCSecurity")
if not IsEmpty(guid)
set instance = Application.Managed.Run(guid)
if not instance is nothing then
txtCard.Text = instance.DALDecrypt(txtDBCard.Text)
end if
Application.Managed.Destroy guid
end if


Make sense
[Reply][Quote]
Jeff Weight
Posts: 219
 
Re: Implementing a Statis Class .Net Extension in SalesLogixYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Oct 07 10:21 AM
That does make sense, and thank you for responding to my question, even if it is almost four months later

In the context that I use it in, I guess it does make more sense to do it the way I did, but I know that I'll really want to access the .Net functions at some point. I was really beginning to think that couldn't be done until you responded. Thank you again for replying.

And this is quite the dog thread we have going here... Non-dog people need not post
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 5/18/2024 2:47:28 AM