DotNet code in NAV - problems with overloads

AquirAquir Member Posts: 23
Hi,

I'm trying to implement this code in NAV:
(a simple converter from RTF to HTML)
using System;
using System.IO;
using System.Text;
using Microsoft.Dynamics.Framework.UI.Extensibility;
using Itenso.Rtf;
using Itenso.Rtf.Parser;
using Itenso.Rtf.Support;
using Itenso.Rtf.Converter.Image;
using Itenso.Rtf.Converter.Html;
using Itenso.Rtf.Interpreter;
using System.Drawing.Imaging;

namespace RTF2HTMLConverter
{
    [ControlAddInExport("RTF2HTMLConverter")] //5a33fb4258a0a66c
    public class Converter
    {
        string HTML;

        public string RTF
        {
           get
           {
               return HTML;
           }
           set
           {
               MemoryStream RTFStream = new MemoryStream(Encoding.UTF8.GetBytes(RTF));
               
               // Parse RTF
               IRtfGroup RTFStructure;
               RtfParserListenerStructureBuilder StructureBuilder = new RtfParserListenerStructureBuilder();
               RtfParser Parser = new RtfParser(StructureBuilder);
               Parser.IgnoreContentAfterRootGroup = true;
               Parser.Parse(new RtfSource(RTFStream));
               RTFStructure = StructureBuilder.StructureRoot;
               RtfVisualImageAdapter imageAdapter = new RtfVisualImageAdapter("C:\\TEMP\\",ImageFormat.Jpeg);
               
               // Interpret RTF
               IRtfDocument RTFDocument;
               RtfInterpreterSettings InterpreterSettings = new RtfInterpreterSettings();
	       InterpreterSettings.IgnoreDuplicatedFonts = true;
	       InterpreterSettings.IgnoreUnknownFonts = true;
               RTFDocument = RtfInterpreterTool.BuildDoc(RTFStructure, InterpreterSettings);

               // Convert RTF to HTML
               RtfHtmlConvertSettings HTMLConvertSettings = new RtfHtmlConvertSettings();
               HTMLConvertSettings.Title = "Converted from RTF";
               HTMLConvertSettings.IsShowHiddenText = true;
               HTMLConvertSettings.UseNonBreakingSpaces = true;
               RtfHtmlConverter HTMLConverter = new RtfHtmlConverter(RTFDocument, HTMLConvertSettings);
               HTML = HTMLConverter.Convert();
           }
        }
    }
}

I'm stuck with this line:
RTFDocument = RtfInterpreterTool.BuildDoc(RTFStructure, InterpreterSettings);

the possible overloads:
public static IRtfDocument BuildDoc(IRtfGroup rtfDocument, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(IRtfSource rtfTextSource, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(Stream rtfTextSource, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(string rtfText, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(TextReader rtfTextSource, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(IRtfGroup rtfDocument, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(IRtfSource rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(Stream rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(string rtfText, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners);
public static IRtfDocument BuildDoc(TextReader rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners);

not matter what I try I get this
"The function call was ambiguous. No matching method was found."

this is the C/AL code

Name	DataType	Subtype	Length
RtfSource	Text		
MemoryStream	DotNet	System.IO.MemoryStream.'mscorlib'	
Encoding	DotNet	System.Text.Encoding.'mscorlib'	
Convert	DotNet	System.Convert.'mscorlib'	
--PARSE	Boolean		
IRtfGroup	DotNet	Itenso.Rtf.IRtfGroup.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfGroup	DotNet	Itenso.Rtf.Model.RtfGroup.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfParserListenerStructureBuilder	DotNet	Itenso.Rtf.Parser.RtfParserListenerStructureBuilder.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfParser	DotNet	Itenso.Rtf.Parser.RtfParser.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfStructureBuilder	DotNet	Itenso.Rtf.Parser.RtfParserListenerStructureBuilder.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfVisualImageAdapter	DotNet	Itenso.Rtf.Converter.Image.RtfVisualImageAdapter.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
ImageFormat	DotNet	System.Drawing.Imaging.ImageFormat.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
--INTERPRET	Boolean		
IRtfDocument	DotNet	Itenso.Rtf.IRtfDocument.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfDocument	DotNet	Itenso.Rtf.Model.RtfDocument.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfInterpreterSettings	DotNet	Itenso.Rtf.Interpreter.RtfInterpreterSettings.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
IRtfInterpreterSettings	DotNet	Itenso.Rtf.IRtfInterpreterSettings.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	
RtfInterpreterTool	DotNet	Itenso.Rtf.Support.RtfInterpreterTool.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'	

Documentation()

OnRun()
RtfSource := '{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\*\generator Riched20 10.0.14393}\viewkind4\uc1\pard\sa200\sl276\slmult1\b\f0\fs22\lang9 TEST\b0\par}';
MemoryStream := MemoryStream.MemoryStream(Convert.ToByte(Encoding.GetEncoding('UTF8').GetBytes(RtfSource)));

// Parse RTF
IRtfGroup := RtfGroup;
RtfParserListenerStructureBuilder := RtfParserListenerStructureBuilder.RtfParserListenerStructureBuilder;
RtfParser := RtfParser.RtfParser;
RtfParser.AddParserListener(RtfParserListenerStructureBuilder);
RtfParser.IgnoreContentAfterRootGroup := TRUE;
RtfParser.Parse(MemoryStream);
RtfStructureBuilder := RtfParserListenerStructureBuilder.StructureRoot;
RtfVisualImageAdapter := RtfVisualImageAdapter.RtfVisualImageAdapter('C:\TEMP\',ImageFormat.Jpeg);

//Interpret RTF
IRtfDocument := RtfDocument;
IRtfInterpreterSettings := RtfInterpreterSettings;
RtfInterpreterSettings := RtfInterpreterSettings.RtfInterpreterSettings;
RtfInterpreterSettings.IgnoreDuplicatedFonts := TRUE;
RtfInterpreterSettings.IgnoreUnknownFonts := TRUE;
RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings);

any ideas?

Best Answer

  • kaspermoerchkaspermoerch Member Posts: 43
    edited 2016-09-14 Answer ✓
    My guess would be that the optional parameter (the one marked bye the keyword params in the C# code) is causing the trouble as C/AL does not work with optional parameters.

    You probably need to instantiate an empty array of type IRtfInterpreterListener. You can do that like this:
    DotNetArray := DotNetArray.CreateInstance(GETDOTNETTYPE(IRtfInterpreterListener),0);
    

    Where DotNetArray refers to System.Array and IRtfInterpreterListener refers to the interface in your Itenso DLL.

    Then you call BuildDoc like with the array as the last parameter:
    RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings,DotNetArray);
    

Answers

  • Wisa123Wisa123 Member Posts: 308
    I'm not a .net pro here, but whenever I scrambled with the interop I (at least think it was the case) that you have to use F5 to select the proper overload of a function for it to work.

    Just a shot in the blue, but maybe it helps.
    Austrian NAV/BC Dev
  • AquirAquir Member Posts: 23
    edited 2016-09-13
    Wisa123 wrote: »
    I'm not a .net pro here, but whenever I scrambled with the interop I (at least think it was the case) that you have to use F5 to select the proper overload of a function for it to work.

    Just a shot in the blue, but maybe it helps.

    Good shout! I'll check ot out! Thanks
  • SunsetSunset Member Posts: 201
    I've had issues when the options get too long. i.e. the length of the various parameters. Seems like NAV has some stringlength it can handle, and if the total length of the overload description goes over, then NAV fails.

    Only solution I have found is to break it down and call the various bits individually.
    Don't just take my word for it, test it yourself
  • kaspermoerchkaspermoerch Member Posts: 43
    edited 2016-09-14 Answer ✓
    My guess would be that the optional parameter (the one marked bye the keyword params in the C# code) is causing the trouble as C/AL does not work with optional parameters.

    You probably need to instantiate an empty array of type IRtfInterpreterListener. You can do that like this:
    DotNetArray := DotNetArray.CreateInstance(GETDOTNETTYPE(IRtfInterpreterListener),0);
    

    Where DotNetArray refers to System.Array and IRtfInterpreterListener refers to the interface in your Itenso DLL.

    Then you call BuildDoc like with the array as the last parameter:
    RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings,DotNetArray);
    
  • AquirAquir Member Posts: 23
    My guess would be that the optional parameter (the one marked bye the keyword params in the C# code) is causing the trouble as C/AL does not work with optional parameters.

    You probably need to instantiate an empty array of type IRtfInterpreterListener. You can do that like this:
    DotNetArray := DotNetArray.CreateInstance(GETDOTNETTYPE(IRtfInterpreterListener),0);
    

    Where DotNetArray refers to System.Array and IRtfInterpreterListener refers to the interface in your Itenso DLL.

    Then you call BuildDoc like with the array as the last parameter:
    RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings,DotNetArray);
    

    Thank you very much! It worked!
Sign In or Register to comment.