Posts: 12,061
Threads: 140
Joined: Dec 2002
Now supports top-level statements and additional code files and reference assemblies.
If your old C# codes contain {} at the start, remove it. See the updated client examples.
Posts: 1,027
Threads: 245
Joined: Jul 2022
07-14-2023, 10:25 AM
(This post was last modified: 07-14-2023, 10:59 AM by Davider.)
I have encountered a practical problem and need help. Thank you in advance!
I have created the following script in LA and tested it. It can be successfully executed.
// script ""
/*/ r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/
using Spire.Doc;
public class Program {
public static void Main(string[] args) {
if (script.testing) {
args = new[] {
@"C:\Users\Administrator\Desktop", //args[0] Current path
"Hello World!", //args[1] AppendText
"Test.pdf" //args[2] Output file Name
};
}
Environment.CurrentDirectory = args[0];
var document = new Document();
Section section = document.AddSection();
var paragraph = section.AddParagraph();
paragraph.AppendText(args[1]);
document.SaveToFile(args[2], FileFormat.PDF);
}
}
Then, I want to use it in QM Use below code, but I have to make many modifications.(I need to add a global reference to the assembly, decompose the arguments of the args array, and so on.)
Also, after a few days, For some reasons, I want to copy it to LA for modification, which is quite cumbersome to use in practice.
Macro use in qm
;dll Env
SetEnvVar "dll" "C:\Users\Administrator\Documents\LibreAutomate\Main\dll"
;globals using
str globals =
;global using System;
;global using Au;
;LA C# Code:
str code=
;/*/ r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/
;using Spire.Doc;
;
;public class Program {
;,//public static void Main(string[] args) {
;,public static void Main2(string a0, string a1, string a2) {
;,,
;,,if (script.testing) {
;,,,var args = new[] {
;,@"C:\Users\Administrator\Desktop", //args[0] Current path
;,"Hello World!", //args[1] AppendText
;,"Test.pdf" //args[2] Output file Name
;,};
;,,}
;,,
;,,//Environment.CurrentDirectory = args[0];
;,,Environment.CurrentDirectory = a0;
;,,var document = new Document();
;,,
;,,Section section = document.AddSection();
;,,var paragraph = section.AddParagraph();
;,,
;,,//paragraph.AppendText(args[1]);
;,,paragraph.AppendText(a1);
;,,//document.SaveToFile(args[2], FileFormat.PDF);
;,,document.SaveToFile(a2, FileFormat.PDF);
;,}
;}
LaHttpCall("Code" F"code={code}" "fun=Program.Main2" "a0=C:\Users\Administrator\Desktop" "a1=hello world" "a2=Test.pdf" "_r=%dll%\spire\Spire.Doc.dll|%dll%\spire\Spire.Pdf.dll" F"_c={globals}")
So, my idea is, if it is possible to achieve something like the following code(PS: using the source code can also be successfully executed), which would be very convenient. This is because it would make copying and modifying it in LA for testing very easy.
This might require more programming with the HTTP server C# compiler file in LA. (need to determine if the first line of the code is enclosed within /*/.../*/ , Identify assembly references through the " r" flag.
/*/ r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/)
Are there any other elegant and convenient solutions?
Macro how to use this
_s=
;C:\Users\Administrator\Desktop
;Hello World!
;Test.pdf
ARRAY(str) args=_s
str code=
;/*/ r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/
;using Spire.Doc;
;
;public class Program {
;,public static void Main(string[] args) {
;,,
;,,if (script.testing) {
;,,,args = new[] {
;,@"C:\Users\Administrator\Desktop", //args[0] Current path
;,"Hello World!", //args[1] AppendText
;,"Test.pdf" //args[2] Output file Name
;,};
;,,}
;,,
;,,Environment.CurrentDirectory = args[0];
;,,var document = new Document();
;,,
;,,Section section = document.AddSection();
;,,var paragraph = section.AddParagraph();
;,,
;,,paragraph.AppendText(args[1]);
;,,document.SaveToFile(args[2], FileFormat.PDF);
;,}
;}
LaHttpCall("Code" F"code={code}" "fun=Program.Main" F"args={args}")
;LaHttpCall("Code" F"code={code}" F"args={args}") ;;or more simpler
In short, everything is aimed at seamlessly, elegantly, and conveniently executing the LA code in QM
|