private void buttonRun_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textSourceCode.Text.Trim()))
            {
                MessageBox.Show("No code found to run", "KntScript");
                return;
            }

            try
            {
                toolStripConsole.Enabled = false;

                _engine.InOutDevice.Clear();
                _engine.ClearAllVars();
                _engine.Run(textSourceCode.Text);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
            finally
            {
                toolStripConsole.Enabled = true;
            }
        }
Beispiel #2
0
        public void RunScript(string code, bool newThread = true)
        {
            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            var kntScript = new KntSEngine(new InOutDeviceForm(), new KNoteScriptLibrary(this));

            if (newThread)
            {
                var t = new Thread(() => kntScript.Run(code));
                t.IsBackground = false;
                t.Start();
            }
            else
            {
                kntScript.Run(code);
            }
        }
Beispiel #3
0
        private void buttonInteract_Click(object sender, EventArgs e)
        {
            //
            // Demo, inject variables and personalized api library
            //

            var kntScript = new KntSEngine(new InOutDeviceForm(), new MyLibrary());

            var a = new DocumentDummy();

            a.Description = "My object, to inject in script.";

            // inject variable
            kntScript.AddVar("_a", a);

            var code = @"printline ""Demo external variables / MyLibrary injected"";

                        ' This variable (_a) comes from the host application
                        printline _a.Description;
                        printline _a.IdDocument;
                        printline _a.CreationDateTime;
                        printline _a.Folder.Name;
                        _a.DocumentTestMethodA("" param A "");
                        var b = _a.DocumentTestMethodB("" == param C =="");
                        printline b;

                        ' Test MyLibrary (injected library)
                        printline """";
                        printline ""Test MyLibrary"";
                        var colec = ColecDocDemo();
                        foreach x in colec
                            printline x.Description;
                        end foreach;

                        printline """";
                        _a.Description = ""KntScript - changed description property !!"";                                                
                        printline _a.Description;
                        printline """";

                        printline ""<< end >>""; 
                        ";

            kntScript.Run(code);

            var b = (DocumentDummy)kntScript.GetVar("_a");  // -> a

            MessageBox.Show(a.Description + " <==> " + b.Description);
        }
Beispiel #4
0
    private void buttonRunScript_Click(object sender, EventArgs e)
    {
        var kntScript = new KntSEngine(new InOutDeviceForm(), new KNoteScriptLibrary(_store));

        kntScript.Run(@"
                        var i = 1;
                        var str = ""Hello world "";
                        for i = 1 to 10
                            printline str + i;
                        end for;                            
                        printline """";
                        str = ""(type text here ...) "";
                        readvar {""Example input str var:"": str };
                        printline str;
                        printline ""<< end >>"";                            
                    ");
    }
Beispiel #5
0
    private void buttonRunBackground_Click(object sender, EventArgs e)
    {
        var kntScript = new KntSEngine(new InOutDeviceForm(), new KNoteScriptLibrary(_store));

        var code = @"
                    var i = 1;
                    var str = ""Hello world "";
                    for i = 1 to 1000
                        printline str + i;
                    end for;                            
                    printline ""<< end >>"";
                ";

        // --- Synchronous version
        // kntScript.Run(code);

        // --- Asynchronous version
        var t = new Thread(() => kntScript.Run(code));

        t.IsBackground = false;
        t.Start();
    }
Beispiel #6
0
    private void buttonInteract_Click(object sender, EventArgs e)
    {
        //
        // Demo, inject variables and personalized api library
        //

        var kntScript = new KntSEngine(new InOutDeviceForm(), new KNoteScriptLibrary(_store));

        var a = new FolderDto();

        a.Name             = "My folder, to inject in script.";
        a.Tags             = "my tags";
        a.CreationDateTime = DateTime.Now;

        // inject variable
        kntScript.AddVar("_a", a);

        var code = @"printline ""Demo external variables / KNoteScriptLibrary injected"";

                    ' This variable (_a) comes from the host application
                    printline _a.Name;
                    printline _a.Tags;
                    printline _a.CreationDateTime;                        

                    _a.Name = ""KntScript - changed description property !!"";                                                
                    printline _a.Name;
                    printline """";

                    printline ""<< end >>""; 
                    ";

        kntScript.Run(code);

        var b = (FolderDto)kntScript.GetVar("_a");  // -> a

        MessageBox.Show(a.Name + " <==> " + b.Name);
    }