Page 1 of 2

Inventory Web Page - 'Native' embedded DLL  Topic is solved

PostPosted: Tue Nov 30, 2021 12:01 pm
by pricerc
I have a new Inventory Web Browser plugin based on Microsoft.WebView2 (chrome) instead of IE.

It's working well, except that it has a native DLL that it seems needs to be available to the plugin at compile-time.

If the DLL is in the Jiwa folder, or I put it into the "compiler" and "runtime" folders, then the plugin runs, but I can't add it to the "embedded assemblies" list, because it's not a .NET assembly.

I've attached it as a document and have this code to copy it to the compile-time and run-time plugin folders, which seems to do the trick:
Code: Select all
    Public Sub SetupBeforeHandlers(ByVal JiwaForm As IJiwaForm, ByVal Plugin As Plugin.Plugin) Implements IJiwaFormPlugin.SetupBeforeHandlers
        For Each doc As Documents.Document In Plugin.Documents ' should only be one
            ' grab the native DLL and put it into the runtime folder.
            If doc.PhysicalFileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) Then
                Dim dllName As String = IO.Path.Combine(Plugin.CompilationFolder, doc.PhysicalFileName)
                If Not My.Computer.FileSystem.FileExists(dllName) OrElse My.Computer.FileSystem.GetFileInfo(dllName).CreationTime < Plugin.LastWriteDateTime Then
                    My.Computer.FileSystem.WriteAllBytes(dllName, doc.FileBinary, False)
                End If

                dllName = IO.Path.Combine(Plugin.RuntimeFolder, doc.PhysicalFileName)
                If Not My.Computer.FileSystem.FileExists(dllName) OrElse My.Computer.FileSystem.GetFileInfo(dllName).CreationTime < Plugin.LastWriteDateTime Then
                    My.Computer.FileSystem.WriteAllBytes(dllName, doc.FileBinary, False)
                End If

            End If
        Next
    End Sub


Is there a better way?


edited subject to be more useful to other punters.

Re: 'Native' embedded DLL

PostPosted: Tue Nov 30, 2021 12:04 pm
by pricerc
For completeness, here's the plugin.

Free to a good home.

I'm not sure if you need the actual runtime installed for it to work: https://go.microsoft.com/fwlink/p/?LinkId=2124703

Re: 'Native' embedded DLL

PostPosted: Tue Nov 30, 2021 12:24 pm
by Mike.Sheen
pricerc wrote:For completeness, here's the plugin.

Free to a good home.

I'm not sure if you need the actual runtime installed for it to work: https://go.microsoft.com/fwlink/p/?LinkId=2124703



Cool - thanks for that.

We also came across this problem on DEV-8922 which uses a Chromium browser to embed Power BI reports / dashboards inside Jiwa. We did that because getting the Microsoft Web Browser control to play nice with auth flows was impossible.

We also arrived at the same solution - attach the required dependencies as documents and extract them if not present.

However, I notice you're not explicitly reading the documents. We added some optimisations a while back to not load the documents of a plugin in DEV-7217 - so in your SetupBeforeHandlers where you extract the documents to the file system, you'll be wanting to do this first:
Code: Select all
Plugin.Documents.Read(Plugin.RecID);


You can see how we do that in DEV-8922 - it has a link to the plugin we developed to download.

I notice your plugin references Jiwa version 7.2.1.0 - the optimisation to not load documents of plugins was implemented in 7.2.0 SR2 - so you'll definitely be impacted by that - I'm actually a little puzzled that didn't trip you up!

Re: 'Native' embedded DLL

PostPosted: Tue Nov 30, 2021 1:10 pm
by pricerc
Mike.Sheen wrote:I'm actually a little puzzled that didn't trip you up!


hmmm. As am I. Now that you mention it. I have encountered that problem previously.

I'll add it to my 'todo' list to find out why.

Re: 'Native' embedded DLL

PostPosted: Tue Nov 30, 2021 1:22 pm
by pricerc
Mike.Sheen wrote:We also came across this problem on DEV-8922 which uses a Chromium browser


I actually looked at the CEF, but it seemed more work than using Edge/WebView2.

I did find https://www.teamdev.com/dotnetbrowser, which is at least an all-managed solution, but they're asking for more than I thought it was worth for my purposes (although with the two days it took me to complete my two hour project, it may have been worth it...)

Re: 'Native' embedded DLL

PostPosted: Tue Nov 30, 2021 2:33 pm
by pricerc
pricerc wrote:
Mike.Sheen wrote:I'm actually a little puzzled that didn't trip you up!


hmmm. As am I. Now that you mention it. I have encountered that problem previously.

I'll add it to my 'todo' list to find out why.


found it.

Plugin documents are read with the plugin... from ILSpy:
Code: Select all
// JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin
...

public override void Read(string RecID)
{
...
      OnReadStart();
      Clear();
      _Documents.DocumentTypes.Read();
      _Notes.NoteTypeCollection.Read();
      text = "SELECT TOP 1 ...  FROM SY_Plugin  WHERE SY_Plugin.RecID = @RecID";

      ...

      PluginFormCollection.Read();
      BusinessLogicCollection.Read();
      ReferenceCollection.Read();
      CustomFieldCollection.Read();
      SystemSettingCollection.Read();
      ExecutionScheduleCollection.Read();
      Documents.Read(base.RecID);
      Notes.Read(base.RecID);
      ImageCollection.Read();
      PluginReferenceCollection.Read();
      EmbeddedReferenceCollection.Read();
      OnReadEnd();

...
}

Re: Inventory Web Page - 'Native' embedded DLL

PostPosted: Tue Nov 30, 2021 2:54 pm
by pricerc
And because I was avoiding doing some other work, I did this, too.

Combining what I learnt for the inventory one with the standard sample 'web browser'.

Even the print button works.

Just needs someone enthusiastic to add forward, back, refresh and 'recent items' support, and you'll be able to use Jiwa as your web browser !

Re: 'Native' embedded DLL

PostPosted: Tue Nov 30, 2021 3:35 pm
by Mike.Sheen
pricerc wrote:found it.

Plugin documents are read with the plugin... from ILSpy:
Code: Select all
// JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin
...

public override void Read(string RecID)
{
...
      OnReadStart();
      Clear();
      _Documents.DocumentTypes.Read();
      _Notes.NoteTypeCollection.Read();
      text = "SELECT TOP 1 ...  FROM SY_Plugin  WHERE SY_Plugin.RecID = @RecID";

      ...

      PluginFormCollection.Read();
      BusinessLogicCollection.Read();
      ReferenceCollection.Read();
      CustomFieldCollection.Read();
      SystemSettingCollection.Read();
      ExecutionScheduleCollection.Read();
      Documents.Read(base.RecID);
      Notes.Read(base.RecID);
      ImageCollection.Read();
      PluginReferenceCollection.Read();
      EmbeddedReferenceCollection.Read();
      OnReadEnd();

...
}


I see what's happening now... we'll only do the full read if the plugin hasn't been compiled before and needs to be - So I guess that actually is good enough in your case, as you only need to be able to see the documents once to deploy to the file system - subsequent times after that the plugin will have an empty documents collection... but won't care because the files you need are already on the filesystem.

Re: Inventory Web Page - 'Native' embedded DLL

PostPosted: Wed Dec 01, 2021 2:07 pm
by Mike.Sheen
FYI This WebView2 works fine on my Windows 10 machine, but Windows Server 2019 I get the error:

---------------------------
Error
---------------------------
Error : Couldn't find a compatible Webview2 Runtime installation to host WebViews.

Module : MoveNext
---------------------------
OK
---------------------------

I think the WebView requires the runtime to be installed - I found that over here : https://developer.microsoft.com/en-us/m ... /webview2/ but haven't managed to find one matching the version of your plugin, Ryan - did you get your embedded assemblies and WebView2Loader.dll from a nuget package?

Re: Inventory Web Page - 'Native' embedded DLL

PostPosted: Wed Dec 01, 2021 3:16 pm
by pricerc
Mike.Sheen wrote:I think the WebView requires the runtime to be installed - I found that over here : https://developer.microsoft.com/en-us/m ... /webview2/ but haven't managed to find one matching the version of your plugin, Ryan - did you get your embedded assemblies and WebView2Loader.dll from a nuget package?


Yes - the Microsoft WebView2 package - https://www.nuget.org/packages/Microsof ... .0.1020.30

But they're supposed to (as I understood the documentation, which is typically vague) rely on the runtime which I left a link to in the plugin description.