1. Arcady Abramov
  2. Beta Testing
  3. Monday, 13 January 2020 11:19 AM UTC

Hello, team

It was not clear in the documentation if it is possible to load c# assemblies from different directories in run time.

For example, I have a local PB application running on user's C drive and I wish it to load different assemblies from different locations (So, IT would be able to only change parts of the application when required, instead of upgrading the whole 500MB package).

Thank you

Arcady

Accepted Answer
Arcady Abramov Accepted Answer Pending Moderation
  1. Sunday, 19 January 2020 06:55 AM UTC
  2. Beta Testing
  3. # Permalink

Where can find tutorial for C# migration?

I am having trouble with string extensions. 

For example, this is the translation of simple PB code: pos = Pos(ln_app_info, '=')

//---------------------------------

pos = ln_app_info.Pos('=')

//--------------------------------

Obviously Pos function does not exist in System.Dll for the string class. Which SnapDevelop using must I add, so the code will work?

Thank you

Arcady

Comment
  1. Michael Kramer
  2. Sunday, 19 January 2020 15:08 PM UTC
Conversion of PowerScript Pos(..) is non-trivial and requires changes beyond replacing the function name Pos => IndexOf. You will need to manually convert after Migrator tool has run.

PowerScript: Function is Pos(...); String is 1-indexed; and return 0 = "not found".

C# code: Function = s.IndexOf(...); String is 0-indexed; and return -1 = "not found".

Or you could add Pos(...) as extension function to String type but watch out for performance in such case.
  1. Helpful
  1. Logan Liu @Appeon
  2. Monday, 20 January 2020 02:26 AM UTC
Hi Arcady,

A new NuGet library is provided: PowerScript.Bridge. It provides pure C# implementation of various non-visual PowerScript constructs to accelerate migrating PowerScript to C#.

Refer to: https://docs.appeon.com/appeon_online_help/snapdevelop2019r2/Features_List/index.html



A tutorial about Using PowerScript Migrator:

https://docs.appeon.com/appeon_online_help/powerscriptmigrator2019r2/Working_with_PowerScript_Migrator/index.html

Regards, Logan



  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Monday, 13 January 2020 13:14 PM UTC
  2. Beta Testing
  3. # 1

PB 2019 R2 supports loading from any file location. However, there is no "unload assembly" method to unload an assembly already loaded.

  • CSharpAssembly . LoadWithNETFramework( filename )
    Load assembly using .NET full framework.
    Filename may include path.
  • CSharpAssembly . LoadWithNETFramework( filename, true )
    When running PB app from IDE will unload assemblies when PB closes.
    Otherwise, assemblies remain in memory (and DLL file is locked) until IDE closes.
  • CSharpAssembly . LoadWithNETCore( filename {, version} )
    Load assembly using .NET Core.
    Optional add specific .NET Core version.
  • CSharpAssembly . CreateInstance( class, ref object {, args[ ]} )
    Instantiates C# object of specific class within the loaded assembly.
    Optional constructor arguments.

I already tested multi-folder setup since I used SnapDevelop + Visual Studio to develop .NET Standard 2.0 assemblies while writing PB "assembly consumer" in different folder tree.

Important to remember ... , true when using .NET Framework.

Comment
  1. Chris Pollach @Appeon
  2. Monday, 13 January 2020 17:59 PM UTC
Hi Michael;

That is an excellent point!

Please create a Support Ticket for the missing CSharpAssembly .UnLoad () method.

Regards ... Chris
  1. Helpful
  1. Michael Kramer
  2. Monday, 13 January 2020 20:31 PM UTC
I created bug #3870 to request CSHarpAssembly.Unload( ).
  1. Helpful
There are no comments made yet.
Arcady Abramov Accepted Answer Pending Moderation
  1. Monday, 13 January 2020 13:18 PM UTC
  2. Beta Testing
  3. # 2

So, we can use these functions in code instead of simple CSharpProxy = create CSharpAssembly ?

 

Comment
  1. Michael Kramer
  2. Monday, 13 January 2020 13:28 PM UTC
Yes, CSharpObject is the equivalent of OLEObject. So:

* CSharpAssembly => Handles C# assembly. Load into memory including .NET runtime. Create C# class instances in .NET managed memory.

* CSharpObject => Handles C# object. Created from C# class in .NET managed memory.

You can instantiate many C# objects simultaneously from a mix of C# classes using just one CSharpAssembly instance for every assembly file.
  1. Helpful
  1. Michael Kramer
  2. Monday, 13 January 2020 13:30 PM UTC
I really like support for constructor arguments and for assembly unload when app closes despite IDE process continuing.

NOTE - It all reads C#, not ".NET in general". The API must use C# datatypes to be supported in PowerScript.
  1. Helpful
  1. Arcady Abramov
  2. Monday, 13 January 2020 13:34 PM UTC
So, do I still need to import the C# classes when using CSharpAssembly or once I loaded it in run time it works exactly like OLE object?
  1. Helpful
There are no comments made yet.
Arcady Abramov Accepted Answer Pending Moderation
  1. Monday, 13 January 2020 13:38 PM UTC
  2. Beta Testing
  3. # 3

Also, another question: if I have old PB Classic .NET assemblies (migrated to PB2019 R2, of course), can they use CSharpAssembly and CSharpobject classes in code?

Because, if yes, this would really be great - using PB UI with C# capabilities in refactored application.

 

Comment
  1. Arcady Abramov
  2. Monday, 13 January 2020 13:48 PM UTC
What about PB.NET assemblies? Can they be migrated to PB2019 R2?
  1. Helpful
  1. Michael Kramer
  2. Monday, 13 January 2020 14:32 PM UTC
Honestly, I don't known. Without knowing internal decisions I expect the PB=>C# migration tool is designed for "PowerScript proper". In any case I suggest you try it out to evaluate how much of your code can be "lifted" to C#.
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Tuesday, 14 January 2020 01:32 AM UTC
Hi Arcady, I recommend you test it out and share the results here.
  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.